diff options
author | Alexey Neyman <stilor@att.net> | 2013-02-25 16:07:09 +0800 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2013-02-25 16:07:09 +0800 |
commit | a9016c492788eb4792c42b52df0c72b46136787d (patch) | |
tree | b8f7e694aa0895286480c92832f91de67d02b8e6 /python/libxml.c | |
parent | 48da90bc4a3809728d08ee9ee8da21d044fbca82 (diff) | |
download | libxml2-a9016c492788eb4792c42b52df0c72b46136787d.tar.gz |
Fix a few problems with setEntityLoader
1. Setting entity loader does not increment the refcount on the Python object
passed in. This works only if the object is not deleted. For example, the
following code results in segmentation fault in Python interpreter when
attempting to process any document:
[[[
def register_entity_loader():
def entity_loader(URL, ID, ctxt):
...
libxml2.setEntityLoader(entity_loader
register_entity_loader()
]]]
2. setEntityLoader() does not verify if the passed object is callable. If it
is not, current implementation attempts to call it anyway and failing that,
silently moves on to default entity loader. Attached patch makes
setEntityLoader raise ValueError exception if non-callable object is
passed.
3. In debug mode, pythonExternalEntityLoader() outputs the result object to
stderr, while the messages before and after the object (description + newline)
go to stdout. Attached patch makes them all go to stdout.
Diffstat (limited to 'python/libxml.c')
-rw-r--r-- | python/libxml.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/python/libxml.c b/python/libxml.c index 9c013a66..8c66fed6 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -665,7 +665,7 @@ pythonExternalEntityLoader(const char *URL, const char *ID, Py_XDECREF(ctxtobj); #ifdef DEBUG_LOADER printf("pythonExternalEntityLoader: result "); - PyObject_Print(ret, stderr, 0); + PyObject_Print(ret, stdout, 0); printf("\n"); #endif @@ -711,13 +711,20 @@ libxml_xmlSetEntityLoader(ATTRIBUTE_UNUSED PyObject *self, PyObject *args) { &loader)) return(NULL); + if (!PyCallable_Check(loader)) { + PyErr_SetString(PyExc_ValueError, "entity loader is not callable"); + return(NULL); + } + #ifdef DEBUG_LOADER printf("libxml_xmlSetEntityLoader\n"); #endif if (defaultExternalEntityLoader == NULL) defaultExternalEntityLoader = xmlGetExternalEntityLoader(); + Py_XDECREF(pythonExternalEntityLoaderObjext); pythonExternalEntityLoaderObjext = loader; + Py_XINCREF(pythonExternalEntityLoaderObjext); xmlSetExternalEntityLoader(pythonExternalEntityLoader); py_retval = PyInt_FromLong(0); |