[ 
https://issues.apache.org/jira/browse/XERCESC-1730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574121#action_12574121
 ] 

Tobias Schuette commented on XERCESC-1730:
------------------------------------------

migrating exceptions between memory managers results in doing it by hand by 
catching and rethrowing all exceptions.
this could already be done in the current implementation even without adding a 
clone(MemoryManager*) aka setMemoryManager method.

but this means having a try/catch-block in every call to a method that can 
throw an exception only for migration,
which is unprofitable and error prone because the exceptional program flow is 
not reached/tested that often and
neither the relationship between the current and the next memory manager 
instance disappear
nor does the "special code" nor the problem to ensure that the instance needs 
to be valid.

the patch provides a way to let the memory manager decide the best strategy in 
the first place when the exception is created, because the memory manager is 
the only one that has knowledge how it has customized the memory allocation 
behavior.
if the memory manager has certain knowledge that the memory allocation strategy 
for the exceptional program flow is different from the normal program flow
it can take the bull by the horns by providing the right memory manager 
instance for the exceptional program flow.

the fact that a custom memory manager is required is intended behavior,
I've implemented some in my code and only looking forward to see its 
integration in the code base
to be able to use an unpatched version of the xerces trunk.

the patch itself doesn't change anything on its own,
it provides a way for custom memory management implementations to control
the memory management of the exceptional program flow separately from the 
normal program flow.




> scoped memory management
> ------------------------
>
>                 Key: XERCESC-1730
>                 URL: https://issues.apache.org/jira/browse/XERCESC-1730
>             Project: Xerces-C++
>          Issue Type: Improvement
>            Reporter: Tobias Schuette
>            Priority: Minor
>             Fix For: 3.0.0
>
>         Attachments: MemoryManager.diff, XMLException.diff
>
>
> passing scoped memory managers to certain helper functions (xercesc/util/...) 
> only works in non-exceptional or catch-all circumstances.
> If those functions (e.g. XMLString::parseInt) throw an exception the scoped 
> memory manager
> is passed via ThrowXMLwithMemMgrXXX to the exception during construction.
> The exception allocates memory for its internal buffers (message/source file) 
> from that memory manager.
> If the exception is not caught before the scoped memory manager goes 
> out-of-scope,
> dereferencing/deallocating the memory during reporting/destruction yields 
> undefined behaviour.
> the attached diffs against trunk are a proposal to change the MemoryManager 
> interface of Xerces-C's pluggable memory management and the exception base 
> class XMLException in such a way that implementors of the MemoryManager 
> interface are able to handle memory requests coming from exceptions 
> separately as discussed on the mailing-list.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to