remove a memory leak on schemas type facets. reduce verbosity incorporated

* relaxng.c: remove a memory leak on schemas type facets.
* check-relaxng-test-suite.py check-relaxng-test-suite2.py
  check-xsddata-test-suite.py: reduce verbosity
* configure.in Makefile.am: incorporated the Python regressions
  tests for Relax-NG and Schemas Datatype to "make tests"
Daniel
diff --git a/ChangeLog b/ChangeLog
index 25d25c0..126ca50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Mar 22 20:07:27 CET 2004 Daniel Veillard <daniel@veillard.com>
+
+	* relaxng.c: remove a memory leak on schemas type facets.
+	* check-relaxng-test-suite.py check-relaxng-test-suite2.py
+	  check-xsddata-test-suite.py: reduce verbosity
+	* configure.in Makefile.am: incorporated the Python regressions
+	  tests for Relax-NG and Schemas Datatype to "make tests"
+
 Mon Mar 22 16:16:18 CET 2004 Daniel Veillard <daniel@veillard.com>
 
 	* xmlwriter.c include/libxml/xmlwriter.h doc/* : applied patch from
diff --git a/Makefile.am b/Makefile.am
index 70d350f..79f278d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -122,7 +122,7 @@
 
 testall : tests SVGtests SAXtests
 
-tests: XMLtests XMLenttests NStests Errtests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@  @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@
+tests: XMLtests XMLenttests NStests Errtests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@  @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@
 	@(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; $(MAKE) tests ; fi)
 	@(cd doc/examples ; $(MAKE) tests)
 
@@ -883,6 +883,20 @@
 	       fi ; fi ; \
 	  done; done)
 
+RelaxNGPythonTests:
+	@(if [ -x $(PYTHON) ] ; then \
+	    echo "## Relax-NG Python based test suite 1" ; \
+	    $(PYTHON) $(srcdir)/check-relaxng-test-suite.py ; \
+	    echo "## Relax-NG Python based test suite 2" ; \
+	    $(PYTHON) $(srcdir)/check-relaxng-test-suite2.py ; \
+	  fi)
+
+SchemasPythonTests:
+	@(if [ -x $(PYTHON) ] ; then \
+	    echo "## XML Schemas datatypes Python based test suite" ; \
+	    $(PYTHON) $(srcdir)/check-xsddata-test-suite.py ; \
+	  fi)
+
 cleanup:
 	-@(find . -name .\#\* -exec rm {} \;)
 
diff --git a/check-relaxng-test-suite.py b/check-relaxng-test-suite.py
index 2e378f4..0832758 100755
--- a/check-relaxng-test-suite.py
+++ b/check-relaxng-test-suite.py
@@ -11,6 +11,7 @@
 libxml2.debugMemory(1)
 debug = 0
 verbose = 0
+quiet = 1
 
 #
 # the testsuite description
@@ -44,6 +45,8 @@
 def resolver(URL, ID, ctxt):
     global resources
 
+    if string.find(URL, '#') != -1:
+        URL = URL[0:string.find(URL, '#')]
     if resources.has_key(URL):
         return(StringIO.StringIO(resources[URL]))
     log.write("Resolver failure: asked %s\n" % (URL))
@@ -306,6 +309,7 @@
 def handle_testSuite(node, level = 0):
     global nb_schemas_tests, nb_schemas_success, nb_schemas_failed
     global nb_instances_tests, nb_instances_success, nb_instances_failed
+    global quiet
     if level >= 1:
 	old_schemas_tests = nb_schemas_tests
 	old_schemas_success = nb_schemas_success
@@ -324,13 +328,15 @@
 	    msg = msg + "written by "
 	    for author in authors:
 	        msg = msg + author.content + " "
-	print msg
+	if quiet == 0:
+	    print msg
     sections = node.xpathEval('section')
     if sections != [] and level <= 0:
         msg = ""
         for section in sections:
 	    msg = msg + section.content + " "
-        print "Tests for section %s" % (msg)
+	if quiet == 0:
+	    print "Tests for section %s" % (msg)
     for test in node.xpathEval('testCase'):
         handle_testCase(test)
     for test in node.xpathEval('testSuite'):
@@ -362,12 +368,17 @@
 if root.name != 'testSuite':
     print "%s doesn't start with a testSuite element, aborting" % (CONF)
     sys.exit(1)
-print "Running Relax NG testsuite"
+if quiet == 0:
+    print "Running Relax NG testsuite"
 handle_testSuite(root)
 
-print "\nTOTAL:\nfound %d test schemas: %d success %d failures" % (
+if quiet == 0:
+    print "\nTOTAL:\n"
+if quiet == 0 or nb_schemas_failed != 0:
+    print "found %d test schemas: %d success %d failures" % (
       nb_schemas_tests, nb_schemas_success, nb_schemas_failed)
-print "found %d test instances: %d success %d failures" % (
+if quiet == 0 or nb_instances_failed != 0:
+    print "found %d test instances: %d success %d failures" % (
       nb_instances_tests, nb_instances_success, nb_instances_failed)
 
 testsuite.freeDoc()
@@ -376,7 +387,8 @@
 libxml2.relaxNGCleanupTypes()
 libxml2.cleanupParser()
 if libxml2.debugMemory(1) == 0:
-    print "OK"
+    if quiet == 0:
+	print "OK"
 else:
     print "Memory leak %d bytes" % (libxml2.debugMemory(1))
     libxml2.dumpMemory()
diff --git a/check-relaxng-test-suite2.py b/check-relaxng-test-suite2.py
index 6a2b6eb..639e587 100755
--- a/check-relaxng-test-suite2.py
+++ b/check-relaxng-test-suite2.py
@@ -10,6 +10,7 @@
 # Memory debug specific
 libxml2.debugMemory(1)
 debug = 0
+quiet = 1
 
 #
 # the testsuite description
@@ -67,7 +68,7 @@
 	    instance = instance + child.serialize()
 	child = child.next
 
-    mem = libxml2.debugMemory(1);
+#    mem = libxml2.debugMemory(1);
     try:
 	doc = libxml2.parseDoc(instance)
     except:
@@ -91,9 +92,9 @@
         ret = -1
 
     doc.freeDoc()
-    if mem != libxml2.debugMemory(1):
-	print "validating instance %d line %d leaks" % (
-		  nb_instances_tests, node.lineNo())
+#    if mem != libxml2.debugMemory(1):
+#	print "validating instance %d line %d leaks" % (
+#		  nb_instances_tests, node.lineNo())
 
     if ret != 0:
         log.write("\nFailed to validate correct instance:\n-----\n")
@@ -120,7 +121,7 @@
 	    instance = instance + child.serialize()
 	child = child.next
 
-    mem = libxml2.debugMemory(1);
+#    mem = libxml2.debugMemory(1);
 
     try:
 	doc = libxml2.parseDoc(instance)
@@ -145,9 +146,10 @@
         ret = -1
 
     doc.freeDoc()
-    if mem != libxml2.debugMemory(1):
-	print "validating instance %d line %d leaks" % (
-		  nb_instances_tests, node.lineNo())
+#    mem2 = libxml2.debugMemory(1)
+#    if mem != mem2:
+#	print "validating instance %d line %d leaks %d bytes" % (
+#		  nb_instances_tests, node.lineNo(), mem2 - mem)
     
     if ret == 0:
         log.write("\nFailed to detect validation problem in instance:\n-----\n")
@@ -339,13 +341,15 @@
 	    msg = msg + "written by "
 	    for author in authors:
 	        msg = msg + author.content + " "
-	print msg
+	if quiet == 0:
+	    print msg
     sections = node.xpathEval('section')
     if sections != [] and level <= 0:
         msg = ""
         for section in sections:
 	    msg = msg + section.content + " "
-        print "Tests for section %s" % (msg)
+	if quiet == 0:
+	    print "Tests for section %s" % (msg)
     for test in node.xpathEval('testCase'):
         handle_testCase(test)
     for test in node.xpathEval('testSuite'):
@@ -387,21 +391,28 @@
 if root.name != 'testSuite':
     print "%s doesn't start with a testSuite element, aborting" % (CONF)
     sys.exit(1)
-print "Running Relax NG testsuite"
+if quiet == 0:
+    print "Running Relax NG testsuite"
 handle_testSuite(root)
 
-print "\nTOTAL:\nfound %d test schemas: %d success %d failures" % (
+if quiet == 0:
+    print "\nTOTAL:\n"
+if quiet == 0 or nb_schemas_failed != 0:
+    print "found %d test schemas: %d success %d failures" % (
       nb_schemas_tests, nb_schemas_success, nb_schemas_failed)
-print "found %d test instances: %d success %d failures" % (
+if quiet == 0 or nb_instances_failed != 0:
+    print "found %d test instances: %d success %d failures" % (
       nb_instances_tests, nb_instances_success, nb_instances_failed)
 
+
 testsuite.freeDoc()
 
 # Memory debug specific
 libxml2.relaxNGCleanupTypes()
 libxml2.cleanupParser()
 if libxml2.debugMemory(1) == 0:
-    print "OK"
+    if quiet == 0:
+	print "OK"
 else:
     print "Memory leak %d bytes" % (libxml2.debugMemory(1))
     libxml2.dumpMemory()
diff --git a/check-xsddata-test-suite.py b/check-xsddata-test-suite.py
index 2fbdc84..f2066e1 100755
--- a/check-xsddata-test-suite.py
+++ b/check-xsddata-test-suite.py
@@ -10,7 +10,8 @@
 # Memory debug specific
 libxml2.debugMemory(1)
 debug = 0
-verbose = 1
+verbose = 0
+quiet = 1
 
 #
 # the testsuite description
@@ -119,7 +120,7 @@
 	    instance = instance + child.serialize()
 	child = child.next
 
-    mem = libxml2.debugMemory(1);
+#    mem = libxml2.debugMemory(1);
 
     try:
 	doc = libxml2.parseDoc(instance)
@@ -144,9 +145,9 @@
         ret = -1
 
     doc.freeDoc()
-    if mem != libxml2.debugMemory(1):
-	print "validating instance %d line %d leaks" % (
-		  nb_instances_tests, node.lineNo())
+#    if mem != libxml2.debugMemory(1):
+#	print "validating instance %d line %d leaks" % (
+#		  nb_instances_tests, node.lineNo())
     
     if ret == 0:
         log.write("\nFailed to detect validation problem in instance:\n-----\n")
@@ -338,13 +339,15 @@
 	    msg = msg + "written by "
 	    for author in authors:
 	        msg = msg + author.content + " "
-	print msg
+	if quiet == 0:
+	    print msg
     sections = node.xpathEval('section')
     if verbose and sections != [] and level <= 0:
         msg = ""
         for section in sections:
 	    msg = msg + section.content + " "
-        print "Tests for section %s" % (msg)
+	if quiet == 0:
+	    print "Tests for section %s" % (msg)
     for test in node.xpathEval('testCase'):
         handle_testCase(test)
     for test in node.xpathEval('testSuite'):
@@ -393,12 +396,15 @@
 if root.name != 'testSuite':
     print "%s doesn't start with a testSuite element, aborting" % (CONF)
     sys.exit(1)
-print "Running Relax NG testsuite"
+if quiet == 0:
+    print "Running Relax NG testsuite"
 handle_testSuite(root)
 
-print "\nTOTAL:\nfound %d test schemas: %d success %d failures" % (
+if quiet == 0 or nb_schemas_failed != 0:
+    print "\nTOTAL:\nfound %d test schemas: %d success %d failures" % (
       nb_schemas_tests, nb_schemas_success, nb_schemas_failed)
-print "found %d test instances: %d success %d failures" % (
+if quiet == 0 or nb_instances_failed != 0:
+    print "found %d test instances: %d success %d failures" % (
       nb_instances_tests, nb_instances_success, nb_instances_failed)
 
 testsuite.freeDoc()
@@ -407,7 +413,8 @@
 libxml2.relaxNGCleanupTypes()
 libxml2.cleanupParser()
 if libxml2.debugMemory(1) == 0:
-    print "OK"
+    if quiet == 0:
+	print "OK"
 else:
     print "Memory leak %d bytes" % (libxml2.debugMemory(1))
     libxml2.dumpMemory()
diff --git a/config.h.in b/config.h.in
index 915ef0c..f54d0bf 100644
--- a/config.h.in
+++ b/config.h.in
@@ -256,7 +256,7 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
-/* Define if compiler has function prototypes */
+/* Define to 1 if the C compiler supports function prototypes. */
 #undef PROTOTYPES
 
 /* Determine what socket length (socklen_t) data type is */
