diff --git a/ChangeLog b/ChangeLog index 3c5f78b9..898b3c46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,12 @@ -Sun Feb 9 15:18:43 CET 2003 Igor Zlatkovic +Mon Feb 10 00:30:01 CET 2003 Daniel Veillard + + * xpath.c: fixed doc comment problems + * python/generator.py python/libxml_wrap.h python/types.c: adding + RelaxNG wrappers + * python/tests/Makefile.am python/tests/relaxng.py: added a specific + test of those early Python RelaxNG bindings + +Sun Feb 9 15:18:43 CET 2003 Daniel Veillard * libxml.spec.in: fixes a libtool problem on AMD 64bits builds * relaxng.c: found the validation problem I had with interleave diff --git a/python/generator.py b/python/generator.py index 95212d6f..fc80417b 100755 --- a/python/generator.py +++ b/python/generator.py @@ -273,6 +273,9 @@ py_types = { 'xmlRegexpPtr': ('O', "xmlReg", "xmlRegexpPtr", "xmlRegexpPtr"), 'xmlTextReaderLocatorPtr': ('O', "xmlTextReaderLocator", "xmlTextReaderLocatorPtr", "xmlTextReaderLocatorPtr"), 'xmlTextReaderPtr': ('O', "xmlTextReader", "xmlTextReaderPtr", "xmlTextReaderPtr"), + 'xmlRelaxNGPtr': ('O', "relaxNgSchema", "xmlRelaxNGPtr", "xmlRelaxNGPtr"), + 'xmlRelaxNGParserCtxtPtr': ('O', "relaxNgParserCtxt", "xmlRelaxNGParserCtxtPtr", "xmlRelaxNGParserCtxtPtr"), + 'xmlRelaxNGValidCtxtPtr': ('O', "relaxNgValidCtxt", "xmlRelaxNGValidCtxtPtr", "xmlRelaxNGValidCtxtPtr"), } py_return_types = { @@ -615,6 +618,9 @@ classes_type = { "xmlRegexpPtr": ("._o", "xmlReg(_obj=%s)", "xmlReg"), "xmlTextReaderLocatorPtr": ("._o", "xmlTextReaderLocator(_obj=%s)", "xmlTextReaderLocator"), "xmlTextReaderPtr": ("._o", "xmlTextReader(_obj=%s)", "xmlTextReader"), + 'xmlRelaxNGPtr': ('._o', "relaxNgSchema(_obj=%s)", "relaxNgSchema"), + 'xmlRelaxNGParserCtxtPtr': ('._o', "relaxNgParserCtxt(_obj=%s)", "relaxNgParserCtxt"), + 'xmlRelaxNGValidCtxtPtr': ('._o', "relaxNgValidCtxt(_obj=%s)", "relaxNgValidCtxt"), } converter_type = { @@ -645,6 +651,9 @@ classes_destructors = { "inputBuffer": "xmlFreeParserInputBuffer", "xmlReg": "xmlRegFreeRegexp", "xmlTextReader": "xmlFreeTextReader", + "relaxNgSchema": "xmlRelaxNGFree", + "relaxNgParserCtxt": "xmlRelaxNGFreeParserCtxt", + "relaxNgValidCtxt": "xmlRelaxNGFreeValidCtxt", } functions_noexcept = { @@ -655,6 +664,7 @@ functions_noexcept = { reference_keepers = { "xmlTextReader": [('inputBuffer', 'input')], + "relaxNgValidCtxt": [('relaxNgSchema', 'schema')], } function_classes = {} diff --git a/python/libxml2class.txt b/python/libxml2class.txt index 72607a4b..8f1e8636 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -128,6 +128,8 @@ setEntityLoader() # functions from module relaxng relaxNGCleanupTypes() +relaxNGNewMemParserCtxt() +relaxNGNewParserCtxt() # functions from module tree compressMode() @@ -464,6 +466,9 @@ Class xmlDoc(xmlNode) encodeSpecialChars() parameterEntity() + # functions from module relaxng + relaxNGValidateDoc() + # functions from module tree copyDoc() createIntSubset() @@ -628,6 +633,16 @@ Class xmlEntity(xmlNode) # functions from module parserInternals handleEntity() +Class relaxNgSchema() + + # functions from module relaxng + relaxNGDump() + relaxNGFree() + relaxNGNewValidCtxt() +Class relaxNgValidCtxt() + + # functions from module relaxng + relaxNGFreeValidCtxt() Class xpathParserContext() # accessors context() @@ -797,6 +812,11 @@ Class inputBuffer(ioReadWrapper) # functions from module xmlreader newTextReader() +Class relaxNgParserCtxt() + + # functions from module relaxng + relaxNGFreeParserCtxt() + relaxNGParse() Class outputBuffer(ioWriteWrapper) diff --git a/python/libxml_wrap.h b/python/libxml_wrap.h index d1c5dc9b..260e6b42 100644 --- a/python/libxml_wrap.h +++ b/python/libxml_wrap.h @@ -132,6 +132,32 @@ typedef struct { #define PyFile_Get(v) (((v) == Py_None) ? NULL : \ (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout)) +#ifdef LIBXML_SCHEMAS_ENABLED +typedef struct { + PyObject_HEAD + xmlRelaxNGPtr obj; +} PyrelaxNgSchema_Object; + +#define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \ + (((PyrelaxNgSchema_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlRelaxNGParserCtxtPtr obj; +} PyrelaxNgParserCtxt_Object; + +#define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PyrelaxNgParserCtxt_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + xmlRelaxNGValidCtxtPtr obj; +} PyrelaxNgValidCtxt_Object; + +#define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \ + (((PyrelaxNgValidCtxt_Object *)(v))->obj)) + +#endif /* LIBXML_SCHEMAS_ENABLED */ PyObject * libxml_intWrap(int val); PyObject * libxml_longWrap(long val); @@ -163,3 +189,8 @@ PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader); PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator); xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj); +#ifdef LIBXML_SCHEMAS_ENABLED +PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt); +PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt); +PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid); +#endif /* LIBXML_SCHEMAS_ENABLED */ diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am index 55a9acb5..761046a5 100644 --- a/python/tests/Makefile.am +++ b/python/tests/Makefile.am @@ -24,7 +24,8 @@ PYTESTS= \ reader2.py \ reader3.py \ ctxterror.py\ - readererr.py + readererr.py\ + relaxng.py XMLS= \ tst.xml \ diff --git a/python/tests/relaxng.py b/python/tests/relaxng.py new file mode 100755 index 00000000..2c836355 --- /dev/null +++ b/python/tests/relaxng.py @@ -0,0 +1,48 @@ +#!/usr/bin/python -u +import libxml2 +import sys + +# Memory debug specific +libxml2.debugMemory(1) + +schema=""" + + A foo element. + + + + + + + +""" +instance=""" +""" + +rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema)) +rngs = rngp.relaxNGParse() +ctxt = rngs.relaxNGNewValidCtxt() +doc = libxml2.parseDoc(instance) +ret = doc.relaxNGValidateDoc(ctxt) +if ret != 0: + print "error doing RelaxNG validation" + sys.exit(1) + +doc.freeDoc() +del rngp +del rngs +del ctxt +libxml2.relaxNGCleanupTypes() + +# Memory debug specific +libxml2.cleanupParser() +if libxml2.debugMemory(1) == 0: + print "OK" +else: + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) + libxml2.dumpMemory() + diff --git a/python/types.c b/python/types.c index 37c9e601..a9717912 100644 --- a/python/types.c +++ b/python/types.c @@ -587,3 +587,57 @@ libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator) return (ret); } +#ifdef LIBXML_SCHEMAS_ENABLED +PyObject * +libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt) +{ + PyObject *ret; + +#ifdef DEBUG + printf("libxml_xmlRelaxNGPtrWrap: ctxt = %p\n", ctxt); +#endif + if (ctxt == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = + PyCObject_FromVoidPtrAndDesc((void *) ctxt, + (char *) "xmlRelaxNGPtr", NULL); + return (ret); +} + +PyObject * +libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt) +{ + PyObject *ret; + +#ifdef DEBUG + printf("libxml_xmlRelaxNGParserCtxtPtrWrap: ctxt = %p\n", ctxt); +#endif + if (ctxt == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = + PyCObject_FromVoidPtrAndDesc((void *) ctxt, + (char *) "xmlRelaxNGParserCtxtPtr", NULL); + return (ret); +} +PyObject * +libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid) +{ + PyObject *ret; + +#ifdef DEBUG + printf("libxml_xmlRelaxNGValidCtxtPtrWrap: valid = %p\n", valid); +#endif + if (valid == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = + PyCObject_FromVoidPtrAndDesc((void *) valid, + (char *) "xmlRelaxNGValidCtxtPtr", NULL); + return (ret); +} +#endif /* LIBXML_SCHEMAS_ENABLED */ diff --git a/xpath.c b/xpath.c index 4bbb7dd0..69a39108 100644 --- a/xpath.c +++ b/xpath.c @@ -8176,7 +8176,7 @@ xmlXPathCompAndExpr(xmlXPathParserContextPtr ctxt) { } /** - * xmlXPathCompExpr: + * xmlXPathCompileExpr: * @ctxt: the XPath Parser context * * [14] Expr ::= OrExpr @@ -10610,7 +10610,7 @@ xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt, * * Compile an XPath expression * - * Returns the xmlXPathObjectPtr resulting from the evaluation or NULL. + * Returns the xmlXPathCompExprPtr resulting from the compilation or NULL. * the caller has to free the object. */ xmlXPathCompExprPtr