Skip to content

XML/DOM: Remove raw pointers from public interfaces #2075

@obiltschnig

Description

@obiltschnig

Raw pointers in XML/DOM interfaces should be replaced with smart pointers (Poco::AutoPtr).

Unfortunately, this cannot be done without breaking existing code. After extensive analysis, a method has been found to implement this with minimal backwards compatibility issues. The main concern was that code requiring changes should not break more or less silently or crash at runtime (e.g., creating memory leaks or double deletes), but break at compile time.

For passing DOM objects as method arguments and return values, the following mechanism will be used:

  1. The duplicate() and release() methods in DOMObject will be made protected, therefore preventing explicit calls to them from client code. This will require changes to client code not already using Poco::AutoPtr (as it should already).

  2. A new class template Poco::XML::NodePtr will be created for passing DOM Node objects as method arguments. This will be a subclass of Poco::AutoPtr, but with the semantics of the constructor taking a raw pointer changed to call duplicate(). This way, existing code using raw pointers will continue to work with correct reference counting. However, this constructor will be marked as deprecated, so that a warning will be issued when it's being used.

  3. All methods returning raw DOMObject pointers will be changed to return Poco::AutoPtr. This should not break any code, except code that explicitly calls release(), e.g., after receiving a NodeList or NamedNodeMap. However, since release() is no longer public, breakage will occur during compilation, and not during runtime in the form of memory leaks or double deletes.

  4. Eventually, in a later version, Poco::XML::NodePtr will be removed and replaced with Poco::AutoPtr.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions