mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-18 16:08:59 +03:00
applied patch from Stphane Bidoul to fix some Python bindings
* python/libxml.c python/generator.py python/libxml.py python/libxml2-python-api.xml python/libxml2class.txt: applied patch from Stphane Bidoul to fix some Python bindings initialization, then had to change the parserCleanup() to handle memory released there. * xmlmemory.c: added more debugging comments. Daniel
This commit is contained in:
@@ -75,6 +75,9 @@ static xmlMallocFunc mallocFunc = NULL;
|
||||
static xmlReallocFunc reallocFunc = NULL;
|
||||
static xmlStrdupFunc strdupFunc = NULL;
|
||||
|
||||
static void
|
||||
libxml_xmlErrorInitialize(void); /* forward declare */
|
||||
|
||||
PyObject *
|
||||
libxml_xmlDebugMemory(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
|
||||
{
|
||||
@@ -104,13 +107,21 @@ libxml_xmlDebugMemory(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
|
||||
(strdupFunc == xmlMemoryStrdup)) {
|
||||
libxmlMemoryAllocatedBase = xmlMemUsed();
|
||||
} else {
|
||||
/*
|
||||
* cleanup first, because some memory has been
|
||||
* allocated with the non-debug malloc in xmlInitParser
|
||||
* when the python module was imported
|
||||
*/
|
||||
xmlCleanupParser();
|
||||
ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc,
|
||||
xmlMemRealloc, xmlMemoryStrdup);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
libxmlMemoryAllocatedBase = xmlMemUsed();
|
||||
/* reinitialize */
|
||||
xmlInitParser();
|
||||
libxml_xmlErrorInitialize();
|
||||
}
|
||||
xmlInitParser();
|
||||
ret = 0;
|
||||
} else if (libxmlMemoryDebugActivated == 0) {
|
||||
libxmlMemoryAllocatedBase = xmlMemUsed();
|
||||
@@ -132,6 +143,29 @@ libxml_xmlDebugMemory(ATTRIBUTE_UNUSED PyObject * self, PyObject * args)
|
||||
return (py_retval);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
libxml_xmlPythonCleanupParser(PyObject *self ATTRIBUTE_UNUSED,
|
||||
PyObject *args ATTRIBUTE_UNUSED) {
|
||||
|
||||
long freed;
|
||||
|
||||
if (libxmlMemoryDebug) {
|
||||
freed = xmlMemUsed();
|
||||
}
|
||||
|
||||
xmlCleanupParser();
|
||||
|
||||
if (libxmlMemoryDebug) {
|
||||
freed -= xmlMemUsed();
|
||||
libxmlMemoryAllocatedBase -= freed;
|
||||
if (libxmlMemoryAllocatedBase < 0)
|
||||
libxmlMemoryAllocatedBase = 0;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return(Py_None);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
libxml_xmlDumpMemory(ATTRIBUTE_UNUSED PyObject * self,
|
||||
ATTRIBUTE_UNUSED PyObject * args)
|
||||
@@ -3228,20 +3262,19 @@ void
|
||||
initlibxml2mod(void)
|
||||
{
|
||||
static int initialized = 0;
|
||||
PyObject *m;
|
||||
|
||||
if (initialized != 0)
|
||||
return;
|
||||
/* XXX xmlInitParser does much more than this */
|
||||
xmlInitGlobals();
|
||||
#ifdef LIBXML_OUTPUT_ENABLED
|
||||
xmlRegisterDefaultOutputCallbacks();
|
||||
#endif /* LIBXML_OUTPUT_ENABLED */
|
||||
xmlRegisterDefaultInputCallbacks();
|
||||
m = Py_InitModule((char *) "libxml2mod", libxmlMethods);
|
||||
initialized = 1;
|
||||
|
||||
/* intialize the python extension module */
|
||||
Py_InitModule((char *) "libxml2mod", libxmlMethods);
|
||||
|
||||
/* initialize libxml2 */
|
||||
xmlInitParser();
|
||||
libxml_xmlErrorInitialize();
|
||||
|
||||
initialized = 1;
|
||||
|
||||
#ifdef MERGED_MODULES
|
||||
initlibxsltmod();
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user