[xml-bindings]libxml-python C-API question

Hello everyone,

i'm trying to write a python (c-extension) module  that needs to
modify libxml2 documents. I seem to run against a (unfortunately
invisible :) wall when i try to get my hands on the xmlNodePtr
from within a function that gets passed a node. Here's the
stripped-down code:

static PyObject *
quark2xml_parseString(PyObject *self, PyObject *args)
  PyObject   *pyobj_tree;
  xmlChar    *buffer;
  xmlNodePtr  doc = NULL;
  xmlNodePtr  tmp = NULL;

  if (!PyArg_ParseTuple(args, (char *)"Os:parseString",
                        &pyobj_tree, &buffer))
    return NULL;

  doc = (xmlNodePtr) PyxmlNode_Get(pyobj_tree);

  /* printf-school of debugging :) */

  fprintf(stderr, "Node  looks like %s \n", PyObject_REPR(pyobj_tree));
  xmlNodeAddContent(doc, buffer);

Now, as you might have realized, most of the code is snarfed from the
python bindings code (i copied libxml_wrap.h). Still, if i call the function 
from python the node/document doesn't change. Worse: if i add a call to 
xmlDebugDumpNode() the whole thing segfaults.
I tried using:

  doc   = (xmlNodePtr) PyCObject_AsVoidPtr(doc)

which _should_ do the unwrapping, but that call returns NULL.

Any pointers to where to start looking for my stupidity?

 Ralf Mattes

PS: since i would guess that libxml2-python might be often used from other
modules, are there any plans to add a public C interface to it?
 doc   = (xmlNodePtr) PyCObject_AsVoidPtr(doc);

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]