mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-06-13 19:21:37 +03:00
make sure SAX endDocument is always called as this could result in a
* parser.c: make sure SAX endDocument is always called as this could result in a Python memory leak otherwise (it's used to decrement ref-counting) * python/generator.py python/libxml.c python/libxml.py python/libxml2-python-api.xml python/libxml2class.txt python/tests/error.py python/tests/xpath.py: implemented the suggestions made by Gary Benson and extended the tests to match it. Daniel
This commit is contained in:
@ -324,7 +324,7 @@ pythonProcessingInstruction(void *user_data,
|
||||
if (PyObject_HasAttrString(handler, "processingInstruction")) {
|
||||
result =
|
||||
PyObject_CallMethod(handler,
|
||||
"ignorableWhitespace", "ss", target, data);
|
||||
"processingInstruction", "ss", target, data);
|
||||
Py_XDECREF(result);
|
||||
}
|
||||
}
|
||||
@ -663,7 +663,7 @@ libxml_xmlCreatePushParser(PyObject *self, PyObject *args) {
|
||||
&chunk, &size, &URI))
|
||||
return(NULL);
|
||||
|
||||
#ifdef DEBUG_ERROR
|
||||
#ifdef DEBUG
|
||||
printf("libxml_xmlCreatePushParser(%p, %s, %d, %s) called\n",
|
||||
pyobj_SAX, chunk, size, URI);
|
||||
#endif
|
||||
@ -691,7 +691,7 @@ libxml_htmlCreatePushParser(PyObject *self, PyObject *args) {
|
||||
&chunk, &size, &URI))
|
||||
return(NULL);
|
||||
|
||||
#ifdef DEBUG_ERROR
|
||||
#ifdef DEBUG
|
||||
printf("libxml_htmlCreatePushParser(%p, %s, %d, %s) called\n",
|
||||
pyobj_SAX, chunk, size, URI);
|
||||
#endif
|
||||
@ -706,6 +706,60 @@ libxml_htmlCreatePushParser(PyObject *self, PyObject *args) {
|
||||
return(pyret);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
libxml_xmlSAXParseFile(PyObject *self, PyObject *args) {
|
||||
int recover;
|
||||
xmlChar *URI;
|
||||
PyObject *pyobj_SAX = NULL;
|
||||
xmlSAXHandlerPtr SAX = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "Osi:xmlSAXParseFile", &pyobj_SAX,
|
||||
&URI, &recover))
|
||||
return(NULL);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("libxml_xmlSAXParseFile(%p, %s, %d) called\n",
|
||||
pyobj_SAX, URI, recover);
|
||||
#endif
|
||||
if (pyobj_SAX == Py_None) {
|
||||
Py_INCREF(Py_None);
|
||||
return(Py_None);
|
||||
}
|
||||
SAX = &pythonSaxHandler;
|
||||
Py_INCREF(pyobj_SAX);
|
||||
/* The reference is released in pythonEndDocument() */
|
||||
xmlSAXParseFileWithData(SAX, URI, recover, pyobj_SAX);
|
||||
Py_INCREF(Py_None);
|
||||
return(Py_None);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
libxml_htmlSAXParseFile(PyObject *self, PyObject *args) {
|
||||
xmlChar *URI;
|
||||
xmlChar *encoding;
|
||||
PyObject *pyobj_SAX = NULL;
|
||||
xmlSAXHandlerPtr SAX = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "Osz:htmlSAXParseFile", &pyobj_SAX,
|
||||
&URI, &encoding))
|
||||
return(NULL);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("libxml_htmlSAXParseFile(%p, %s, %s) called\n",
|
||||
pyobj_SAX, URI, encoding);
|
||||
#endif
|
||||
if (pyobj_SAX == Py_None) {
|
||||
Py_INCREF(Py_None);
|
||||
return(Py_None);
|
||||
}
|
||||
SAX = &pythonSaxHandler;
|
||||
Py_INCREF(pyobj_SAX);
|
||||
/* The reference is released in pythonEndDocument() */
|
||||
htmlSAXParseFile(URI, encoding, SAX, pyobj_SAX);
|
||||
Py_INCREF(Py_None);
|
||||
return(Py_None);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* Error message callback *
|
||||
|
Reference in New Issue
Block a user