diff --git a/ChangeLog b/ChangeLog index 351b61d8..be5e3be8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Mar 15 23:21:40 CET 2002 Daniel Veillard + + * libxml.spec.in python/Makefile.am python/tests/Makefile.am + python/generator.py python/libxml.c python/types.c: Cleanup + of the python Makefiles based on Jacob and James feedback, + fixed the spec file accordingly, fixed the number of warning + that passing my pedantic CFLAGS was generating. Conclusion + is that Python includes are real crap. + Fri Mar 15 19:41:25 CET 2002 Daniel Veillard * configure,in: it was reported quite a few times that diff --git a/libxml.spec.in b/libxml.spec.in index dd4392b9..8d13a18c 100644 --- a/libxml.spec.in +++ b/libxml.spec.in @@ -98,8 +98,10 @@ do echo generating bindings for Python $py_version (cd python ; make clean ; \ make PYTHON="%{prefix}/bin/python$py_version" \ + PYTHON_INCLUDES="%{prefix}/include/python$py_version" \ PYTHON_VERSION="$py_version"; \ make PYTHON="%{prefix}/bin/python$py_version" \ + PYTHON_INCLUDES="%{prefix}/include/python$py_version" \ PYTHON_VERSION="$py_version" \ prefix=$RPM_BUILD_ROOT%{prefix} \ mandir=$RPM_BUILD_ROOT%{_mandir} install) diff --git a/python/Makefile.am b/python/Makefile.am index 6078702d..1a188cbd 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -4,12 +4,12 @@ AUTOMAKE_OPTIONS = 1.4 foreign SUBDIRS= . tests INCLUDES = \ - -I/usr/include/python$(PYTHON_VERSION) \ -I$(PYTHON_INCLUDES) \ -I$(top_srcdir)/include DOCS_DIR = $(prefix)/share/doc/libxml2-python-$(LIBXML_VERSION) -DOCS = TODO libxml2class.txt +# libxml2class.txt is generated +DOCS = TODO EXTRA_DIST = \ libxml.c \ @@ -22,24 +22,19 @@ EXTRA_DIST = \ libxml2-python-api.xml \ $(DOCS) +libxml2mod_la_LDFLAGS = -module -avoid-version + if WITH_PYTHON mylibs = \ $(top_builddir)/libxml2.la -all: libxml2mod.so libxml2.py +all: libxml2.py # libxml2mod.so pythondir = $(prefix)/lib/python${PYTHON_VERSION}/site-packages -python_PROGRAMS = libxml2mod.so - -libxml2mod_so_SOURCES = -libxml2mod_so_LDFLAGS = $(mylibs) $(LIBS) -shared -Wl,-soname,libxml2mod.so - -noinst_LTLIBRARIES = libxmlmodule.la -libxmlmodule_la_SOURCES = libxml.c types.c libxml2-py.c - -libxml2mod.so: $(libxmlmodule_la_OBJECTS) $(mylibs) - $(LINK) -o $@ $(libxmlmodule_la_OBJECTS) $(libxml2mod_so_LDFLAGS) +python_LTLIBRARIES = libxml2mod.la +libxml2mod_la_SOURCES = libxml.c types.c libxml2-py.c +libxml2mod_la_LIBADD = $(mylibs) libxml2.py: $(srcdir)/libxml.py libxml2class.py cat $(srcdir)/libxml.py libxml2class.py > libxml2.py @@ -62,7 +57,6 @@ $(GENERATED): $(srcdir)/$(GENERATE) $(API_DESC) cd $(srcdir) && $(PYTHON) $(GENERATE) $(libxmlmodule_la_OBJECTS): $(GENERATED) - else all: endif diff --git a/python/generator.py b/python/generator.py index e4618d15..149eb1c5 100755 --- a/python/generator.py +++ b/python/generator.py @@ -350,7 +350,7 @@ def print_function_wrapper(name, output, export, include): if args[1][1] == "char *" or args[1][1] == "xmlChar *": c_call = "\n if (%s->%s != NULL) xmlFree(%s->%s);\n" % ( args[0][0], args[1][0], args[0][0], args[1][0]) - c_call = c_call + " %s->%s = xmlStrdup(%s);\n" % (args[0][0], + c_call = c_call + " %s->%s = xmlStrdup((const xmlChar *)%s);\n" % (args[0][0], args[1][0], args[1][0]) else: c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0], @@ -384,9 +384,9 @@ def print_function_wrapper(name, output, export, include): return -1 include.write("PyObject * ") - include.write("libxml_%s(PyObject *self, PyObject *args);\n" % (name)) + include.write("libxml_%s(PyObject *self, PyObject *args);\n" % (name)); - export.write(" { \"%s\", libxml_%s, METH_VARARGS, NULL },\n" % + export.write(" { (char *)\"%s\", libxml_%s, METH_VARARGS, NULL },\n" % (name, name)) if file == "python": @@ -397,7 +397,10 @@ def print_function_wrapper(name, output, export, include): return 1 output.write("PyObject *\n") - output.write("libxml_%s(PyObject *self, PyObject *args) {\n" % (name)) + output.write("libxml_%s(ATTRIBUTE_UNUSED PyObject *self," % (name)) + if format == "": + output.write("ATTRIBUTE_UNUSED ") + output.write(" PyObject *args) {\n") if ret[0] != 'void': output.write(" PyObject *py_retval;\n") if c_return != "": @@ -405,7 +408,7 @@ def print_function_wrapper(name, output, export, include): if c_args != "": output.write(c_args) if format != "": - output.write("\n if (!PyArg_ParseTuple(args, \"%s\"%s))\n" % + output.write("\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" % (format, format_args)) output.write(" return(NULL);\n") if c_convert != "": @@ -465,6 +468,8 @@ def buildStubs(): wrapper = open("libxml2-py.c", "w") wrapper.write("/* Generated */\n\n") wrapper.write("#include \n") + wrapper.write("#include \"config.h\"\n") + wrapper.write("#include \n") wrapper.write("#include \n") wrapper.write("#include \"libxml_wrap.h\"\n") wrapper.write("#include \"libxml2-py.h\"\n\n") diff --git a/python/libxml.c b/python/libxml.c index cf7b1492..0072c31f 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -12,6 +12,7 @@ * daniel@veillard.com */ #include +#include "config.h" #include #include #include @@ -23,11 +24,17 @@ #include "libxml2-py.h" /* #define DEBUG */ + /* #define DEBUG_SAX */ + /* #define DEBUG_XPATH */ + /* #define DEBUG_ERROR */ + /* #define DEBUG_MEMORY */ +void initlibxml2mod(void); + /************************************************************************ * * * Memory debug interface * @@ -36,7 +43,7 @@ extern void xmlMemFree(void *ptr); extern void *xmlMemMalloc(size_t size); -extern void *xmlMemRealloc(void *ptr,size_t size); +extern void *xmlMemRealloc(void *ptr, size_t size); extern char *xmlMemoryStrdup(const char *str); static int libxmlMemoryDebugActivated = 0; @@ -49,68 +56,71 @@ static xmlReallocFunc reallocFunc = NULL; static xmlStrdupFunc strdupFunc = NULL; PyObject * -libxml_xmlDebugMemory(PyObject *self, PyObject *args) { +libxml_xmlDebugMemory(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ int activate; PyObject *py_retval; long ret; - if (!PyArg_ParseTuple(args, "i:xmlDebugMemory", &activate)) - return(NULL); + if (!PyArg_ParseTuple(args, (char *) "i:xmlDebugMemory", &activate)) + return (NULL); #ifdef DEBUG_MEMORY printf("libxml_xmlDebugMemory(%d) called\n", activate); #endif if (activate != 0) { - if (libxmlMemoryDebug == 0) { - /* - * First initialize the library and grab the old memory handlers - * and switch the library to memory debugging - */ - xmlMemGet((xmlFreeFunc *) &freeFunc, - (xmlMallocFunc *)&mallocFunc, - (xmlReallocFunc *)&reallocFunc, - (xmlStrdupFunc *) &strdupFunc); - if ((freeFunc == xmlMemFree) && (mallocFunc == xmlMemMalloc) && - (reallocFunc == xmlMemRealloc) && - (strdupFunc == xmlMemoryStrdup)) { - libxmlMemoryAllocatedBase = xmlMemUsed(); - } else { - ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc, - xmlMemRealloc, xmlMemoryStrdup); - if (ret < 0) - goto error; - libxmlMemoryAllocatedBase = xmlMemUsed(); - } - xmlInitParser(); - ret = 0; - } else if (libxmlMemoryDebugActivated == 0) { - libxmlMemoryAllocatedBase = xmlMemUsed(); - ret = 0; - } else { - ret = xmlMemUsed() - libxmlMemoryAllocatedBase; - } - libxmlMemoryDebug = 1; - libxmlMemoryDebugActivated = 1; + if (libxmlMemoryDebug == 0) { + /* + * First initialize the library and grab the old memory handlers + * and switch the library to memory debugging + */ + xmlMemGet((xmlFreeFunc *) & freeFunc, + (xmlMallocFunc *) & mallocFunc, + (xmlReallocFunc *) & reallocFunc, + (xmlStrdupFunc *) & strdupFunc); + if ((freeFunc == xmlMemFree) && (mallocFunc == xmlMemMalloc) && + (reallocFunc == xmlMemRealloc) && + (strdupFunc == xmlMemoryStrdup)) { + libxmlMemoryAllocatedBase = xmlMemUsed(); + } else { + ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc, + xmlMemRealloc, xmlMemoryStrdup); + if (ret < 0) + goto error; + libxmlMemoryAllocatedBase = xmlMemUsed(); + } + xmlInitParser(); + ret = 0; + } else if (libxmlMemoryDebugActivated == 0) { + libxmlMemoryAllocatedBase = xmlMemUsed(); + ret = 0; + } else { + ret = xmlMemUsed() - libxmlMemoryAllocatedBase; + } + libxmlMemoryDebug = 1; + libxmlMemoryDebugActivated = 1; } else { - if (libxmlMemoryDebugActivated == 1) - ret = xmlMemUsed() - libxmlMemoryAllocatedBase; - else - ret = 0; - libxmlMemoryDebugActivated = 0; + if (libxmlMemoryDebugActivated == 1) + ret = xmlMemUsed() - libxmlMemoryAllocatedBase; + else + ret = 0; + libxmlMemoryDebugActivated = 0; } -error: + error: py_retval = libxml_longWrap(ret); - return(py_retval); + return (py_retval); } PyObject * -libxml_xmlDumpMemory(PyObject *self, PyObject *args) { +libxml_xmlDumpMemory(ATTRIBUTE_UNUSED PyObject * self, + ATTRIBUTE_UNUSED PyObject * args) +{ if (libxmlMemoryDebug != 0) - xmlMemoryDump(); + xmlMemoryDump(); Py_INCREF(Py_None); - return(Py_None); + return (Py_None); } /************************************************************************ @@ -128,16 +138,16 @@ pythonStartElement(void *user_data, const xmlChar * name, PyObject *dict; PyObject *attrname; PyObject *attrvalue; - PyObject *result; + PyObject *result = NULL; int type = 0; #ifdef DEBUG_SAX printf("pythonStartElement(%s) called\n", name); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "startElement")) + if (PyObject_HasAttrString(handler, (char *) "startElement")) type = 1; - else if (PyObject_HasAttrString(handler, "start")) + else if (PyObject_HasAttrString(handler, (char *) "start")) type = 2; if (type != 0) { /* @@ -147,15 +157,15 @@ pythonStartElement(void *user_data, const xmlChar * name, if ((attrs == NULL) && (type == 1)) { Py_XINCREF(Py_None); dict = Py_None; - } else if (attrs == NULL) { - dict = PyDict_New(); + } else if (attrs == NULL) { + dict = PyDict_New(); } else { dict = PyDict_New(); for (i = 0; attrs[i] != NULL; i++) { - attrname = PyString_FromString(attrs[i]); + attrname = PyString_FromString((char *) attrs[i]); i++; if (attrs[i] != NULL) { - attrvalue = PyString_FromString(attrs[i]); + attrvalue = PyString_FromString((char *) attrs[i]); } else { Py_XINCREF(Py_None); attrvalue = Py_None; @@ -165,13 +175,13 @@ pythonStartElement(void *user_data, const xmlChar * name, } if (type == 1) - result = PyObject_CallMethod(handler, "startElement", - "sO", name, dict); + result = PyObject_CallMethod(handler, (char *) "startElement", + (char *) "sO", name, dict); else if (type == 2) - result = PyObject_CallMethod(handler, "start", - "sO", name, dict); - if (PyErr_Occurred()) - PyErr_Print(); + result = PyObject_CallMethod(handler, (char *) "start", + (char *) "sO", name, dict); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(dict); Py_XDECREF(result); } @@ -187,10 +197,11 @@ pythonStartDocument(void *user_data) printf("pythonStartDocument() called\n"); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "startDocument")) { - result = PyObject_CallMethod(handler, "startDocument", NULL); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "startDocument")) { + result = + PyObject_CallMethod(handler, (char *) "startDocument", NULL); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -205,10 +216,11 @@ pythonEndDocument(void *user_data) printf("pythonEndDocument() called\n"); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "endDocument")) { - result = PyObject_CallMethod(handler, "endDocument", NULL); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "endDocument")) { + result = + PyObject_CallMethod(handler, (char *) "endDocument", NULL); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } /* @@ -227,15 +239,17 @@ pythonEndElement(void *user_data, const xmlChar * name) printf("pythonEndElement(%s) called\n", name); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "endElement")) { - result = PyObject_CallMethod(handler, "endElement", "s", name); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "endElement")) { + result = PyObject_CallMethod(handler, (char *) "endElement", + (char *) "s", name); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); - } else if (PyObject_HasAttrString(handler, "end")) { - result = PyObject_CallMethod(handler, "end", "s", name); - if (PyErr_Occurred()) - PyErr_Print(); + } else if (PyObject_HasAttrString(handler, (char *) "end")) { + result = PyObject_CallMethod(handler, (char *) "end", + (char *) "s", name); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -250,10 +264,11 @@ pythonReference(void *user_data, const xmlChar * name) printf("pythonReference(%s) called\n", name); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "reference")) { - result = PyObject_CallMethod(handler, "reference", "s", name); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "reference")) { + result = PyObject_CallMethod(handler, (char *) "reference", + (char *) "s", name); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -262,24 +277,26 @@ static void pythonCharacters(void *user_data, const xmlChar * ch, int len) { PyObject *handler; - PyObject *result; + PyObject *result = NULL; int type = 0; #ifdef DEBUG_SAX printf("pythonCharacters(%s, %d) called\n", ch, len); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "characters")) - type = 1; - else if (PyObject_HasAttrString(handler, "data")) - type = 2; + if (PyObject_HasAttrString(handler, (char *) "characters")) + type = 1; + else if (PyObject_HasAttrString(handler, (char *) "data")) + type = 2; if (type != 0) { - if (type == 1) - result = PyObject_CallMethod(handler, "characters", "s#", ch, len); - else if (type == 2) - result = PyObject_CallMethod(handler, "data", "s#", ch, len); - if (PyErr_Occurred()) - PyErr_Print(); + if (type == 1) + result = PyObject_CallMethod(handler, (char *) "characters", + (char *) "s#", ch, len); + else if (type == 2) + result = PyObject_CallMethod(handler, (char *) "data", + (char *) "s#", ch, len); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -288,24 +305,27 @@ static void pythonIgnorableWhitespace(void *user_data, const xmlChar * ch, int len) { PyObject *handler; - PyObject *result; + PyObject *result = NULL; int type = 0; #ifdef DEBUG_SAX printf("pythonIgnorableWhitespace(%s, %d) called\n", ch, len); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "ignorableWhitespace")) + if (PyObject_HasAttrString(handler, (char *) "ignorableWhitespace")) type = 1; - else if (PyObject_HasAttrString(handler, "data")) + else if (PyObject_HasAttrString(handler, (char *) "data")) type = 2; if (type != 0) { if (type == 1) result = - PyObject_CallMethod(handler, "ignorableWhitespace", "s#", - ch, len); + PyObject_CallMethod(handler, + (char *) "ignorableWhitespace", + (char *) "s#", ch, len); else if (type == 2) - result = PyObject_CallMethod(handler, "data", "s#", ch, len); + result = + PyObject_CallMethod(handler, (char *) "data", + (char *) "s#", ch, len); Py_XDECREF(result); } } @@ -321,10 +341,10 @@ pythonProcessingInstruction(void *user_data, printf("pythonProcessingInstruction(%s, %s) called\n", target, data); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "processingInstruction")) { - result = - PyObject_CallMethod(handler, - "processingInstruction", "ss", target, data); + if (PyObject_HasAttrString(handler, (char *) "processingInstruction")) { + result = PyObject_CallMethod(handler, (char *) + "processingInstruction", + (char *) "ss", target, data); Py_XDECREF(result); } } @@ -339,10 +359,12 @@ pythonComment(void *user_data, const xmlChar * value) printf("pythonComment(%s) called\n", value); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "comment")) { - result = PyObject_CallMethod(handler, "comment", "s", value); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "comment")) { + result = + PyObject_CallMethod(handler, (char *) "comment", (char *) "s", + value); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -359,14 +381,16 @@ pythonWarning(void *user_data, const char *msg, ...) printf("pythonWarning(%s) called\n", msg); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "warning")) { + if (PyObject_HasAttrString(handler, (char *) "warning")) { va_start(args, msg); vsnprintf(buf, 1023, msg, args); - va_end(args); - buf[1023] = 0; - result = PyObject_CallMethod(handler, "warning", "s", buf); - if (PyErr_Occurred()) - PyErr_Print(); + va_end(args); + buf[1023] = 0; + result = + PyObject_CallMethod(handler, (char *) "warning", (char *) "s", + buf); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -383,14 +407,16 @@ pythonError(void *user_data, const char *msg, ...) printf("pythonError(%s) called\n", msg); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "error")) { + if (PyObject_HasAttrString(handler, (char *) "error")) { va_start(args, msg); vsnprintf(buf, 1023, msg, args); - va_end(args); - buf[1023] = 0; - result = PyObject_CallMethod(handler, "error", "s", buf); - if (PyErr_Occurred()) - PyErr_Print(); + va_end(args); + buf[1023] = 0; + result = + PyObject_CallMethod(handler, (char *) "error", (char *) "s", + buf); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -407,14 +433,16 @@ pythonFatalError(void *user_data, const char *msg, ...) printf("pythonFatalError(%s) called\n", msg); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "fatalError")) { + if (PyObject_HasAttrString(handler, (char *) "fatalError")) { va_start(args, msg); vsnprintf(buf, 1023, msg, args); - va_end(args); - buf[1023] = 0; - result = PyObject_CallMethod(handler, "fatalError", "s", buf); - if (PyErr_Occurred()) - PyErr_Print(); + va_end(args); + buf[1023] = 0; + result = + PyObject_CallMethod(handler, (char *) "fatalError", + (char *) "s", buf); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -423,24 +451,28 @@ static void pythonCdataBlock(void *user_data, const xmlChar * ch, int len) { PyObject *handler; - PyObject *result; + PyObject *result = NULL; int type = 0; #ifdef DEBUG_SAX printf("pythonCdataBlock(%s, %d) called\n", ch, len); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "cdataBlock")) - type = 1; - else if (PyObject_HasAttrString(handler, "cdata")) - type = 2; + if (PyObject_HasAttrString(handler, (char *) "cdataBlock")) + type = 1; + else if (PyObject_HasAttrString(handler, (char *) "cdata")) + type = 2; if (type != 0) { - if (type == 1) - result = PyObject_CallMethod(handler, "cdataBlock", "s#", ch, len); - else if (type == 2) - result = PyObject_CallMethod(handler, "cdata", "s#", ch, len); - if (PyErr_Occurred()) - PyErr_Print(); + if (type == 1) + result = + PyObject_CallMethod(handler, (char *) "cdataBlock", + (char *) "s#", ch, len); + else if (type == 2) + result = + PyObject_CallMethod(handler, (char *) "cdata", + (char *) "s#", ch, len); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -455,13 +487,14 @@ pythonExternalSubset(void *user_data, #ifdef DEBUG_SAX printf("pythonExternalSubset(%s, %s, %s) called\n", - name, externalID, systemID); + name, externalID, systemID); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "externalSubset")) { + if (PyObject_HasAttrString(handler, (char *) "externalSubset")) { result = - PyObject_CallMethod(handler, "externalSubset", - "sss", name, externalID, systemID); + PyObject_CallMethod(handler, (char *) "externalSubset", + (char *) "sss", name, externalID, + systemID); Py_XDECREF(result); } } @@ -477,12 +510,12 @@ pythonEntityDecl(void *user_data, PyObject *result; handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "entityDecl")) { - result = PyObject_CallMethod(handler, "entityDecl", - "sisss", name, type, publicId, - systemId, content); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "entityDecl")) { + result = PyObject_CallMethod(handler, (char *) "entityDecl", + (char *) "sisss", name, type, + publicId, systemId, content); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -499,11 +532,12 @@ pythonNotationDecl(void *user_data, PyObject *result; handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "notationDecl")) { - result = PyObject_CallMethod(handler, "notationDecl", - "sss", name, publicId, systemId); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "notationDecl")) { + result = PyObject_CallMethod(handler, (char *) "notationDecl", + (char *) "sss", name, publicId, + systemId); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -514,8 +548,7 @@ pythonAttributeDecl(void *user_data, const xmlChar * name, int type, int def, - const xmlChar * defaultValue, - xmlEnumerationPtr tree) + const xmlChar * defaultValue, xmlEnumerationPtr tree) { PyObject *handler; PyObject *nameList; @@ -525,7 +558,7 @@ pythonAttributeDecl(void *user_data, int count; handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "attributeDecl")) { + if (PyObject_HasAttrString(handler, (char *) "attributeDecl")) { count = 0; for (node = tree; node != NULL; node = node->next) { count++; @@ -533,15 +566,15 @@ pythonAttributeDecl(void *user_data, nameList = PyList_New(count); count = 0; for (node = tree; node != NULL; node = node->next) { - newName = PyString_FromString(node->name); + newName = PyString_FromString((char *) node->name); PyList_SetItem(nameList, count, newName); count++; } - result = PyObject_CallMethod(handler, "attributeDecl", - "ssiisO", elem, name, type, def, - defaultValue, nameList); - if (PyErr_Occurred()) - PyErr_Print(); + result = PyObject_CallMethod(handler, (char *) "attributeDecl", + (char *) "ssiisO", elem, name, type, + def, defaultValue, nameList); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(nameList); Py_XDECREF(result); } @@ -550,22 +583,23 @@ pythonAttributeDecl(void *user_data, static void pythonElementDecl(void *user_data, const xmlChar * name, - int type, xmlElementContentPtr content) + int type, ATTRIBUTE_UNUSED xmlElementContentPtr content) { PyObject *handler; PyObject *obj; PyObject *result; handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "elementDecl")) { - /* TODO: wrap in an elementContent object */ - printf("pythonElementDecl: xmlElementContentPtr wrapper missing !\n"); - obj = Py_None; - /* Py_XINCREF(Py_None); isn't the reference just borrowed ??? */ - result = PyObject_CallMethod(handler, "elementDecl", - "siO", name, type, obj); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "elementDecl")) { + /* TODO: wrap in an elementContent object */ + printf + ("pythonElementDecl: xmlElementContentPtr wrapper missing !\n"); + obj = Py_None; + /* Py_XINCREF(Py_None); isn't the reference just borrowed ??? */ + result = PyObject_CallMethod(handler, (char *) "elementDecl", + (char *) "siO", name, type, obj); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -581,12 +615,13 @@ pythonUnparsedEntityDecl(void *user_data, PyObject *result; handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "unparsedEntityDecl")) { - result = PyObject_CallMethod(handler, "unparsedEntityDecl", - "ssss", name, publicId, systemId, - notationName); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "unparsedEntityDecl")) { + result = + PyObject_CallMethod(handler, (char *) "unparsedEntityDecl", + (char *) "ssss", name, publicId, systemId, + notationName); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } @@ -600,31 +635,32 @@ pythonInternalSubset(void *user_data, const xmlChar * name, #ifdef DEBUG_SAX printf("pythonInternalSubset(%s, %s, %s) called\n", - name, ExternalID, SystemID); + name, ExternalID, SystemID); #endif handler = (PyObject *) user_data; - if (PyObject_HasAttrString(handler, "internalSubset")) { - result = PyObject_CallMethod(handler, "internalSubset", - "sss", name, ExternalID, SystemID); - if (PyErr_Occurred()) - PyErr_Print(); + if (PyObject_HasAttrString(handler, (char *) "internalSubset")) { + result = PyObject_CallMethod(handler, (char *) "internalSubset", + (char *) "sss", name, ExternalID, + SystemID); + if (PyErr_Occurred()) + PyErr_Print(); Py_XDECREF(result); } } static xmlSAXHandler pythonSaxHandler = { pythonInternalSubset, - NULL, /* TODO pythonIsStandalone, */ - NULL, /* TODO pythonHasInternalSubset, */ - NULL, /* TODO pythonHasExternalSubset, */ - NULL, /* TODO pythonResolveEntity, */ - NULL, /* TODO pythonGetEntity, */ + NULL, /* TODO pythonIsStandalone, */ + NULL, /* TODO pythonHasInternalSubset, */ + NULL, /* TODO pythonHasExternalSubset, */ + NULL, /* TODO pythonResolveEntity, */ + NULL, /* TODO pythonGetEntity, */ pythonEntityDecl, pythonNotationDecl, pythonAttributeDecl, pythonElementDecl, pythonUnparsedEntityDecl, - NULL, /* OBSOLETED pythonSetDocumentLocator, */ + NULL, /* OBSOLETED pythonSetDocumentLocator, */ pythonStartDocument, pythonEndDocument, pythonStartElement, @@ -637,7 +673,7 @@ static xmlSAXHandler pythonSaxHandler = { pythonWarning, pythonError, pythonFatalError, - NULL, /* TODO pythonGetParameterEntity, */ + NULL, /* TODO pythonGetParameterEntity, */ pythonCdataBlock, pythonExternalSubset, 1 @@ -650,114 +686,123 @@ static xmlSAXHandler pythonSaxHandler = { ************************************************************************/ PyObject * -libxml_xmlCreatePushParser(PyObject *self, PyObject *args) { - xmlChar *chunk; +libxml_xmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self, + PyObject * args) +{ + const char *chunk; int size; - xmlChar *URI; + const char *URI; PyObject *pyobj_SAX = NULL; xmlSAXHandlerPtr SAX = NULL; xmlParserCtxtPtr ret; PyObject *pyret; - if (!PyArg_ParseTuple(args, "Oziz:xmlCreatePushParser", &pyobj_SAX, - &chunk, &size, &URI)) - return(NULL); + if (!PyArg_ParseTuple + (args, (char *) "Oziz:xmlCreatePushParser", &pyobj_SAX, &chunk, + &size, &URI)) + return (NULL); #ifdef DEBUG printf("libxml_xmlCreatePushParser(%p, %s, %d, %s) called\n", - pyobj_SAX, chunk, size, URI); + pyobj_SAX, chunk, size, URI); #endif if (pyobj_SAX != Py_None) { - SAX = &pythonSaxHandler; - Py_INCREF(pyobj_SAX); - /* The reference is released in pythonEndDocument() */ + SAX = &pythonSaxHandler; + Py_INCREF(pyobj_SAX); + /* The reference is released in pythonEndDocument() */ } ret = xmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI); pyret = libxml_xmlParserCtxtPtrWrap(ret); - return(pyret); + return (pyret); } PyObject * -libxml_htmlCreatePushParser(PyObject *self, PyObject *args) { - xmlChar *chunk; +libxml_htmlCreatePushParser(ATTRIBUTE_UNUSED PyObject * self, + PyObject * args) +{ + const char *chunk; int size; - xmlChar *URI; + const char *URI; PyObject *pyobj_SAX = NULL; xmlSAXHandlerPtr SAX = NULL; xmlParserCtxtPtr ret; PyObject *pyret; - if (!PyArg_ParseTuple(args, "Oziz:htmlCreatePushParser", &pyobj_SAX, - &chunk, &size, &URI)) - return(NULL); + if (!PyArg_ParseTuple + (args, (char *) "Oziz:htmlCreatePushParser", &pyobj_SAX, &chunk, + &size, &URI)) + return (NULL); #ifdef DEBUG printf("libxml_htmlCreatePushParser(%p, %s, %d, %s) called\n", - pyobj_SAX, chunk, size, URI); + pyobj_SAX, chunk, size, URI); #endif if (pyobj_SAX != Py_None) { - SAX = &pythonSaxHandler; - Py_INCREF(pyobj_SAX); - /* The reference is released in pythonEndDocument() */ + SAX = &pythonSaxHandler; + Py_INCREF(pyobj_SAX); + /* The reference is released in pythonEndDocument() */ } ret = htmlCreatePushParserCtxt(SAX, pyobj_SAX, chunk, size, URI, - XML_CHAR_ENCODING_NONE); + XML_CHAR_ENCODING_NONE); pyret = libxml_xmlParserCtxtPtrWrap(ret); - return(pyret); + return (pyret); } PyObject * -libxml_xmlSAXParseFile(PyObject *self, PyObject *args) { +libxml_xmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ int recover; - xmlChar *URI; + const char *URI; PyObject *pyobj_SAX = NULL; xmlSAXHandlerPtr SAX = NULL; - if (!PyArg_ParseTuple(args, "Osi:xmlSAXParseFile", &pyobj_SAX, - &URI, &recover)) - return(NULL); + if (!PyArg_ParseTuple(args, (char *) "Osi:xmlSAXParseFile", &pyobj_SAX, + &URI, &recover)) + return (NULL); #ifdef DEBUG printf("libxml_xmlSAXParseFile(%p, %s, %d) called\n", - pyobj_SAX, URI, recover); + pyobj_SAX, URI, recover); #endif if (pyobj_SAX == Py_None) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } SAX = &pythonSaxHandler; Py_INCREF(pyobj_SAX); /* The reference is released in pythonEndDocument() */ xmlSAXParseFileWithData(SAX, URI, recover, pyobj_SAX); Py_INCREF(Py_None); - return(Py_None); + return (Py_None); } PyObject * -libxml_htmlSAXParseFile(PyObject *self, PyObject *args) { - xmlChar *URI; - xmlChar *encoding; +libxml_htmlSAXParseFile(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ + const char *URI; + const char *encoding; PyObject *pyobj_SAX = NULL; xmlSAXHandlerPtr SAX = NULL; - if (!PyArg_ParseTuple(args, "Osz:htmlSAXParseFile", &pyobj_SAX, - &URI, &encoding)) - return(NULL); + if (!PyArg_ParseTuple + (args, (char *) "Osz:htmlSAXParseFile", &pyobj_SAX, &URI, + &encoding)) + return (NULL); #ifdef DEBUG printf("libxml_htmlSAXParseFile(%p, %s, %s) called\n", - pyobj_SAX, URI, encoding); + pyobj_SAX, URI, encoding); #endif if (pyobj_SAX == Py_None) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } SAX = &pythonSaxHandler; Py_INCREF(pyobj_SAX); /* The reference is released in pythonEndDocument() */ htmlSAXParseFile(URI, encoding, SAX, pyobj_SAX); Py_INCREF(Py_None); - return(Py_None); + return (Py_None); } /************************************************************************ @@ -770,12 +815,14 @@ static PyObject *libxml_xmlPythonErrorFuncHandler = NULL; static PyObject *libxml_xmlPythonErrorFuncCtxt = NULL; static void -libxml_xmlErrorFuncHandler(void *ctx, const char *msg, ...) { - int size; - int chars; - char *larger; - va_list ap; - char *str; +libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, + ...) +{ + int size; + int chars; + char *larger; + va_list ap; + char *str; PyObject *list; PyObject *message; PyObject *result; @@ -786,46 +833,47 @@ libxml_xmlErrorFuncHandler(void *ctx, const char *msg, ...) { if (libxml_xmlPythonErrorFuncHandler == NULL) { - va_start(ap, msg); - vfprintf(stdout, msg, ap); - va_end(ap); + va_start(ap, msg); + vfprintf(stdout, msg, ap); + va_end(ap); } else { - str = (char *) xmlMalloc(150); - if (str == NULL) - return; + str = (char *) xmlMalloc(150); + if (str == NULL) + return; - size = 150; + size = 150; - while (1) { - va_start(ap, msg); - chars = vsnprintf(str, size, msg, ap); - va_end(ap); - if ((chars > -1) && (chars < size)) - break; - if (chars > -1) - size += chars + 1; - else - size += 100; - if ((larger = (char *) xmlRealloc(str, size)) == NULL) { - xmlFree(str); - return; - } - str = larger; - } + while (1) { + va_start(ap, msg); + chars = vsnprintf(str, size, msg, ap); + va_end(ap); + if ((chars > -1) && (chars < size)) + break; + if (chars > -1) + size += chars + 1; + else + size += 100; + if ((larger = (char *) xmlRealloc(str, size)) == NULL) { + xmlFree(str); + return; + } + str = larger; + } - list = PyTuple_New(2); - PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt); - Py_XINCREF(libxml_xmlPythonErrorFuncCtxt); - message = libxml_charPtrWrap(str); - PyTuple_SetItem(list, 1, message); - result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list); - Py_XDECREF(list); - Py_XDECREF(result); + list = PyTuple_New(2); + PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt); + Py_XINCREF(libxml_xmlPythonErrorFuncCtxt); + message = libxml_charPtrWrap(str); + PyTuple_SetItem(list, 1, message); + result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list); + Py_XDECREF(list); + Py_XDECREF(result); } } static void -libxml_xmlErrorInitialize(void) { +libxml_xmlErrorInitialize(void) +{ #ifdef DEBUG_ERROR printf("libxml_xmlErrorInitialize() called\n"); #endif @@ -833,24 +881,28 @@ libxml_xmlErrorInitialize(void) { } PyObject * -libxml_xmlRegisterErrorHandler(PyObject *self, PyObject *args) { +libxml_xmlRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self, + PyObject * args) +{ PyObject *py_retval; PyObject *pyobj_f; PyObject *pyobj_ctx; - if (!PyArg_ParseTuple(args, "OO:xmlRegisterErrorHandler", &pyobj_f, - &pyobj_ctx)) - return(NULL); + if (!PyArg_ParseTuple + (args, (char *) "OO:xmlRegisterErrorHandler", &pyobj_f, + &pyobj_ctx)) + return (NULL); #ifdef DEBUG_ERROR - printf("libxml_registerXPathFunction(%p, %p) called\n", pyobj_ctx, pyobj_f); + printf("libxml_registerXPathFunction(%p, %p) called\n", pyobj_ctx, + pyobj_f); #endif if (libxml_xmlPythonErrorFuncHandler != NULL) { - Py_XDECREF(libxml_xmlPythonErrorFuncHandler); + Py_XDECREF(libxml_xmlPythonErrorFuncHandler); } if (libxml_xmlPythonErrorFuncCtxt != NULL) { - Py_XDECREF(libxml_xmlPythonErrorFuncCtxt); + Py_XDECREF(libxml_xmlPythonErrorFuncCtxt); } Py_XINCREF(pyobj_ctx); @@ -861,8 +913,9 @@ libxml_xmlRegisterErrorHandler(PyObject *self, PyObject *args) { libxml_xmlPythonErrorFuncCtxt = pyobj_ctx; py_retval = libxml_intWrap(1); - return(py_retval); + return (py_retval); } + /************************************************************************ * * * XPath extensions * @@ -882,7 +935,8 @@ static int libxml_xpathCallbacksNb = 0; static int libxml_xpathCallbacksMax = 10; static void -libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) { +libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) +{ PyObject *list, *cur, *result; xmlXPathObjectPtr obj; xmlXPathContextPtr rctxt; @@ -892,38 +946,40 @@ libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) { int i; if (ctxt == NULL) - return; + return; rctxt = ctxt->context; if (rctxt == NULL) - return; + return; name = rctxt->function; ns_uri = rctxt->functionURI; #ifdef DEBUG_XPATH - printf("libxml_xmlXPathFuncCallback called name %s URI %s\n", name, ns_uri); + 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; - } + 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; + printf + ("libxml_xmlXPathFuncCallback: internal error %s not found !\n", + name); + return; } list = PyTuple_New(nargs + 1); PyTuple_SetItem(list, 0, libxml_xmlXPathParserContextPtrWrap(ctxt)); - for (i = 0;i < nargs;i++) { - obj = valuePop(ctxt); - cur = libxml_xmlXPathObjectPtrWrap(obj); - PyTuple_SetItem(list, i + 1, cur); + for (i = 0; i < nargs; i++) { + obj = valuePop(ctxt); + cur = libxml_xmlXPathObjectPtrWrap(obj); + PyTuple_SetItem(list, i + 1, cur); } result = PyEval_CallObject(current_function, list); Py_DECREF(list); @@ -933,12 +989,14 @@ libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) { } static xmlXPathFunction -libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar *name, - const xmlChar *ns_uri) { +libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar * name, + const xmlChar * ns_uri) +{ int i; + #ifdef DEBUG_XPATH printf("libxml_xmlXPathFuncLookupFunc(%p, %s, %s) called\n", - ctxt, name, ns_uri); + ctxt, name, ns_uri); #endif /* * This is called once only. The address is then stored in the @@ -946,38 +1004,41 @@ libxml_xmlXPathFuncLookupFunc(void *ctxt, const xmlChar *name, * 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))) { - return(libxml_xmlXPathFuncCallback); - } + 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))) { + return (libxml_xmlXPathFuncCallback); + } } - return(NULL); + return (NULL); } static void -libxml_xpathCallbacksInitialize(void) { +libxml_xpathCallbacksInitialize(void) +{ int i; if (libxml_xpathCallbacksInitialized != 0) - return; + return; #ifdef DEBUG_XPATH printf("libxml_xpathCallbacksInitialized called\n"); #endif - for (i = 0;i < 10;i++) { - libxml_xpathCallbacks[i].ctx = NULL; - libxml_xpathCallbacks[i].name = NULL; - libxml_xpathCallbacks[i].ns_uri = NULL; - libxml_xpathCallbacks[i].function = NULL; + for (i = 0; i < 10; i++) { + libxml_xpathCallbacks[i].ctx = NULL; + libxml_xpathCallbacks[i].name = NULL; + libxml_xpathCallbacks[i].ns_uri = NULL; + libxml_xpathCallbacks[i].function = NULL; } libxml_xpathCallbacksInitialized = 1; } PyObject * -libxml_xmlRegisterXPathFunction(PyObject *self, PyObject *args) { +libxml_xmlRegisterXPathFunction(ATTRIBUTE_UNUSED PyObject * self, + PyObject * args) +{ PyObject *py_retval; int c_retval = 0; xmlChar *name; @@ -987,49 +1048,49 @@ libxml_xmlRegisterXPathFunction(PyObject *self, PyObject *args) { PyObject *pyobj_f; int i; - if (!PyArg_ParseTuple(args, "OszO:registerXPathFunction", &pyobj_ctx, - &name, &ns_uri, &pyobj_f)) - return(NULL); + if (!PyArg_ParseTuple + (args, (char *) "OszO:registerXPathFunction", &pyobj_ctx, &name, + &ns_uri, &pyobj_f)) + return (NULL); ctx = (xmlXPathContextPtr) PyxmlXPathContext_Get(pyobj_ctx); if (libxml_xpathCallbacksInitialized == 0) - libxml_xpathCallbacksInitialize(); + libxml_xpathCallbacksInitialize(); xmlXPathRegisterFuncLookup(ctx, libxml_xmlXPathFuncLookupFunc, ctx); if ((pyobj_ctx == NULL) || (name == NULL) || (pyobj_f == NULL)) { - py_retval = libxml_intWrap(-1); - return(py_retval); + py_retval = libxml_intWrap(-1); + return (py_retval); } - #ifdef DEBUG_XPATH printf("libxml_registerXPathFunction(%p, %s, %s) called\n", - ctx, name, ns_uri); + ctx, name, ns_uri); #endif - for (i = 0;i < libxml_xpathCallbacksNb;i++) { - if ((ctx == libxml_xpathCallbacks[i].ctx) && - (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) && - (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) { - Py_XINCREF(pyobj_f); - Py_XDECREF(libxml_xpathCallbacks[i].function); - libxml_xpathCallbacks[i].function = pyobj_f; - c_retval = 1; - goto done; - } + for (i = 0; i < libxml_xpathCallbacksNb; i++) { + if ((ctx == libxml_xpathCallbacks[i].ctx) && + (xmlStrEqual(name, libxml_xpathCallbacks[i].name)) && + (xmlStrEqual(ns_uri, libxml_xpathCallbacks[i].ns_uri))) { + Py_XINCREF(pyobj_f); + Py_XDECREF(libxml_xpathCallbacks[i].function); + libxml_xpathCallbacks[i].function = pyobj_f; + c_retval = 1; + goto done; + } } if (libxml_xpathCallbacksNb >= libxml_xpathCallbacksMax) { - printf("libxml_registerXPathFunction() table full\n"); + printf("libxml_registerXPathFunction() table full\n"); } else { - i = libxml_xpathCallbacksNb++; - Py_XINCREF(pyobj_f); + 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; + libxml_xpathCallbacks[i].function = pyobj_f; + c_retval = 1; } -done: + done: py_retval = libxml_intWrap((int) c_retval); - return(py_retval); + return (py_retval); } /************************************************************************ @@ -1038,13 +1099,13 @@ done: * * ************************************************************************/ static PyObject * -libxml_name(PyObject *self, PyObject *args) +libxml_name(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; const xmlChar *res; - if (!PyArg_ParseTuple(args, "O:name", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:name", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1052,29 +1113,32 @@ libxml_name(PyObject *self, PyObject *args) printf("libxml_name: cur = %p type %d\n", cur, cur->type); #endif - switch(cur->type) { - case XML_DOCUMENT_NODE: + switch (cur->type) { + case XML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - case XML_HTML_DOCUMENT_NODE: { - xmlDocPtr doc = (xmlDocPtr) cur; - res = doc->URL; - break; - } - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = attr->name; - break; - } - case XML_NAMESPACE_DECL: { - xmlNsPtr ns = (xmlNsPtr) cur; - res = ns->prefix; - break; - } - default: - res = cur->name; - break; + case XML_HTML_DOCUMENT_NODE:{ + xmlDocPtr doc = (xmlDocPtr) cur; + + res = doc->URL; + break; + } + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = attr->name; + break; + } + case XML_NAMESPACE_DECL:{ + xmlNsPtr ns = (xmlNsPtr) cur; + + res = ns->prefix; + break; + } + default: + res = cur->name; + break; } resultobj = libxml_constxmlCharPtrWrap(res); @@ -1082,13 +1146,13 @@ libxml_name(PyObject *self, PyObject *args) } static PyObject * -libxml_doc(PyObject *self, PyObject *args) +libxml_doc(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; xmlDocPtr res; - if (!PyArg_ParseTuple(args, "O:doc", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:doc", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1096,56 +1160,57 @@ libxml_doc(PyObject *self, PyObject *args) printf("libxml_doc: cur = %p\n", cur); #endif - switch(cur->type) { - case XML_DOCUMENT_NODE: + switch (cur->type) { + case XML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - case XML_HTML_DOCUMENT_NODE: - res = NULL; - break; - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = attr->doc; - break; - } - case XML_NAMESPACE_DECL: - res = NULL; - break; - default: - res = cur->doc; - break; + case XML_HTML_DOCUMENT_NODE: + res = NULL; + break; + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = attr->doc; + break; + } + case XML_NAMESPACE_DECL: + res = NULL; + break; + default: + res = cur->doc; + break; } resultobj = libxml_xmlDocPtrWrap(res); return resultobj; } static PyObject * -libxml_properties(PyObject *self, PyObject *args) +libxml_properties(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur = NULL; xmlAttrPtr res; - if (!PyArg_ParseTuple(args, "O:properties", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:properties", &obj)) return NULL; cur = PyxmlNode_Get(obj); if (cur->type == XML_ELEMENT_NODE) - res = cur->properties; + res = cur->properties; else - res = NULL; + res = NULL; resultobj = libxml_xmlAttrPtrWrap(res); return resultobj; } static PyObject * -libxml_next(PyObject *self, PyObject *args) +libxml_next(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; xmlNodePtr res; - if (!PyArg_ParseTuple(args, "O:next", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:next", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1153,27 +1218,29 @@ libxml_next(PyObject *self, PyObject *args) printf("libxml_next: cur = %p\n", cur); #endif - switch(cur->type) { - case XML_DOCUMENT_NODE: + switch (cur->type) { + case XML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - case XML_HTML_DOCUMENT_NODE: - res = NULL; - break; - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = (xmlNodePtr) attr->next; - break; - } - case XML_NAMESPACE_DECL: { - xmlNsPtr ns = (xmlNsPtr) cur; - res = (xmlNodePtr) ns->next; - break; - } - default: - res = cur->next; - break; + case XML_HTML_DOCUMENT_NODE: + res = NULL; + break; + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = (xmlNodePtr) attr->next; + break; + } + case XML_NAMESPACE_DECL:{ + xmlNsPtr ns = (xmlNsPtr) cur; + + res = (xmlNodePtr) ns->next; + break; + } + default: + res = cur->next; + break; } resultobj = libxml_xmlNodePtrWrap(res); @@ -1181,13 +1248,13 @@ libxml_next(PyObject *self, PyObject *args) } static PyObject * -libxml_prev(PyObject *self, PyObject *args) +libxml_prev(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; xmlNodePtr res; - if (!PyArg_ParseTuple(args, "O:prev", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:prev", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1195,37 +1262,38 @@ libxml_prev(PyObject *self, PyObject *args) printf("libxml_prev: cur = %p\n", cur); #endif - switch(cur->type) { - case XML_DOCUMENT_NODE: + switch (cur->type) { + case XML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - case XML_HTML_DOCUMENT_NODE: - res = NULL; - break; - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = (xmlNodePtr) attr->next; - } - case XML_NAMESPACE_DECL: - res = NULL; - break; - default: - res = cur->next; - break; + case XML_HTML_DOCUMENT_NODE: + res = NULL; + break; + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = (xmlNodePtr) attr->next; + } + case XML_NAMESPACE_DECL: + res = NULL; + break; + default: + res = cur->next; + break; } resultobj = libxml_xmlNodePtrWrap(res); return resultobj; } static PyObject * -libxml_children(PyObject *self, PyObject *args) +libxml_children(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; xmlNodePtr res; - if (!PyArg_ParseTuple(args, "O:children", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:children", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1233,41 +1301,42 @@ libxml_children(PyObject *self, PyObject *args) printf("libxml_children: cur = %p\n", cur); #endif - switch(cur->type) { - case XML_ELEMENT_NODE: - case XML_ENTITY_REF_NODE: - case XML_ENTITY_NODE: - case XML_PI_NODE: - case XML_COMMENT_NODE: - case XML_DOCUMENT_NODE: + switch (cur->type) { + case XML_ELEMENT_NODE: + case XML_ENTITY_REF_NODE: + case XML_ENTITY_NODE: + case XML_PI_NODE: + case XML_COMMENT_NODE: + case XML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - case XML_HTML_DOCUMENT_NODE: - case XML_DTD_NODE: - res = cur->children; - break; - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = attr->children; - break; - } - default: - res = NULL; - break; + case XML_HTML_DOCUMENT_NODE: + case XML_DTD_NODE: + res = cur->children; + break; + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = attr->children; + break; + } + default: + res = NULL; + break; } resultobj = libxml_xmlNodePtrWrap(res); return resultobj; } static PyObject * -libxml_last(PyObject *self, PyObject *args) +libxml_last(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; xmlNodePtr res; - if (!PyArg_ParseTuple(args, "O:last", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:last", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1275,40 +1344,41 @@ libxml_last(PyObject *self, PyObject *args) printf("libxml_last: cur = %p\n", cur); #endif - switch(cur->type) { - case XML_ELEMENT_NODE: - case XML_ENTITY_REF_NODE: - case XML_ENTITY_NODE: - case XML_PI_NODE: - case XML_COMMENT_NODE: - case XML_DOCUMENT_NODE: + switch (cur->type) { + case XML_ELEMENT_NODE: + case XML_ENTITY_REF_NODE: + case XML_ENTITY_NODE: + case XML_PI_NODE: + case XML_COMMENT_NODE: + case XML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - case XML_HTML_DOCUMENT_NODE: - case XML_DTD_NODE: - res = cur->last; - break; - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = attr->last; - } - default: - res = NULL; - break; + case XML_HTML_DOCUMENT_NODE: + case XML_DTD_NODE: + res = cur->last; + break; + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = attr->last; + } + default: + res = NULL; + break; } resultobj = libxml_xmlNodePtrWrap(res); return resultobj; } static PyObject * -libxml_parent(PyObject *self, PyObject *args) +libxml_parent(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; xmlNodePtr res; - if (!PyArg_ParseTuple(args, "O:parent", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:parent", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1316,40 +1386,41 @@ libxml_parent(PyObject *self, PyObject *args) printf("libxml_parent: cur = %p\n", cur); #endif - switch(cur->type) { - case XML_DOCUMENT_NODE: - case XML_HTML_DOCUMENT_NODE: + switch (cur->type) { + case XML_DOCUMENT_NODE: + case XML_HTML_DOCUMENT_NODE: #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: + case XML_DOCB_DOCUMENT_NODE: #endif - res = NULL; - break; - case XML_ATTRIBUTE_NODE: { - xmlAttrPtr attr = (xmlAttrPtr) cur; - res = attr->parent; - } - case XML_ENTITY_DECL: - case XML_NAMESPACE_DECL: - case XML_XINCLUDE_START: - case XML_XINCLUDE_END: - res = NULL; - break; - default: - res = cur->parent; - break; + res = NULL; + break; + case XML_ATTRIBUTE_NODE:{ + xmlAttrPtr attr = (xmlAttrPtr) cur; + + res = attr->parent; + } + case XML_ENTITY_DECL: + case XML_NAMESPACE_DECL: + case XML_XINCLUDE_START: + case XML_XINCLUDE_END: + res = NULL; + break; + default: + res = cur->parent; + break; } resultobj = libxml_xmlNodePtrWrap(res); return resultobj; } static PyObject * -libxml_type(PyObject *self, PyObject *args) +libxml_type(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) { PyObject *resultobj, *obj; xmlNodePtr cur; - const xmlChar *res; + const xmlChar *res = NULL; - if (!PyArg_ParseTuple(args, "O:last", &obj)) + if (!PyArg_ParseTuple(args, (char *) "O:last", &obj)) return NULL; cur = PyxmlNode_Get(obj); @@ -1357,50 +1428,71 @@ libxml_type(PyObject *self, PyObject *args) printf("libxml_type: cur = %p\n", cur); #endif - switch(cur->type) { + switch (cur->type) { case XML_ELEMENT_NODE: - res = (const xmlChar *) "element"; break; + res = (const xmlChar *) "element"; + break; case XML_ATTRIBUTE_NODE: - res = (const xmlChar *) "attribute"; break; + res = (const xmlChar *) "attribute"; + break; case XML_TEXT_NODE: - res = (const xmlChar *) "text"; break; + res = (const xmlChar *) "text"; + break; case XML_CDATA_SECTION_NODE: - res = (const xmlChar *) "cdata"; break; + res = (const xmlChar *) "cdata"; + break; case XML_ENTITY_REF_NODE: - res = (const xmlChar *) "entity_ref"; break; + res = (const xmlChar *) "entity_ref"; + break; case XML_ENTITY_NODE: - res = (const xmlChar *) "entity"; break; + res = (const xmlChar *) "entity"; + break; case XML_PI_NODE: - res = (const xmlChar *) "pi"; break; + res = (const xmlChar *) "pi"; + break; case XML_COMMENT_NODE: - res = (const xmlChar *) "comment"; break; + res = (const xmlChar *) "comment"; + break; case XML_DOCUMENT_NODE: - res = (const xmlChar *) "document_xml"; break; + res = (const xmlChar *) "document_xml"; + break; case XML_DOCUMENT_TYPE_NODE: - res = (const xmlChar *) "doctype"; break; + res = (const xmlChar *) "doctype"; + break; case XML_DOCUMENT_FRAG_NODE: - res = (const xmlChar *) "fragment"; break; + res = (const xmlChar *) "fragment"; + break; case XML_NOTATION_NODE: - res = (const xmlChar *) "notation"; break; + res = (const xmlChar *) "notation"; + break; case XML_HTML_DOCUMENT_NODE: - res = (const xmlChar *) "document_html"; break; + res = (const xmlChar *) "document_html"; + break; case XML_DTD_NODE: - res = (const xmlChar *) "dtd"; break; + res = (const xmlChar *) "dtd"; + break; case XML_ELEMENT_DECL: - res = (const xmlChar *) "elem_decl"; break; + res = (const xmlChar *) "elem_decl"; + break; case XML_ATTRIBUTE_DECL: - res = (const xmlChar *) "attribute_decl"; break; + res = (const xmlChar *) "attribute_decl"; + break; case XML_ENTITY_DECL: - res = (const xmlChar *) "entity_decl"; break; + res = (const xmlChar *) "entity_decl"; + break; case XML_NAMESPACE_DECL: - res = (const xmlChar *) "namespace"; break; + res = (const xmlChar *) "namespace"; + break; case XML_XINCLUDE_START: - res = (const xmlChar *) "xinclude_start"; break; + res = (const xmlChar *) "xinclude_start"; + break; case XML_XINCLUDE_END: - res = (const xmlChar *) "xinclude_end"; break; + res = (const xmlChar *) "xinclude_end"; + break; #ifdef LIBXML_DOCB_ENABLED - case XML_DOCB_DOCUMENT_NODE: - res = (const xmlChar *) "document_docbook"; break; + case XML_DOCB_DOCUMENT_NODE: + res = (const xmlChar *) "document_docbook"; + break; #endif } #ifdef DEBUG @@ -1417,43 +1509,46 @@ libxml_type(PyObject *self, PyObject *args) * * ************************************************************************/ PyObject * -libxml_xmlNodeGetNsDefs(PyObject *self, PyObject *args) { +libxml_xmlNodeGetNsDefs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ PyObject *py_retval; xmlNsPtr c_retval; xmlNodePtr node; PyObject *pyobj_node; - if (!PyArg_ParseTuple(args, "O:xmlNodeGetNsDefs", &pyobj_node)) - return(NULL); + if (!PyArg_ParseTuple + (args, (char *) "O:xmlNodeGetNsDefs", &pyobj_node)) + return (NULL); node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } c_retval = node->nsDef; py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval); - return(py_retval); + return (py_retval); } PyObject * -libxml_xmlNodeGetNs(PyObject *self, PyObject *args) { +libxml_xmlNodeGetNs(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ PyObject *py_retval; xmlNsPtr c_retval; xmlNodePtr node; PyObject *pyobj_node; - if (!PyArg_ParseTuple(args, "O:xmlNodeGetNs", &pyobj_node)) - return(NULL); + if (!PyArg_ParseTuple(args, (char *) "O:xmlNodeGetNs", &pyobj_node)) + return (NULL); node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } c_retval = node->ns; py_retval = libxml_xmlNsPtrWrap((xmlNsPtr) c_retval); - return(py_retval); + return (py_retval); } /************************************************************************ @@ -1462,221 +1557,224 @@ libxml_xmlNodeGetNs(PyObject *self, PyObject *args) { * * ************************************************************************/ -PyObject * -libxml_serializeNode(PyObject *self, PyObject *args) { +static PyObject * +libxml_serializeNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ PyObject *py_retval = NULL; xmlChar *c_retval; PyObject *pyobj_node; xmlNodePtr node; xmlDocPtr doc; - xmlChar *encoding; + const char *encoding; int format; int len; - if (!PyArg_ParseTuple(args, "Ozi:serializeNode", &pyobj_node, - &encoding, &format)) - return(NULL); + if (!PyArg_ParseTuple(args, (char *) "Ozi:serializeNode", &pyobj_node, + &encoding, &format)) + return (NULL); node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); if (node == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } if (node->type == XML_DOCUMENT_NODE) { - doc = (xmlDocPtr) node; - xmlDocDumpFormatMemoryEnc(doc, &c_retval, &len, encoding, format); - py_retval = libxml_charPtrWrap(c_retval); + doc = (xmlDocPtr) node; + xmlDocDumpFormatMemoryEnc(doc, &c_retval, &len, + (const char *) encoding, format); + py_retval = libxml_charPtrWrap((char *) c_retval); } else if (node->type == XML_HTML_DOCUMENT_NODE) { - xmlOutputBufferPtr buf; - xmlCharEncodingHandlerPtr handler = NULL; + xmlOutputBufferPtr buf; + xmlCharEncodingHandlerPtr handler = NULL; - doc = (xmlDocPtr) node; - if (encoding != NULL) - htmlSetMetaEncoding(doc, encoding); - encoding = (xmlChar *) htmlGetMetaEncoding(doc); + doc = (xmlDocPtr) node; + if (encoding != NULL) + htmlSetMetaEncoding(doc, (const xmlChar *) encoding); + encoding = (const char *) htmlGetMetaEncoding(doc); - if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - Py_INCREF(Py_None); - return(Py_None); - } - } + if (encoding != NULL) { + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + } - /* - * Fallback to HTML or ASCII when the encoding is unspecified - */ - if (handler == NULL) - handler = xmlFindCharEncodingHandler("HTML"); - if (handler == NULL) - handler = xmlFindCharEncodingHandler("ascii"); + /* + * Fallback to HTML or ASCII when the encoding is unspecified + */ + if (handler == NULL) + handler = xmlFindCharEncodingHandler("HTML"); + if (handler == NULL) + handler = xmlFindCharEncodingHandler("ascii"); - buf = xmlAllocOutputBuffer(handler); - if (buf == NULL) { - Py_INCREF(Py_None); - return(Py_None); - } - htmlDocContentDumpFormatOutput(buf, doc, encoding, format); - xmlOutputBufferFlush(buf); - if (buf->conv != NULL) { - len = buf->conv->use; - c_retval = buf->conv->content; - buf->conv->content = NULL; - } else { - len = buf->buffer->use; - c_retval = buf->buffer->content; - buf->buffer->content = NULL; - } - (void)xmlOutputBufferClose(buf); - py_retval = libxml_charPtrWrap(c_retval); + buf = xmlAllocOutputBuffer(handler); + if (buf == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + htmlDocContentDumpFormatOutput(buf, doc, encoding, format); + xmlOutputBufferFlush(buf); + if (buf->conv != NULL) { + len = buf->conv->use; + c_retval = buf->conv->content; + buf->conv->content = NULL; + } else { + len = buf->buffer->use; + c_retval = buf->buffer->content; + buf->buffer->content = NULL; + } + (void) xmlOutputBufferClose(buf); + py_retval = libxml_charPtrWrap((char *) c_retval); } else { - doc = node->doc; - if (doc->type == XML_DOCUMENT_NODE) { - xmlOutputBufferPtr buf; - xmlCharEncodingHandlerPtr handler = NULL; + doc = node->doc; + if (doc->type == XML_DOCUMENT_NODE) { + xmlOutputBufferPtr buf; + xmlCharEncodingHandlerPtr handler = NULL; - if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - Py_INCREF(Py_None); - return(Py_None); - } - } + if (encoding != NULL) { + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + } - buf = xmlAllocOutputBuffer(handler); - if (buf == NULL) { - Py_INCREF(Py_None); - return(Py_None); - } - xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); - xmlOutputBufferFlush(buf); - if (buf->conv != NULL) { - len = buf->conv->use; - c_retval = buf->conv->content; - buf->conv->content = NULL; - } else { - len = buf->buffer->use; - c_retval = buf->buffer->content; - buf->buffer->content = NULL; - } - (void)xmlOutputBufferClose(buf); - py_retval = libxml_charPtrWrap(c_retval); - } else if (doc->type == XML_HTML_DOCUMENT_NODE) { - xmlOutputBufferPtr buf; - xmlCharEncodingHandlerPtr handler = NULL; + buf = xmlAllocOutputBuffer(handler); + if (buf == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); + xmlOutputBufferFlush(buf); + if (buf->conv != NULL) { + len = buf->conv->use; + c_retval = buf->conv->content; + buf->conv->content = NULL; + } else { + len = buf->buffer->use; + c_retval = buf->buffer->content; + buf->buffer->content = NULL; + } + (void) xmlOutputBufferClose(buf); + py_retval = libxml_charPtrWrap((char *) c_retval); + } else if (doc->type == XML_HTML_DOCUMENT_NODE) { + xmlOutputBufferPtr buf; + xmlCharEncodingHandlerPtr handler = NULL; - if (encoding != NULL) - htmlSetMetaEncoding(doc, encoding); - encoding = (xmlChar *) htmlGetMetaEncoding(doc); - if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - Py_INCREF(Py_None); - return(Py_None); - } - } + if (encoding != NULL) + htmlSetMetaEncoding(doc, (const xmlChar *) encoding); + encoding = (const char *) htmlGetMetaEncoding(doc); + if (encoding != NULL) { + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + } - /* - * Fallback to HTML or ASCII when the encoding is unspecified - */ - if (handler == NULL) - handler = xmlFindCharEncodingHandler("HTML"); - if (handler == NULL) - handler = xmlFindCharEncodingHandler("ascii"); + /* + * Fallback to HTML or ASCII when the encoding is unspecified + */ + if (handler == NULL) + handler = xmlFindCharEncodingHandler("HTML"); + if (handler == NULL) + handler = xmlFindCharEncodingHandler("ascii"); - buf = xmlAllocOutputBuffer(handler); - if (buf == NULL) { - Py_INCREF(Py_None); - return(Py_None); - } - htmlNodeDumpFormatOutput(buf, doc, node, encoding, format); - xmlOutputBufferFlush(buf); - if (buf->conv != NULL) { - len = buf->conv->use; - c_retval = buf->conv->content; - buf->conv->content = NULL; - } else { - len = buf->buffer->use; - c_retval = buf->buffer->content; - buf->buffer->content = NULL; - } - (void)xmlOutputBufferClose(buf); - py_retval = libxml_charPtrWrap(c_retval); - } else { - Py_INCREF(Py_None); - return(Py_None); - } + buf = xmlAllocOutputBuffer(handler); + if (buf == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + htmlNodeDumpFormatOutput(buf, doc, node, encoding, format); + xmlOutputBufferFlush(buf); + if (buf->conv != NULL) { + len = buf->conv->use; + c_retval = buf->conv->content; + buf->conv->content = NULL; + } else { + len = buf->buffer->use; + c_retval = buf->buffer->content; + buf->buffer->content = NULL; + } + (void) xmlOutputBufferClose(buf); + py_retval = libxml_charPtrWrap((char *) c_retval); + } else { + Py_INCREF(Py_None); + return (Py_None); + } } - return(py_retval); + return (py_retval); } -PyObject * -libxml_saveNodeTo(PyObject *self, PyObject *args) { +static PyObject * +libxml_saveNodeTo(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ PyObject *py_file = NULL; FILE *output; PyObject *pyobj_node; xmlNodePtr node; xmlDocPtr doc; - xmlChar *encoding; + const char *encoding; int format; int len; xmlOutputBufferPtr buf; xmlCharEncodingHandlerPtr handler = NULL; - if (!PyArg_ParseTuple(args, "OOzi:serializeNode", &pyobj_node, - &py_file, &encoding, &format)) - return(NULL); + if (!PyArg_ParseTuple(args, (char *) "OOzi:serializeNode", &pyobj_node, + &py_file, &encoding, &format)) + return (NULL); node = (xmlNodePtr) PyxmlNode_Get(pyobj_node); if (node == NULL) { - return(PyInt_FromLong((long) -1)); + return (PyInt_FromLong((long) -1)); } if ((py_file == NULL) || (!(PyFile_Check(py_file)))) { - return(PyInt_FromLong((long) -1)); + return (PyInt_FromLong((long) -1)); } output = PyFile_AsFile(py_file); if (output == NULL) { - return(PyInt_FromLong((long) -1)); + return (PyInt_FromLong((long) -1)); } if (node->type == XML_DOCUMENT_NODE) { - doc = (xmlDocPtr) node; + doc = (xmlDocPtr) node; } else if (node->type == XML_HTML_DOCUMENT_NODE) { - doc = (xmlDocPtr) node; + doc = (xmlDocPtr) node; } else { - doc = node->doc; + doc = node->doc; } if (doc->type == XML_HTML_DOCUMENT_NODE) { - if (encoding == NULL) - encoding = (xmlChar *) htmlGetMetaEncoding(doc); + if (encoding == NULL) + encoding = (const char *) htmlGetMetaEncoding(doc); } if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - return(PyInt_FromLong((long) -1)); - } + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + return (PyInt_FromLong((long) -1)); + } } if (doc->type == XML_HTML_DOCUMENT_NODE) { - if (handler == NULL) - handler = xmlFindCharEncodingHandler("HTML"); - if (handler == NULL) - handler = xmlFindCharEncodingHandler("ascii"); + if (handler == NULL) + handler = xmlFindCharEncodingHandler("HTML"); + if (handler == NULL) + handler = xmlFindCharEncodingHandler("ascii"); } buf = xmlOutputBufferCreateFile(output, handler); if (node->type == XML_DOCUMENT_NODE) { - len = xmlSaveFormatFileTo(buf, doc, encoding, format); + len = xmlSaveFormatFileTo(buf, doc, encoding, format); } else if (node->type == XML_HTML_DOCUMENT_NODE) { - htmlDocContentDumpFormatOutput(buf, doc, encoding, format); - len = xmlOutputBufferClose(buf); + htmlDocContentDumpFormatOutput(buf, doc, encoding, format); + len = xmlOutputBufferClose(buf); } else if (doc->type == XML_HTML_DOCUMENT_NODE) { - htmlNodeDumpFormatOutput(buf, doc, node, encoding, format); - len = xmlOutputBufferClose(buf); + htmlNodeDumpFormatOutput(buf, doc, node, encoding, format); + len = xmlOutputBufferClose(buf); } else { - xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); - len = xmlOutputBufferClose(buf); + xmlNodeDumpOutput(buf, doc, node, 0, format, encoding); + len = xmlOutputBufferClose(buf); } - return(PyInt_FromLong((long) len)); + return (PyInt_FromLong((long) len)); } /************************************************************************ @@ -1685,22 +1783,23 @@ libxml_saveNodeTo(PyObject *self, PyObject *args) { * * ************************************************************************/ PyObject * -libxml_xmlNewNode(PyObject *self, PyObject *args) { +libxml_xmlNewNode(ATTRIBUTE_UNUSED PyObject * self, PyObject * args) +{ PyObject *py_retval; - xmlChar * name; + xmlChar *name; xmlNodePtr node; - if (!PyArg_ParseTuple(args, "s:xmlNewNode", &name)) - return(NULL); + if (!PyArg_ParseTuple(args, (char *) "s:xmlNewNode", &name)) + return (NULL); node = (xmlNodePtr) xmlNewNode(NULL, name); - printf("NewNode: %s : %p\n", name, node); + printf("NewNode: %s : %p\n", name, (void *) node); if (node == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } py_retval = libxml_xmlNodePtrWrap(node); - return(py_retval); + return (py_retval); } /************************************************************************ @@ -1710,32 +1809,34 @@ libxml_xmlNewNode(PyObject *self, PyObject *args) { ************************************************************************/ static PyMethodDef libxmlMethods[] = { #include "libxml2-export.c" - { "name", libxml_name, METH_VARARGS, NULL }, - { "children", libxml_children, METH_VARARGS, NULL }, - { "properties", libxml_properties, METH_VARARGS, NULL }, - { "last", libxml_last, METH_VARARGS, NULL }, - { "prev", libxml_prev, METH_VARARGS, NULL }, - { "next", libxml_next, METH_VARARGS, NULL }, - { "parent", libxml_parent, METH_VARARGS, NULL }, - { "type", libxml_type, METH_VARARGS, NULL }, - { "doc", libxml_doc, METH_VARARGS, NULL }, - { "xmlNewNode", libxml_xmlNewNode, METH_VARARGS, NULL }, - { "serializeNode", libxml_serializeNode, METH_VARARGS, NULL }, - { "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL }, - { NULL } + {(char *) "name", libxml_name, METH_VARARGS, NULL}, + {(char *) "children", libxml_children, METH_VARARGS, NULL}, + {(char *) "properties", libxml_properties, METH_VARARGS, NULL}, + {(char *) "last", libxml_last, METH_VARARGS, NULL}, + {(char *) "prev", libxml_prev, METH_VARARGS, NULL}, + {(char *) "next", libxml_next, METH_VARARGS, NULL}, + {(char *) "parent", libxml_parent, METH_VARARGS, NULL}, + {(char *) "type", libxml_type, METH_VARARGS, NULL}, + {(char *) "doc", libxml_doc, METH_VARARGS, NULL}, + {(char *) "xmlNewNode", libxml_xmlNewNode, METH_VARARGS, NULL}, + {(char *) "serializeNode", libxml_serializeNode, METH_VARARGS, NULL}, + {(char *) "saveNodeTo", libxml_saveNodeTo, METH_VARARGS, NULL}, + {NULL, NULL, 0, NULL} }; #ifdef MERGED_MODULES extern void initlibxsltmod(void); #endif -void initlibxml2mod(void) { +void +initlibxml2mod(void) +{ static int initialized = 0; PyObject *m; if (initialized != 0) - return; - m = Py_InitModule("libxml2mod", libxmlMethods); + return; + m = Py_InitModule((char *) "libxml2mod", libxmlMethods); initialized = 1; libxml_xmlErrorInitialize(); @@ -1743,4 +1844,3 @@ void initlibxml2mod(void) { initlibxsltmod(); #endif } - diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am index 9a326e42..be21203b 100644 --- a/python/tests/Makefile.am +++ b/python/tests/Makefile.am @@ -25,7 +25,7 @@ EXTRA_DIST = $(PYTESTS) $(XMLS) if WITH_PYTHON tests: $(PYTESTS) - -@(PYTHONPATH=".." ; export PYTHONPATH; \ + -@(PYTHONPATH="..:../.libs" ; export PYTHONPATH; \ for test in $(PYTESTS) ; do echo "-- $$test" ; $(PYTHON) $$test ; done) else tests: diff --git a/python/types.c b/python/types.c index 12562450..2eff1a3e 100644 --- a/python/types.c +++ b/python/types.c @@ -9,256 +9,288 @@ #include "libxml_wrap.h" PyObject * -libxml_intWrap(int val) { +libxml_intWrap(int val) +{ PyObject *ret; #ifdef DEBUG printf("libxml_intWrap: val = %d\n", val); #endif ret = PyInt_FromLong((long) val); - return(ret); + return (ret); } PyObject * -libxml_longWrap(long val) { +libxml_longWrap(long val) +{ PyObject *ret; #ifdef DEBUG printf("libxml_longWrap: val = %ld\n", val); #endif ret = PyInt_FromLong(val); - return(ret); + return (ret); } PyObject * -libxml_doubleWrap(double val) { +libxml_doubleWrap(double val) +{ PyObject *ret; #ifdef DEBUG printf("libxml_doubleWrap: val = %f\n", val); #endif ret = PyFloat_FromDouble((double) val); - return(ret); + return (ret); } PyObject * -libxml_charPtrWrap(char *str) { +libxml_charPtrWrap(char *str) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlcharPtrWrap: str = %s\n", str); #endif if (str == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ ret = PyString_FromString(str); xmlFree(str); - return(ret); + return (ret); } PyObject * -libxml_charPtrConstWrap(const char *str) { +libxml_charPtrConstWrap(const char *str) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlcharPtrWrap: str = %s\n", str); #endif if (str == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ ret = PyString_FromString(str); - return(ret); + return (ret); } PyObject * -libxml_xmlCharPtrWrap(xmlChar *str) { +libxml_xmlCharPtrWrap(xmlChar * str) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlCharPtrWrap: str = %s\n", str); #endif if (str == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ - ret = PyString_FromString(str); + ret = PyString_FromString((char *) str); xmlFree(str); - return(ret); + return (ret); } PyObject * -libxml_xmlCharPtrConstWrap(const xmlChar *str) { +libxml_xmlCharPtrConstWrap(const xmlChar * str) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlCharPtrWrap: str = %s\n", str); #endif if (str == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ - ret = PyString_FromString(str); - return(ret); + ret = PyString_FromString((char *) str); + return (ret); } PyObject * -libxml_constcharPtrWrap(const char *str) { +libxml_constcharPtrWrap(const char *str) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlcharPtrWrap: str = %s\n", str); #endif if (str == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ ret = PyString_FromString(str); - return(ret); + return (ret); } PyObject * -libxml_constxmlCharPtrWrap(const xmlChar *str) { +libxml_constxmlCharPtrWrap(const xmlChar * str) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlCharPtrWrap: str = %s\n", str); #endif if (str == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ - ret = PyString_FromString(str); - return(ret); + ret = PyString_FromString((char *) str); + return (ret); } PyObject * -libxml_xmlDocPtrWrap(xmlDocPtr doc) { +libxml_xmlDocPtrWrap(xmlDocPtr doc) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlDocPtrWrap: doc = %p\n", doc); #endif if (doc == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } /* TODO: look at deallocation */ - ret = PyCObject_FromVoidPtrAndDesc((void *) doc, "xmlDocPtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr", + NULL); + return (ret); } PyObject * -libxml_xmlNodePtrWrap(xmlNodePtr node) { +libxml_xmlNodePtrWrap(xmlNodePtr node) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlNodePtrWrap: node = %p\n", node); #endif if (node == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) node, "xmlNodePtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr", + NULL); + return (ret); } PyObject * -libxml_xmlURIPtrWrap(xmlURIPtr uri) { +libxml_xmlURIPtrWrap(xmlURIPtr uri) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlURIPtrWrap: uri = %p\n", uri); #endif if (uri == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) uri, "xmlURIPtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) uri, (char *) "xmlURIPtr", + NULL); + return (ret); } PyObject * -libxml_xmlNsPtrWrap(xmlNsPtr ns) { +libxml_xmlNsPtrWrap(xmlNsPtr ns) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlNsPtrWrap: node = %p\n", ns); #endif if (ns == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) ns, "xmlNsPtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) ns, (char *) "xmlNsPtr", + NULL); + return (ret); } PyObject * -libxml_xmlAttrPtrWrap(xmlAttrPtr attr) { +libxml_xmlAttrPtrWrap(xmlAttrPtr attr) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlAttrNodePtrWrap: attr = %p\n", attr); #endif if (attr == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) attr, "xmlAttrPtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) attr, (char *) "xmlAttrPtr", + NULL); + return (ret); } PyObject * -libxml_xmlAttributePtrWrap(xmlAttributePtr attr) { +libxml_xmlAttributePtrWrap(xmlAttributePtr attr) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlAttributePtrWrap: attr = %p\n", attr); #endif if (attr == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) attr, "xmlAttributePtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) attr, + (char *) "xmlAttributePtr", NULL); + return (ret); } PyObject * -libxml_xmlElementPtrWrap(xmlElementPtr elem) { +libxml_xmlElementPtrWrap(xmlElementPtr elem) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlElementNodePtrWrap: elem = %p\n", elem); #endif if (elem == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) elem, "xmlElementPtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) elem, + (char *) "xmlElementPtr", NULL); + return (ret); } PyObject * -libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt) { +libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlXPathContextPtrWrap: ctxt = %p\n", ctxt); #endif if (ctxt == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xmlXPathContextPtr", - NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) ctxt, + (char *) "xmlXPathContextPtr", NULL); + return (ret); } PyObject * @@ -274,153 +306,166 @@ libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt) return (Py_None); } ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, - "xmlXPathParserContextPtr", NULL); + (char *) "xmlXPathParserContextPtr", + NULL); return (ret); } PyObject * -libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt) { +libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlParserCtxtPtrWrap: ctxt = %p\n", ctxt); #endif if (ctxt == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xmlParserCtxtPtr", - NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) ctxt, + (char *) "xmlParserCtxtPtr", NULL); + return (ret); } PyObject * -libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) { +libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlXPathObjectPtrWrap: ctxt = %p\n", obj); #endif if (obj == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - switch(obj->type) { + switch (obj->type) { case XPATH_XSLT_TREE: - /* TODO !!!! Allocation problems */ + /* TODO !!!! Allocation problems */ case XPATH_NODESET: - if ((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) - ret = PyList_New(0); - else { - int i; - xmlNodePtr node; + if ((obj->nodesetval == NULL) + || (obj->nodesetval->nodeNr == 0)) + ret = PyList_New(0); + else { + int i; + xmlNodePtr node; - ret = PyList_New(obj->nodesetval->nodeNr); - for (i = 0;i < obj->nodesetval->nodeNr;i++) { - node = obj->nodesetval->nodeTab[i]; - /* TODO: try to cast directly to the proper node type */ - PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node)); - } - } - break; + ret = PyList_New(obj->nodesetval->nodeNr); + for (i = 0; i < obj->nodesetval->nodeNr; i++) { + node = obj->nodesetval->nodeTab[i]; + /* TODO: try to cast directly to the proper node type */ + PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node)); + } + } + break; case XPATH_BOOLEAN: - ret = PyInt_FromLong((long) obj->boolval); - break; + ret = PyInt_FromLong((long) obj->boolval); + break; case XPATH_NUMBER: - ret = PyFloat_FromDouble(obj->floatval); - break; + ret = PyFloat_FromDouble(obj->floatval); + break; case XPATH_STRING: - ret = PyString_FromString(obj->stringval); - break; + ret = PyString_FromString((char *) obj->stringval); + break; case XPATH_POINT: case XPATH_RANGE: case XPATH_LOCATIONSET: - default: - printf("Unable to convert XPath object type %d\n", obj->type); - Py_INCREF(Py_None); - ret = Py_None; + default: + printf("Unable to convert XPath object type %d\n", obj->type); + Py_INCREF(Py_None); + ret = Py_None; } xmlXPathFreeObject(obj); - return(ret); + return (ret); } xmlXPathObjectPtr -libxml_xmlXPathObjectPtrConvert(PyObject * obj) { +libxml_xmlXPathObjectPtrConvert(PyObject * obj) +{ xmlXPathObjectPtr ret = NULL; #ifdef DEBUG printf("libxml_xmlXPathObjectPtrConvert: obj = %p\n", obj); #endif if (obj == NULL) { - return(NULL); + return (NULL); } - if PyFloat_Check(obj) { - ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj)); - } else if PyString_Check(obj) { - xmlChar *str; + if PyFloat_Check + (obj) { + ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj)); + } else if PyString_Check + (obj) { + xmlChar *str; - str = xmlStrndup((const xmlChar *)PyString_AS_STRING(obj), - PyString_GET_SIZE(obj)); - ret = xmlXPathWrapString(str); - } else if PyList_Check(obj) { - int i; - PyObject *node; - xmlNodePtr cur; - xmlNodeSetPtr set; + str = xmlStrndup((const xmlChar *) PyString_AS_STRING(obj), + PyString_GET_SIZE(obj)); + ret = xmlXPathWrapString(str); + } else if PyList_Check + (obj) { + int i; + PyObject *node; + xmlNodePtr cur; + xmlNodeSetPtr set; - set = xmlXPathNodeSetCreate(NULL); + set = xmlXPathNodeSetCreate(NULL); - for (i = 0;i < PyList_Size(obj);i++) { - node = PyList_GetItem(obj, i); - if ((node == NULL) || (node->ob_type == NULL)) - continue; + for (i = 0; i < PyList_Size(obj); i++) { + node = PyList_GetItem(obj, i); + if ((node == NULL) || (node->ob_type == NULL)) + continue; - cur = NULL; - if (PyCObject_Check(node)) { - printf("Got a CObject\n"); - cur = PyxmlNode_Get(node); - } else if (PyInstance_Check(node)) { - PyInstanceObject *inst = (PyInstanceObject *) node; - PyObject *name = inst->in_class->cl_name; - if PyString_Check(name) { - char *type = PyString_AS_STRING(name); - PyObject *wrapper; + cur = NULL; + if (PyCObject_Check(node)) { + printf("Got a CObject\n"); + cur = PyxmlNode_Get(node); + } else if (PyInstance_Check(node)) { + PyInstanceObject *inst = (PyInstanceObject *) node; + PyObject *name = inst->in_class->cl_name; - if (!strcmp(type, "xmlNode")) { - wrapper = PyObject_GetAttrString(node, "_o"); - if (wrapper != NULL) { - cur = PyxmlNode_Get(wrapper); - } - } - } - } else { - printf("Unknown object in Python return list\n"); - } - if (cur != NULL) { - xmlXPathNodeSetAdd(set, cur); - } - } - ret = xmlXPathWrapNodeSet(set); + if PyString_Check + (name) { + char *type = PyString_AS_STRING(name); + PyObject *wrapper; + + if (!strcmp(type, "xmlNode")) { + wrapper = + PyObject_GetAttrString(node, (char *) "_o"); + if (wrapper != NULL) { + cur = PyxmlNode_Get(wrapper); + } + } + } + } else { + printf("Unknown object in Python return list\n"); + } + if (cur != NULL) { + xmlXPathNodeSetAdd(set, cur); + } + } + ret = xmlXPathWrapNodeSet(set); } else { - printf("Unable to convert Python Object to XPath"); + printf("Unable to convert Python Object to XPath"); } Py_DECREF(obj); - return(ret); + return (ret); } PyObject * -libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal) { +libxml_xmlCatalogPtrWrap(xmlCatalogPtr catal) +{ PyObject *ret; #ifdef DEBUG printf("libxml_xmlNodePtrWrap: catal = %p\n", catal); #endif if (catal == NULL) { - Py_INCREF(Py_None); - return(Py_None); + Py_INCREF(Py_None); + return (Py_None); } - ret = PyCObject_FromVoidPtrAndDesc((void *) catal, "xmlCatalogPtr", NULL); - return(ret); + ret = + PyCObject_FromVoidPtrAndDesc((void *) catal, + (char *) "xmlCatalogPtr", NULL); + return (ret); } - -