@@ -274,6 +274,9 @@
 /* Using the Win32 Socket implementation */
 #undef _WINSOCKAPI_
 
+/* Define like PROTOTYPES; this can be used by system headers. */
+#undef __PROTOTYPES
+
 /* Win32 Std C name mangling work-around */
 #undef snprintf
 
diff --git a/configure.in b/configure.in
index 07d6fa5..77771c0 100644
--- a/configure.in
+++ b/configure.in
@@ -326,6 +326,7 @@
 PYTHON_VERSION=
 PYTHON_INCLUDES=
 PYTHON_SITE_PACKAGES=
+PYTHON_TESTS=
 pythondir=
 AC_ARG_WITH(python,
 [  --with-python[[=DIR]]     build Python bindings if found])
@@ -954,6 +955,9 @@
     echo "Enabled Schemas/Relax-NG support"
     WITH_SCHEMAS=1
     TEST_SCHEMAS="Schemastests Relaxtests"
+    if test "$PYTHON_INCLUDES" != "" ; then
+        PYTHON_TESTS="$PYTHON_TESTS RelaxNGPythonTests SchemasPythonTests"
+    fi
     with_regexps=yes
 fi
 AC_SUBST(WITH_SCHEMAS)
@@ -1049,6 +1053,7 @@
 dnl for the spec file
 RELDATE=`date +'%a %b %e %Y'`
 AC_SUBST(RELDATE)
