-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
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:
-
The
duplicate()
andrelease()
methods inDOMObject
will be madeprotected
, therefore preventing explicit calls to them from client code. This will require changes to client code not already usingPoco::AutoPtr
(as it should already). -
A new class template
Poco::XML::NodePtr
will be created for passing DOM Node objects as method arguments. This will be a subclass ofPoco::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. -
All methods returning raw
DOMObject
pointers will be changed to returnPoco::AutoPtr
. This should not break any code, except code that explicitly callsrelease()
, e.g., after receiving aNodeList
orNamedNodeMap
. However, sincerelease()
is no longer public, breakage will occur during compilation, and not during runtime in the form of memory leaks or double deletes. -
Eventually, in a later version,
Poco::XML::NodePtr
will be removed and replaced withPoco::AutoPtr
.