diff --git a/ChangeLog b/ChangeLog index eb37a3e8..5a4fc9f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Jul 3 11:31:02 HKT 2004 William Brack + + * python/libxml.c: Changed the number of XPath extension functions + allowed to be variable-length (patch supplied by Marc-Antoine + Parent, bug 143805). Added code to "unregister" the functions + when the parser cleanup takes place. + Fri Jul 2 14:22:14 CEST 2004 Daniel Veillard * xmlmemory.c python/libxml.c python/libxml2-python-api.xml: diff --git a/python/libxml.c b/python/libxml.c index b58c526c..3db0f5ff 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -52,6 +52,22 @@ void initlibxml2mod(void); xmlGenericError(xmlGenericErrorContext, \ "Unimplemented block at %s:%d\n", \ __FILE__, __LINE__); +/* + * the following vars are used for XPath extensions, but + * are also referenced within the parser cleanup routine. + */ +static int libxml_xpathCallbacksInitialized = 0; + +typedef struct libxml_xpathCallback { + xmlXPathContextPtr ctx; + xmlChar *name; + xmlChar *ns_uri; + PyObject *function; +} libxml_xpathCallback, *libxml_xpathCallbackPtr; +typedef libxml_xpathCallback libxml_xpathCallbackArray[]; +static int libxml_xpathCallbacksAllocd = 10; +static libxml_xpathCallbackArray *libxml_xpathCallbacks = NULL; +static int libxml_xpathCallbacksNb = 0; /************************************************************************ * * @@ -159,13 +175,30 @@ PyObject * libxml_xmlPythonCleanupParser(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED) { - long freed; + int ix; + long freed = -1; if (libxmlMemoryDebug) { freed = xmlMemUsed(); } xmlCleanupParser(); + /* + * Need to confirm whether we really want to do this (required for + * memcheck) in all cases... + */ + + if (libxml_xpathCallbacks != NULL) { /* if ext funcs declared */ + for (ix=0; ix= libxml_xpathCallbacksMax) { - printf("libxml_registerXPathFunction() table full\n"); - } else { - i = libxml_xpathCallbacksNb++; - Py_XINCREF(pyobj_f); - libxml_xpathCallbacks[i].ctx = ctx; - libxml_xpathCallbacks[i].name = xmlStrdup(name); - libxml_xpathCallbacks[i].ns_uri = xmlStrdup(ns_uri); - libxml_xpathCallbacks[i].function = pyobj_f; + if (libxml_xpathCallbacksNb >= libxml_xpathCallbacksAllocd) { + libxml_xpathCallbacksAllocd+=10; + libxml_xpathCallbacks = (libxml_xpathCallbackArray*)xmlRealloc( + libxml_xpathCallbacks, + libxml_xpathCallbacksAllocd*sizeof(libxml_xpathCallback)); + } + i = libxml_xpathCallbacksNb++; + Py_XINCREF(pyobj_f); + (*libxml_xpathCallbacks)[i].ctx = ctx; + (*libxml_xpathCallbacks)[i].name = xmlStrdup(name); + (*libxml_xpathCallbacks)[i].ns_uri = xmlStrdup(ns_uri); + (*libxml_xpathCallbacks)[i].function = pyobj_f; c_retval = 1; - } + done: py_retval = libxml_intWrap((int) c_retval); return (py_retval); @@ -3277,7 +3303,7 @@ initlibxml2mod(void) if (initialized != 0) return; - + /* intialize the python extension module */ Py_InitModule((char *) "libxml2mod", libxmlMethods);