cleanup patch from Stéphane Bidoul Daniel
* python/libxml.c: cleanup patch from Stéphane Bidoul
Daniel
diff --git a/ChangeLog b/ChangeLog
index ebbf6d6..d6e645a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Jan 14 15:39:14 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+ * python/libxml.c: cleanup patch from Stéphane Bidoul
+
Tue Jan 14 14:41:18 CET 2003 Daniel Veillard <daniel@veillard.com>
* encoding.c: fixing bug #103100 with a dummy UTF8ToUTF8 copy
@@ -6,7 +10,7 @@
* python/generator.py python/libxml.c python/libxml.py
python/libxml_wrap.h python/types.c: applied and fixed a patch
- from Stephane Bibould to provide per parser error handlers at the
+ from Stéphane Bidoul to provide per parser error handlers at the
Python level.
* python/tests/Makefile.am python/tests/ctxterror.py: added a
regression test for it.
diff --git a/python/libxml.c b/python/libxml.c
index 15a30b5..f1b0d6a 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -439,6 +439,7 @@
ret = PyObject_CallFunction(pythonExternalEntityLoaderObjext,
(char *) "(ssO)", URL, ID, ctxtobj);
+ Py_XDECREF(ctxtobj);
#ifdef DEBUG_LOADER
printf("pythonExternalEntityLoader: result ");
PyObject_Print(ret, stdout, 0);
@@ -1372,6 +1373,7 @@
{
PyObject *py_retval;
xmlParserCtxtPtr ctxt;
+ xmlParserCtxtPyCtxtPtr pyCtxt;
PyObject *pyobj_ctxt;
PyObject *pyobj_f;
PyObject *pyobj_arg;
@@ -1381,8 +1383,6 @@
return(NULL);
ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
if (ctxt->_private == NULL) {
- xmlParserCtxtPyCtxt *pyCtxt;
-
pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt));
if (pyCtxt == NULL) {
py_retval = libxml_intWrap(-1);
@@ -1391,11 +1391,16 @@
memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt));
ctxt->_private = pyCtxt;
}
+ else {
+ pyCtxt = ctxt->_private;
+ }
/* TODO: check f is a function ! */
+ Py_XDECREF(pyCtxt->errorFunc);
Py_XINCREF(pyobj_f);
- ((xmlParserCtxtPyCtxt *)ctxt->_private)->errorFunc = pyobj_f;
+ pyCtxt->errorFunc = pyobj_f;
+ Py_XDECREF(pyCtxt->errorFuncArg);
Py_XINCREF(pyobj_arg);
- ((xmlParserCtxtPyCtxt *)ctxt->_private)->errorFuncArg = pyobj_arg;
+ pyCtxt->errorFuncArg = pyobj_arg;
ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler;
ctxt->vctxt.error = libxml_xmlParserCtxtErrorFuncHandler;
@@ -1445,6 +1450,7 @@
{
PyObject *py_retval;
xmlParserCtxtPtr ctxt;
+ xmlParserCtxtPyCtxtPtr pyCtxt;
PyObject *pyobj_ctxt;
PyObject *pyobj_f;
PyObject *pyobj_arg;
@@ -1452,11 +1458,25 @@
if (!PyArg_ParseTuple(args, (char *)"OOO:xmlSetParserCtxtWarningHandler", &pyobj_ctxt, &pyobj_f, &pyobj_arg))
return(NULL);
ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
+ if (ctxt->_private == NULL) {
+ pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt));
+ if (pyCtxt == NULL) {
+ py_retval = libxml_intWrap(-1);
+ return(py_retval);
+ }
+ memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt));
+ ctxt->_private = pyCtxt;
+ }
+ else {
+ pyCtxt = ctxt->_private;
+ }
/* TODO: check f is a function ! */
+ Py_XDECREF(pyCtxt->warningFunc);
Py_XINCREF(pyobj_f);
- ((xmlParserCtxtPyCtxt *)ctxt->_private)->warningFunc = pyobj_f;
+ pyCtxt->warningFunc = pyobj_f;
+ Py_XDECREF(pyCtxt->warningFuncArg);
Py_XINCREF(pyobj_arg);
- ((xmlParserCtxtPyCtxt *)ctxt->_private)->warningFuncArg = pyobj_arg;
+ pyCtxt->warningFuncArg = pyobj_arg;
ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler;
ctxt->vctxt.warning = libxml_xmlParserCtxtWarningFuncHandler;