1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-30 22:43:14 +03:00

cleanup patch from Stphane Bidoul Daniel

* python/libxml.c: cleanup patch from Stphane Bidoul
Daniel
This commit is contained in:
Daniel Veillard
2003-01-14 14:40:25 +00:00
parent 81601f9834
commit e4a07e7b77
2 changed files with 31 additions and 7 deletions

View File

@ -1,3 +1,7 @@
Tue Jan 14 15:39:14 CET 2003 Daniel Veillard <daniel@veillard.com>
* python/libxml.c: cleanup patch from St<53>phane Bidoul
Tue Jan 14 14:41:18 CET 2003 Daniel Veillard <daniel@veillard.com> Tue Jan 14 14:41:18 CET 2003 Daniel Veillard <daniel@veillard.com>
* encoding.c: fixing bug #103100 with a dummy UTF8ToUTF8 copy * encoding.c: fixing bug #103100 with a dummy UTF8ToUTF8 copy
@ -6,7 +10,7 @@ Tue Jan 14 12:40:29 CET 2003 Daniel Veillard <daniel@veillard.com>
* python/generator.py python/libxml.c python/libxml.py * python/generator.py python/libxml.c python/libxml.py
python/libxml_wrap.h python/types.c: applied and fixed a patch 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<EFBFBD>phane Bidoul to provide per parser error handlers at the
Python level. Python level.
* python/tests/Makefile.am python/tests/ctxterror.py: added a * python/tests/Makefile.am python/tests/ctxterror.py: added a
regression test for it. regression test for it.

View File

@ -439,6 +439,7 @@ pythonExternalEntityLoader(const char *URL, const char *ID,
ret = PyObject_CallFunction(pythonExternalEntityLoaderObjext, ret = PyObject_CallFunction(pythonExternalEntityLoaderObjext,
(char *) "(ssO)", URL, ID, ctxtobj); (char *) "(ssO)", URL, ID, ctxtobj);
Py_XDECREF(ctxtobj);
#ifdef DEBUG_LOADER #ifdef DEBUG_LOADER
printf("pythonExternalEntityLoader: result "); printf("pythonExternalEntityLoader: result ");
PyObject_Print(ret, stdout, 0); PyObject_Print(ret, stdout, 0);
@ -1372,6 +1373,7 @@ libxml_xmlSetParserCtxtErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *a
{ {
PyObject *py_retval; PyObject *py_retval;
xmlParserCtxtPtr ctxt; xmlParserCtxtPtr ctxt;
xmlParserCtxtPyCtxtPtr pyCtxt;
PyObject *pyobj_ctxt; PyObject *pyobj_ctxt;
PyObject *pyobj_f; PyObject *pyobj_f;
PyObject *pyobj_arg; PyObject *pyobj_arg;
@ -1381,8 +1383,6 @@ libxml_xmlSetParserCtxtErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *a
return(NULL); return(NULL);
ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt);
if (ctxt->_private == NULL) { if (ctxt->_private == NULL) {
xmlParserCtxtPyCtxt *pyCtxt;
pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt)); pyCtxt = xmlMalloc(sizeof(xmlParserCtxtPyCtxt));
if (pyCtxt == NULL) { if (pyCtxt == NULL) {
py_retval = libxml_intWrap(-1); py_retval = libxml_intWrap(-1);
@ -1391,11 +1391,16 @@ libxml_xmlSetParserCtxtErrorHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject *a
memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt)); memset(pyCtxt,0,sizeof(xmlParserCtxtPyCtxt));
ctxt->_private = pyCtxt; ctxt->_private = pyCtxt;
} }
else {
pyCtxt = ctxt->_private;
}
/* TODO: check f is a function ! */ /* TODO: check f is a function ! */
Py_XDECREF(pyCtxt->errorFunc);
Py_XINCREF(pyobj_f); Py_XINCREF(pyobj_f);
((xmlParserCtxtPyCtxt *)ctxt->_private)->errorFunc = pyobj_f; pyCtxt->errorFunc = pyobj_f;
Py_XDECREF(pyCtxt->errorFuncArg);
Py_XINCREF(pyobj_arg); Py_XINCREF(pyobj_arg);
((xmlParserCtxtPyCtxt *)ctxt->_private)->errorFuncArg = pyobj_arg; pyCtxt->errorFuncArg = pyobj_arg;
ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler; ctxt->sax->error = libxml_xmlParserCtxtErrorFuncHandler;
ctxt->vctxt.error = libxml_xmlParserCtxtErrorFuncHandler; ctxt->vctxt.error = libxml_xmlParserCtxtErrorFuncHandler;
@ -1445,6 +1450,7 @@ libxml_xmlSetParserCtxtWarningHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject
{ {
PyObject *py_retval; PyObject *py_retval;
xmlParserCtxtPtr ctxt; xmlParserCtxtPtr ctxt;
xmlParserCtxtPyCtxtPtr pyCtxt;
PyObject *pyobj_ctxt; PyObject *pyobj_ctxt;
PyObject *pyobj_f; PyObject *pyobj_f;
PyObject *pyobj_arg; PyObject *pyobj_arg;
@ -1452,11 +1458,25 @@ libxml_xmlSetParserCtxtWarningHandler(ATTRIBUTE_UNUSED PyObject *self, PyObject
if (!PyArg_ParseTuple(args, (char *)"OOO:xmlSetParserCtxtWarningHandler", &pyobj_ctxt, &pyobj_f, &pyobj_arg)) if (!PyArg_ParseTuple(args, (char *)"OOO:xmlSetParserCtxtWarningHandler", &pyobj_ctxt, &pyobj_f, &pyobj_arg))
return(NULL); return(NULL);
ctxt = (xmlParserCtxtPtr) PyparserCtxt_Get(pyobj_ctxt); 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 ! */ /* TODO: check f is a function ! */
Py_XDECREF(pyCtxt->warningFunc);
Py_XINCREF(pyobj_f); Py_XINCREF(pyobj_f);
((xmlParserCtxtPyCtxt *)ctxt->_private)->warningFunc = pyobj_f; pyCtxt->warningFunc = pyobj_f;
Py_XDECREF(pyCtxt->warningFuncArg);
Py_XINCREF(pyobj_arg); Py_XINCREF(pyobj_arg);
((xmlParserCtxtPyCtxt *)ctxt->_private)->warningFuncArg = pyobj_arg; pyCtxt->warningFuncArg = pyobj_arg;
ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler; ctxt->sax->warning = libxml_xmlParserCtxtWarningFuncHandler;
ctxt->vctxt.warning = libxml_xmlParserCtxtWarningFuncHandler; ctxt->vctxt.warning = libxml_xmlParserCtxtWarningFuncHandler;