libxml2 r3791 - in trunk: . python/tests



Author: veillard
Date: Mon Sep  1 13:38:22 2008
New Revision: 3791
URL: http://svn.gnome.org/viewvc/libxml2?rev=3791&view=rev

Log:
* schematron.c xpath.c: applied a couple of patches from Martin
  avoiding some leaks, fixinq QName checks in XPath, XPath debugging
  and schematron code cleanups.
* python/tests/Makefile.am python/tests/xpathleak.py: add the
  specific regression tests, just tweak it to avoid output by default
Daniel


Added:
   trunk/python/tests/xpathleak.py
Modified:
   trunk/ChangeLog
   trunk/python/tests/Makefile.am
   trunk/schematron.c
   trunk/xpath.c

Modified: trunk/python/tests/Makefile.am
==============================================================================
--- trunk/python/tests/Makefile.am	(original)
+++ trunk/python/tests/Makefile.am	Mon Sep  1 13:38:22 2008
@@ -46,7 +46,8 @@
     validSchemas.py \
     validRNG.py \
     compareNodes.py \
-    xpathns.py
+    xpathns.py \
+    xpathleak.py
 
 XMLS=		\
     tst.xml	\

Added: trunk/python/tests/xpathleak.py
==============================================================================
--- (empty file)
+++ trunk/python/tests/xpathleak.py	Mon Sep  1 13:38:22 2008
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+import sys, libxml2
+
+libxml2.debugMemory(True)
+
+expect="""--> Invalid expression
+--> xmlXPathEval: evaluation failed
+--> Invalid expression
+--> xmlXPathEval: evaluation failed
+--> Invalid expression
+--> xmlXPathEval: evaluation failed
+--> Invalid expression
+--> xmlXPathEval: evaluation failed
+--> Invalid expression
+--> xmlXPathEval: evaluation failed
+--> Invalid expression
+--> xmlXPathEval: evaluation failed
+"""
+err=""
+def callback(ctx, str):
+     global err
+
+     err = err + "%s %s" % (ctx, str)
+
+libxml2.registerErrorHandler(callback, "-->")
+
+doc = libxml2.parseDoc("<fish/>")
+ctxt = doc.xpathNewContext()
+ctxt.setContextNode(doc)
+for expr in (":false()","bad:()","bad(:)",":bad(:)","bad:(:)","bad:bad(:)"):
+	try:
+		ctxt.xpathEval(expr)
+	except libxml2.xpathError, e:
+	        pass
+	else:
+		print "Unexpectedly legal expression:", expr
+ctxt.xpathFreeContext()
+doc.freeDoc()
+
+if err != expect:
+    print "error"
+    print "received %s" %(err)
+    print "expected %s" %(expect)
+    sys.exit(1)
+
+libxml2.cleanupParser()
+leakedbytes = libxml2.debugMemory(True)
+if leakedbytes == 0:
+	print "OK"
+else:
+	print "Memory leak", leakedbytes, "bytes"
+	# drop file to .memdump file in cwd, but won't work if not compiled in
+	libxml2.dumpMemory()

Modified: trunk/schematron.c
==============================================================================
--- trunk/schematron.c	(original)
+++ trunk/schematron.c	Mon Sep  1 13:38:22 2008
@@ -1691,7 +1691,7 @@
 		if (xmlPatternMatch(rule->pattern, cur) == 1) {
 		    test = rule->tests;
 		    while (test != NULL) {
-			xmlSchematronRunTest(ctxt, test, instance, cur, rule->pattern);
+			xmlSchematronRunTest(ctxt, test, instance, cur, (xmlSchematronPatternPtr)rule->pattern);
 			test = test->next;
 		    }
 		}

Modified: trunk/xpath.c
==============================================================================
--- trunk/xpath.c	(original)
+++ trunk/xpath.c	Mon Sep  1 13:38:22 2008
@@ -187,11 +187,11 @@
  * TODO: when compatibility allows remove all "fake node libxslt" strings
  *       the test should just be name[0] = ' '
  */
