summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-03-18 15:24:51 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-03-18 15:24:51 +0000
commit2abd71732c5d4cb31a3177262c605920918d7b54 (patch)
tree1c0d48b83104ae97ca9270f3b71b41b13c38e679 /python
parent0503357eba2199d1cad0d6fe209d141d97d1c9ee (diff)
downloadlibxslt-2abd71732c5d4cb31a3177262c605920918d7b54.tar.gz
libxslt-2abd71732c5d4cb31a3177262c605920918d7b54.tar.bz2
libxslt-2abd71732c5d4cb31a3177262c605920918d7b54.zip
applied the same kind of fixes to the Python Makefiels than to libxml2
* python/Makefile.am python/generator.py python/libxslt.c python/types.c python/tests/Makefile.am: applied the same kind of fixes to the Python Makefiels than to libxml2 ones. Updates and cleanups too. Daniel
Diffstat (limited to 'python')
-rw-r--r--python/Makefile.am41
-rwxr-xr-xpython/generator.py26
-rw-r--r--python/libxslt.c121
-rw-r--r--python/tests/Makefile.am2
-rw-r--r--python/types.c383
5 files changed, 332 insertions, 241 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 84cfc973..bd30ef57 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -4,13 +4,13 @@ AUTOMAKE_OPTIONS = 1.4 foreign
SUBDIRS= . tests
INCLUDES = \
- -I/usr/include/python$(PYTHON_VERSION) \
-I$(PYTHON_INCLUDES) \
$(LIBXML_CFLAGS) \
-I$(top_srcdir)
DOCS_DIR = $(prefix)/share/doc/libxslt-python-$(LIBXML_VERSION)
-DOCS = TODO libxsltclass.txt
+# libxsltclass.txt is generated
+DOCS = TODO
EXTRA_DIST = \
libxslt.c \
@@ -22,37 +22,20 @@ EXTRA_DIST = \
libxslt-python-api.xml \
$(DOCS)
+libxsltmod_la_LDFLAGS = -module -avoid-version
+
if WITH_PYTHON
mylibs = \
$(top_builddir)/libxslt/libxslt.la \
$(top_builddir)/libexslt/libexslt.la
-LDADD = -lxslt -lexslt
-CFLAGS = -Wall -g
+all: libxslt.py
pythondir = $(prefix)/lib/python${PYTHON_VERSION}/site-packages
-python_PROGRAMS = libxsltmod.so
-
-libxsltmod_so_SOURCES =
-libxsltmod_so_LDFLAGS = $(mylibs) $(LIBS) -shared -Wl,-soname,libxsltmod.so
-
-noinst_LTLIBRARIES = libxsltmodule.la
-libxsltmodule_la_SOURCES = libxslt.c types.c libxslt-py.c
-
-GENERATE = generator.py
-API_DESC = $(top_srcdir)/doc/libxslt-api.xml $(srcdir)/libxslt-python-api.xml
-GENERATED= $(srcdir)/libxsltclass.py \
- $(srcdir)/libxslt-export.c \
- $(srcdir)/libxslt-py.c \
- $(srcdir)/libxslt-py.h
-
-all: $(GENERATED) libxsltmod.so libxslt.py $(PYTHONSODV)
-
-libxsltmod.so: $(libxsltmodule_la_OBJECTS) libxsltmodule.la
- -(rm -f .libs/libxsltmod.so; \
- $(LINK) -o $@ $(libxsltmodule_la_OBJECTS) $(libxsltmod_so_LDFLAGS);\
- if [ -r .libs/libxsltmod.so ] ; then cp .libs/libxsltmod.so . ; fi)
+python_LTLIBRARIES = libxsltmod.la
+libxsltmod_la_SOURCES = libxslt.c types.c libxslt-py.c
+libxsltmod_la_LIBADD = $(mylibs)
libxslt.py: $(srcdir)/libxsl.py libxsltclass.py
cat $(srcdir)/libxsl.py libxsltclass.py > libxslt.py
@@ -64,6 +47,13 @@ install-data-local:
-@(for doc in $(DOCS) ; \
do @INSTALL@ -m 0644 $$doc $(DESTDIR)$(DOCS_DIR) ; done)
+GENERATE = generator.py
+API_DESC = $(top_srcdir)/doc/libxslt-api.xml $(srcdir)/libxslt-python-api.xml
+GENERATED= $(srcdir)/libxsltclass.py \
+ $(srcdir)/libxslt-export.c \
+ $(srcdir)/libxslt-py.c \
+ $(srcdir)/libxslt-py.h
+
$(GENERATED): $(srcdir)/$(GENERATE) $(API_DESC)
cd $(srcdir) && $(PYTHON) $(GENERATE)
@@ -78,4 +68,3 @@ tests test: all
clean:
rm -f $(GENERATED) *.o libxslt.so *.pyc libxslt.py
-
diff --git a/python/generator.py b/python/generator.py
index 6a6abe4a..0ea7ae6d 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -351,8 +351,14 @@ def print_function_wrapper(name, output, export, include):
if ret[0] == 'void':
if file == "python_accessor":
- c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
- args[1][0])
+ 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((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],
+ args[1][0])
else:
c_call = "\n %s(%s);\n" % (name, c_call);
ret_convert = " Py_INCREF(Py_None);\n return(Py_None);\n"
@@ -368,7 +374,10 @@ def print_function_wrapper(name, output, export, include):
elif py_return_types.has_key(ret[0]):
(f, t, n, c, p) = py_return_types[ret[0]]
c_return = " %s c_retval;\n" % (ret[0])
- c_call = "\n c_retval = %s(%s);\n" % (name, c_call);
+ if file == "python_accessor" and ret[2] != None:
+ c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2])
+ else:
+ c_call = "\n c_retval = %s(%s);\n" % (name, c_call);
ret_convert = " py_retval = %s%sWrap((%s) c_retval);\n" % (p,n,c)
ret_convert = ret_convert + " return(py_retval);\n"
else:
@@ -384,7 +393,7 @@ def print_function_wrapper(name, output, export, include):
include.write("PyObject * ")
include.write("libxslt_%s(PyObject *self, PyObject *args);\n" % (name))
- export.write(" { \"%s\", libxslt_%s, METH_VARARGS, NULL },\n" % (name, name))
+ export.write(" { (char *)\"%s\", libxslt_%s, METH_VARARGS, NULL },\n" % (name, name))
if file == "python":
# Those have been manually generated
@@ -394,7 +403,10 @@ def print_function_wrapper(name, output, export, include):
return 1
output.write("PyObject *\n")
- output.write("libxslt_%s(PyObject *self, PyObject *args) {\n" % (name))
+ output.write("libxslt_%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 != "":
@@ -402,7 +414,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 != "":
@@ -461,6 +473,8 @@ def buildStubs():
export.write("/* Generated */\n\n")
wrapper = open("libxslt-py.c", "w")
wrapper.write("/* Generated */\n\n")
+ wrapper.write("#include \"config.h\"\n")
+ wrapper.write("#include <libxslt/xsltconfig.h>\n")
wrapper.write("#include \"libxslt_wrap.h\"\n")
wrapper.write("#include \"libxslt-py.h\"\n\n")
for function in functions.keys():
diff --git a/python/libxslt.c b/python/libxslt.c
index 50e9b5b2..5c9eb0eb 100644
--- a/python/libxslt.c
+++ b/python/libxslt.c
@@ -12,17 +12,21 @@
* daniel@veillard.com
*/
#include <Python.h>
+#include "config.h"
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include "libxslt_wrap.h"
#include "libxslt-py.h"
+
/* #define DEBUG */
/* #define DEBUG_XPATH */
/* #define DEBUG_ERROR */
/* #define DEBUG_MEMORY */
+void initlibxsltmod(void);
+
/************************************************************************
* *
* Per type specific glue *
@@ -40,7 +44,8 @@ libxslt_xsltStylesheetPtrWrap(xsltStylesheetPtr style) {
Py_INCREF(Py_None);
return(Py_None);
}
- ret = PyCObject_FromVoidPtrAndDesc((void *) style, "xsltStylesheetPtr", NULL);
+ ret = PyCObject_FromVoidPtrAndDesc((void *) style,
+ (char *)"xsltStylesheetPtr", NULL);
return(ret);
}
@@ -55,97 +60,13 @@ libxslt_xsltTransformContextPtrWrap(xsltTransformContextPtr ctxt) {
Py_INCREF(Py_None);
return(Py_None);
}
- ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xsltTransformContextPtr", NULL);
+ ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
+ (char *)"xsltTransformContextPtr", NULL);
return(ret);
}
/************************************************************************
* *
- * Memory debug interface *
- * *
- ************************************************************************/
-
-extern void xmlMemFree(void *ptr);
-extern void *xmlMemMalloc(size_t size);
-extern void *xmlMemRealloc(void *ptr,size_t size);
-extern char *xmlMemoryStrdup(const char *str);
-
-static int libxsltMemoryDebugActivated = 0;
-static long libxsltMemoryAllocatedBase = 0;
-
-static int libxsltMemoryDebug = 0;
-static xmlFreeFunc freeFunc = NULL;
-static xmlMallocFunc mallocFunc = NULL;
-static xmlReallocFunc reallocFunc = NULL;
-static xmlStrdupFunc strdupFunc = NULL;
-
-PyObject *
-libxslt_xmlDebugMemory(PyObject *self, PyObject *args) {
- int activate;
- PyObject *py_retval;
- long ret;
-
- if (!PyArg_ParseTuple(args, "i:xmlDebugMemory", &activate))
- return(NULL);
-
-#ifdef DEBUG_MEMORY
- printf("libxslt_xmlDebugMemory(%d) called\n", activate);
-#endif
-
- if (activate != 0) {
- if (libxsltMemoryDebug == 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)) {
- libxsltMemoryAllocatedBase = xmlMemUsed();
- } else {
- ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc,
- xmlMemRealloc, xmlMemoryStrdup);
- if (ret < 0)
- goto error;
- libxsltMemoryAllocatedBase = xmlMemUsed();
- }
- xmlInitParser();
- ret = 0;
- } else if (libxsltMemoryDebugActivated == 0) {
- libxsltMemoryAllocatedBase = xmlMemUsed();
- ret = 0;
- } else {
- ret = xmlMemUsed() - libxsltMemoryAllocatedBase;
- }
- libxsltMemoryDebug = 1;
- libxsltMemoryDebugActivated = 1;
- } else {
- if (libxsltMemoryDebugActivated == 1)
- ret = xmlMemUsed() - libxsltMemoryAllocatedBase;
- else
- ret = 0;
- libxsltMemoryDebugActivated = 0;
- }
-error:
- py_retval = libxml_longWrap(ret);
- return(py_retval);
-}
-
-PyObject *
-libxslt_xmlDumpMemory(PyObject *self, PyObject *args) {
-
- if (libxsltMemoryDebug != 0)
- xmlMemoryDump();
- Py_INCREF(Py_None);
- return(Py_None);
-}
-
-/************************************************************************
- * *
* Extending the API *
* *
************************************************************************/
@@ -199,14 +120,15 @@ libxslt_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs) {
}
PyObject *
-libxslt_xsltRegisterExtModuleFunction(PyObject *self, PyObject *args) {
+libxslt_xsltRegisterExtModuleFunction(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
PyObject *py_retval;
int ret = 0;
xmlChar *name;
xmlChar *ns_uri;
PyObject *pyobj_f;
- if (!PyArg_ParseTuple(args, "szO:registerXPathFunction",
+ if (!PyArg_ParseTuple(args, (char *)"szO:registerXPathFunction",
&name, &ns_uri, &pyobj_f))
return(NULL);
@@ -239,8 +161,8 @@ libxslt_xsltRegisterExtModuleFunction(PyObject *self, PyObject *args) {
return(py_retval);
}
-void
-deallocateCallback(void *payload, xmlChar *name) {
+static void
+deallocateCallback(void *payload, xmlChar *name ATTRIBUTE_UNUSED) {
PyObject *function = (PyObject *) payload;
#ifdef DEBUG_XPATH
@@ -257,7 +179,7 @@ deallocateCallback(void *payload, xmlChar *name) {
************************************************************************/
PyObject *
-libxslt_xsltApplyStylesheet(PyObject *self, PyObject *args) {
+libxslt_xsltApplyStylesheet(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
xmlDocPtr c_retval;
xsltStylesheetPtr style;
@@ -270,7 +192,8 @@ libxslt_xsltApplyStylesheet(PyObject *self, PyObject *args) {
PyObject *name;
PyObject *value;
- if (!PyArg_ParseTuple(args, "OOO:xsltApplyStylesheet", &pyobj_style, &pyobj_doc, &pyobj_params))
+ if (!PyArg_ParseTuple(args, (char *) "OOO:xsltApplyStylesheet",
+ &pyobj_style, &pyobj_doc, &pyobj_params))
return(NULL);
if (pyobj_params != Py_None) {
@@ -291,11 +214,12 @@ libxslt_xsltApplyStylesheet(PyObject *self, PyObject *args) {
tmp = PyString_AS_STRING(name);
size = PyString_GET_SIZE(name);
- params[j * 2] = xmlCharStrndup(tmp, size);
+ params[j * 2] = (char *) xmlCharStrndup(tmp, size);
if (PyString_Check(value)) {
tmp = PyString_AS_STRING(value);
size = PyString_GET_SIZE(value);
- params[(j * 2) + 1] = xmlCharStrndup(tmp, size);
+ params[(j * 2) + 1] = (char *)
+ xmlCharStrndup(tmp, size);
} else {
params[(j * 2) + 1] = NULL;
}
@@ -334,7 +258,8 @@ libxslt_xsltApplyStylesheet(PyObject *self, PyObject *args) {
************************************************************************/
PyObject *
-libxslt_xsltCleanup(PyObject *self, PyObject *args) {
+libxslt_xsltCleanup(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args ATTRIBUTE_UNUSED) {
if (libxslt_extModuleFunctions != NULL) {
xmlHashFree(libxslt_extModuleFunctions, deallocateCallback);
@@ -352,7 +277,7 @@ libxslt_xsltCleanup(PyObject *self, PyObject *args) {
************************************************************************/
static PyMethodDef libxsltMethods[] = {
#include "libxslt-export.c"
- { NULL }
+ { NULL, NULL, 0, NULL }
};
#ifdef MERGED_MODULES
@@ -369,7 +294,7 @@ void initlibxsltmod(void) {
if (initialized != 0)
return;
- m = Py_InitModule("libxsltmod", libxsltMethods);
+ m = Py_InitModule((char *)"libxsltmod", libxsltMethods);
initialized = 1;
/* libxslt_xmlErrorInitialize(); */
/*
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am
index 8cc110d0..d4589e9f 100644
--- a/python/tests/Makefile.am
+++ b/python/tests/Makefile.am
@@ -15,7 +15,7 @@ EXTRA_DIST = $(TESTSPY) $(XMLS) $(EXTRAS)
if WITH_PYTHON
tests: $(TESTSPY)
- -@(PYTHONPATH=".." ; export PYTHONPATH; \
+ -@(PYTHONPATH="..:../.libs" ; export PYTHONPATH; \
for test in $(TESTSPY) ; do echo "-- $$test" ; $(PYTHON) $$test ; done)
else
tests:
diff --git a/python/types.c b/python/types.c
index 29fe84f2..2eff1a3e 100644
--- a/python/types.c
+++ b/python/types.c
@@ -6,303 +6,466 @@
*
* daniel@veillard.com
*/
-#include "libxslt_wrap.h"
+#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_xmlCharPtrWrap(xmlChar *str) {
+libxml_charPtrConstWrap(const char *str)
+{
PyObject *ret;
#ifdef DEBUG
- printf("libxml_xmlCharPtrWrap: str = %s\n", str);
+ 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);
+}
+
+PyObject *
+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);
+ }
+ /* TODO: look at deallocation */
+ ret = PyString_FromString((char *) str);
xmlFree(str);
- return(ret);
+ return (ret);
+}
+
+PyObject *
+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);
+ }
+ /* TODO: look at deallocation */
+ 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, (char *) "xmlNodePtr",
+ NULL);
+ return (ret);
+}
+
+PyObject *
+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);
}
- ret = PyCObject_FromVoidPtrAndDesc((void *) node, "xmlNodePtr", 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,
+ (char *) "xmlXPathContextPtr", NULL);
+ return (ret);
+}
+
+PyObject *
+libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt)
+{
+ PyObject *ret;
+
+#ifdef DEBUG
+ printf("libxml_xmlXPathParserContextPtrWrap: ctxt = %p\n", ctxt);
+#endif
+ if (ctxt == NULL) {
+ Py_INCREF(Py_None);
+ return (Py_None);
}
- ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt, "xmlXPathContextPtr",
- NULL);
- return(ret);
+ ret = PyCObject_FromVoidPtrAndDesc((void *) ctxt,
+ (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;
-
- 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;
+ 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;
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) {
- xmlXPathObjectPtr ret;
+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;
-
- str = xmlStrndup((const xmlChar *)PyString_AS_STRING(obj),
- PyString_GET_SIZE(obj));
- ret = xmlXPathWrapString(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;
+
+ set = xmlXPathNodeSetCreate(NULL);
+
+ 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;
+
+ 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)
+{
+ PyObject *ret;
+#ifdef DEBUG
+ printf("libxml_xmlNodePtrWrap: catal = %p\n", catal);
+#endif
+ if (catal == NULL) {
+ Py_INCREF(Py_None);
+ return (Py_None);
+ }
+ ret =
+ PyCObject_FromVoidPtrAndDesc((void *) catal,
+ (char *) "xmlCatalogPtr", NULL);
+ return (ret);
+}