diff options
author | Mike Hommey <glandium@debian.org> | 2008-04-09 10:33:41 +0200 |
---|---|---|
committer | Mike Hommey <glandium@debian.org> | 2008-04-09 10:33:41 +0200 |
commit | 88f9c7ca80bfbc9a5429fc632b90d6c4a2a2787d (patch) | |
tree | e12ef38cd8eb205c495e5718852d758b95e3a3c6 /python/types.c | |
parent | fc760252aba4054a612dd20b803d0c7c19713064 (diff) | |
download | libxml2-88f9c7ca80bfbc9a5429fc632b90d6c4a2a2787d.tar.gz |
Load /tmp/libxml2-2.6.32 intoupstream/2.6.32.dfsg
libxml2/branches/upstream/current.
Diffstat (limited to 'python/types.c')
-rw-r--r-- | python/types.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/python/types.c b/python/types.c index 9a17749..80e4304 100644 --- a/python/types.c +++ b/python/types.c @@ -7,6 +7,7 @@ * daniel@veillard.com */ #include "libxml_wrap.h" +#include <libxml/xpathInternals.h> PyObject * libxml_intWrap(int val) @@ -330,6 +331,24 @@ libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt) return (ret); } +/** + * libxml_xmlXPathDestructNsNode: + * cobj: xmlNsPtr namespace node + * desc: ignored string + * + * This function is called if and when a namespace node returned in + * an XPath node set is to be destroyed. That's the only kind of + * object returned in node set not directly linked to the original + * xmlDoc document, see xmlXPathNodeSetDupNs. + */ +static void +libxml_xmlXPathDestructNsNode(void *cobj, void *desc ATTRIBUTE_UNUSED) { +#ifdef DEBUG + fprintf(stderr, "libxml_xmlXPathDestructNsNode called %p\n", cobj); +#endif + xmlXPathNodeSetFreeNs((xmlNsPtr) cobj); +} + PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) { @@ -380,8 +399,17 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) 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)); + if (node->type == XML_NAMESPACE_DECL) { + PyObject *ns = + PyCObject_FromVoidPtrAndDesc((void *) node, + (char *) "xmlNsPtr", + libxml_xmlXPathDestructNsNode); + PyList_SetItem(ret, i, ns); + /* make sure the xmlNsPtr is not destroyed now */ + obj->nodesetval->nodeTab[i] = NULL; + } else { + PyList_SetItem(ret, i, libxml_xmlNodePtrWrap(node)); + } } } break; |