-/* #define DEBUG */
-/* #define DEBUG_STEP */
-/* #define DEBUG_STEP_NTH */
-/* #define DEBUG_EXPR */
-/* #define DEBUG_EVAL_COUNTS */
+#ifdef DEBUG_XPATH_EXPRESSION
+#define DEBUG_STEP
+#define DEBUG_EXPR
+#define DEBUG_EVAL_COUNTS
+#endif
 
 static xmlNs xmlXPathXMLNamespaceStruct = {
     NULL,
@@ -9778,7 +9778,7 @@
 
     *prefix = NULL;
     ret = xmlXPathParseNCName(ctxt);
-    if (CUR == ':') {
+    if (ret && CUR == ':') {
         *prefix = ret;
 	NEXT;
 	ret = xmlXPathParseNCName(ctxt);
@@ -10274,6 +10274,7 @@
 
     name = xmlXPathParseQName(ctxt, &prefix);
     if (name == NULL) {
+	xmlFree(prefix);
 	XP_ERROR(XPATH_EXPR_ERROR);
     }
     SKIP_BLANKS;
@@ -10306,7 +10307,11 @@
 	    int op1 = ctxt->comp->last;
 	    ctxt->comp->last = -1;
 	    xmlXPathCompileExpr(ctxt, sort);
-	    CHECK_ERROR;
+	    if (ctxt->error != XPATH_EXPRESSION_OK) {
+		xmlFree(name);
+		xmlFree(prefix);
+		return;
+	    }
 	    PUSH_BINARY_EXPR(XPATH_OP_ARG, op1, ctxt->comp->last, 0, 0);
 	    nbargs++;
 	    if (CUR == ')') break;
@@ -11401,12 +11406,11 @@
 
 #ifdef DEBUG_STEP
 static void
-xmlXPathDebugDumpStepAxis(xmlXPathAxisVal axis,
-			  xmlXPathTestVal test,
+xmlXPathDebugDumpStepAxis(xmlXPathStepOpPtr op,
 			  int nbNodes)
 {
     xmlGenericError(xmlGenericErrorContext, "new step : ");
-    switch (axis) {
+    switch (op->value) {
         case AXIS_ANCESTOR:
             xmlGenericError(xmlGenericErrorContext, "axis 'ancestors' ");
             break;
@@ -11453,14 +11457,14 @@
     }
     xmlGenericError(xmlGenericErrorContext,
 	" context contains %d nodes\n", nbNodes);
-    switch (test) {
+    switch (op->value2) {
         case NODE_TEST_NONE:
             xmlGenericError(xmlGenericErrorContext,
                             "           searching for none !!!\n");
             break;
         case NODE_TEST_TYPE:
             xmlGenericError(xmlGenericErrorContext,
-                            "           searching for type %d\n", type);
+                            "           searching for type %d\n", op->value3);
             break;
         case NODE_TEST_PI:
             xmlGenericError(xmlGenericErrorContext,
@@ -11473,14 +11477,14 @@
         case NODE_TEST_NS:
             xmlGenericError(xmlGenericErrorContext,
                             "           searching for namespace %s\n",
-                            prefix);
+                            op->value5);
             break;
         case NODE_TEST_NAME:
             xmlGenericError(xmlGenericErrorContext,
-                            "           searching for name %s\n", name);
-            if (prefix != NULL)
+                            "           searching for name %s\n", op->value5);
+            if (op->value4)
                 xmlGenericError(xmlGenericErrorContext,
-                                "           with namespace %s\n", prefix);
+                                "           with namespace %s\n", op->value4);
             break;
     }
     xmlGenericError(xmlGenericErrorContext, "Testing : ");
@@ -12055,8 +12059,8 @@
     }
 
 #ifdef DEBUG_STEP
-    xmlXPathDebugDumpStepAxis(axis, test,
-	(obj->nodesetval != NULL) ? obj->nodsetval->nodeNr : 0);
+    xmlXPathDebugDumpStepAxis(op,
+	(obj->nodesetval != NULL) ? obj->nodesetval->nodeNr : 0);
 #endif
 
     if (next == NULL) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]