Re: [xml] strange transformCtxt free-ing problem

"William M. Brack" <wbrack mmm com hk> writes:

While waiting for a proper test file, I did some more checking, this time
with Valgrind (unfortunately, Valgrind and Python tend to work in a very
adversarial manner, so this isn't very easy).  I think I now understand
where the original trouble comes from.

The pythonDocLoaderFuncWrapper function in python/libxslt.c creates a
parser context, pctxt, using xmlNewParserCtxt().  Apparently the reason
for doing this is so that later, after calling the user's loader, some
additional error checking and cleanup can be done.  pctxt is then
converted into a Python object [pctxtobj =
libxml_xmlParserCtxtPtrWrap(pctxt)] which is passed to the user's loader
function (the routine 'loader' in your test program).

Within the loader function which you posted, you create a new object:
  parserContext = libxml2.parserCtxt(_obj=pctx)
where 'pctx' is pctxtobj.  However, parserContext is only a local python
object, so at the end of the loader function Python very kindly calls
upon it's Garbage Collector to dispose of it.  That action causes
xmlFreeParserCtxt to be called for the underlying parser context pointer,
which in this instance is the (original C) variable pctxt.  That, in
turn, causes nothing but trouble for the remainder of the code within

Right. Then I think that the parserContext cleanup should not cause
the C object to be cleaned up.

That's about as far as I can go, since it now would appear to be a
problem with the basic design of the loader code.  Please let me know if
I have made some error in my analysis described above, or if I can
further assist in any way.

Ok. Thanks for that.

As far as I knew the loader had to use the parserContext calls:


etc.. because of the memory management issues.

When you call:


the thought was that the underlying parserContext was being used and
documents read were being stored in the parserContext ready to be
cleaned up later on when the context is no longer needed.

However, that doesn't seem to be happening.

It does appear there is some confusion about the loader. Certainly I'm
confused now. 

Daniel? This is really your bag since you designed this API?

Nic Ferrier   for all your tapsell ferrier needs

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]