diff --git a/ChangeLog b/ChangeLog index 6f8439c7..c1200f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Feb 6 17:04:51 CET 2002 Daniel Veillard + + * python/TODO python/libxml.c: cleanup the extension function lookup + * xmlmemory.c include/libxml/xmlmemory.h: always compile the list + Tue Feb 5 17:33:30 CET 2002 Daniel Veillard * configure.in python/Makefile.am: do not install outside diff --git a/include/libxml/xmlmemory.h b/include/libxml/xmlmemory.h index 1802af15..89386948 100644 --- a/include/libxml/xmlmemory.h +++ b/include/libxml/xmlmemory.h @@ -39,13 +39,6 @@ * libxml i.e. if libxml has been configured with --with-debug-mem too */ #ifdef DEBUG_MEMORY_LOCATION - -/** - * MEM_LIST: - * - * keep track of all allocated blocks for error reporting - */ -#define MEM_LIST /* keep a list of all the allocated memory blocks */ #endif #ifdef __cplusplus diff --git a/python/TODO b/python/TODO index a19dfe4e..f446f6e1 100644 --- a/python/TODO +++ b/python/TODO @@ -13,6 +13,8 @@ Things to do: - access to XPath variables - xmlBuffer exposure - xpathContext, being able to set/get info and clean it up +- more work needed on context handling for function lookup + and use of an hash table. - add regression tests - SAX flow - DTD element and attributes content accesses diff --git a/python/libxml.c b/python/libxml.c index 6b4d4fe0..62d9dcd5 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -769,19 +769,43 @@ static libxml_xpathCallback libxml_xpathCallbacks[10]; static int libxml_xpathCallbacksNb = 0; static int libxml_xpathCallbacksMax = 10; -/* TODO: this is not reentrant !!! MUST FIX with a per context hash */ -static PyObject *current_function = NULL; - static void libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) { PyObject *list, *cur, *result; xmlXPathObjectPtr obj; + xmlXPathContextPtr rctxt; + PyObject *current_function = NULL; + const xmlChar *name; + const xmlChar *ns_uri; int i; + if (ctxt == NULL) + return; + rctxt = ctxt->context; + if (rctxt == NULL) + return; + name = rctxt->function; + ns_uri = rctxt->functionURI; #ifdef DEBUG_XPATH - printf("libxml_xmlXPathFuncCallback called\n"); + printf("libxml_xmlXPathFuncCallback called name %s URI %s\n", name, ns_uri); #endif + /* + * Find the function, it should be there it was there at lookup + */ + for (i = 0;i < libxml_xpathCallbacksNb;i++) { + if (/* TODO (ctxt == libxml_xpathCallbacks[i].ctx) && */ + (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) && + (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) { + current_function = libxml_xpathCallbacks[i].function; + } + } + if (current_function == NULL) { + printf("libxml_xmlXPathFuncCallback: internal error %s not found !\n", + name); + return; + } + list = PyTuple_New(nargs); for (i = 0;i < nargs;i++) { obj = valuePop(ctxt); @@ -803,15 +827,19 @@ libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar *name, printf("libxml_xmlXPathFuncLookupFunc(%p, %s, %s) called\n", ctxt, name, ns_uri); #endif + /* + * This is called once only. The address is then stored in the + * XPath expression evaluation, the proper object to call can + * then still be found using the execution context function + * and functionURI fields. + */ for (i = 0;i < libxml_xpathCallbacksNb;i++) { if ((ctxt == libxml_xpathCallbacks[i].ctx) && (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) && (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) { - current_function = libxml_xpathCallbacks[i].function; return(libxml_xmlXPathFuncCallback); } } - current_function = NULL; return(NULL); } @@ -832,7 +860,6 @@ libxml_xpathCallbacksInitialize(void) { libxml_xpathCallbacks[i].ns_uri = NULL; libxml_xpathCallbacks[i].function = NULL; } - current_function = NULL; libxml_xpathCallbacksInitialized = 1; } diff --git a/xmlmemory.c b/xmlmemory.c index afb8b8aa..57a7ce59 100644 --- a/xmlmemory.c +++ b/xmlmemory.c @@ -24,6 +24,15 @@ #include #endif +/** + * MEM_LIST: + * + * keep track of all allocated blocks for error reporting + * Always build the memory list ! + */ +#ifndef MEM_LIST +#define MEM_LIST /* keep a list of all the allocated memory blocks */ +#endif #include #include @@ -638,7 +647,6 @@ static FILE *xmlMemoryDumpFile = NULL; void xmlMemoryDump(void) { -#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY) FILE *dump; dump = fopen(".memdump", "w"); @@ -649,7 +657,6 @@ xmlMemoryDump(void) xmlMemDisplay(xmlMemoryDumpFile); if (dump != NULL) fclose(dump); -#endif }