+AC_SUBST(PYTHON_TESTS)
 
 rm -f COPYING.LIB COPYING
 ln -s Copyright COPYING
diff --git a/relaxng.c b/relaxng.c
index 9292497..1fd46e9 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -2501,7 +2501,7 @@
         xmlSchemaFreeFacet(facet);
         return (-1);
     }
-    facet->value = xmlStrdup(val);
+    facet->value = val;
     ret = xmlSchemaCheckFacet(facet, typ, NULL, type);
     if (ret != 0) {
         xmlSchemaFreeFacet(facet);
@@ -6871,6 +6871,7 @@
                     xmlChar *href, *ns, *base, *URL;
                     xmlRelaxNGDocumentPtr docu;
                     xmlNodePtr tmp;
+		    xmlURIPtr uri;
 
                     ns = xmlGetProp(cur, BAD_CAST "ns");
                     if (ns == NULL) {
@@ -6891,6 +6892,27 @@
                         delete = cur;
                         goto skip_children;
                     }
+		    uri = xmlParseURI((const char *) href);
+		    if (uri == NULL) {
+                        xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
+                                   "Incorrect URI for externalRef %s\n",
+                                   href, NULL);
+                        if (href != NULL)
+                            xmlFree(href);
+                        delete = cur;
+                        goto skip_children;
+		    }
+		    if (uri->fragment != NULL) {
+                        xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
+			       "Fragment forbidden in URI for externalRef %s\n",
+                                   href, NULL);
+		        xmlFreeURI(uri);
+                        if (href != NULL)
+                            xmlFree(href);
+                        delete = cur;
+                        goto skip_children;
+		    }
+		    xmlFreeURI(uri);
                     base = xmlNodeGetBase(cur->doc, cur);
                     URL = xmlBuildURI(href, base);
                     if (URL == NULL) {