Learning Pyrex with libxml2

V

Victor Ng

Hi, I'm trying to learn how to use Pyrex by converting some of the
libxml2 examples. I'm not having much luck - I can create a document,
but any attempt to create nodes causes a segfault.

The code I'm trying to port is io2.c (http://xmlsoft.org/examples/io2.c)

I've commented the couple lines that cause a problem for me.

thanks,
vic


----


cdef extern from "libxml/tree.h":
ctypedef xmlDocPtr
ctypedef xmlNodePtr
ctypedef xmlNsPtr
xmlDocPtr xmlNewDoc(unsigned char *)
xmlNodePtr xmlNewNode (xmlNsPtr, unsigned char *)
void xmlNodeSetContent (xmlNodePtr, unsigned char *)
xmlNodePtr xmlDocSetRootElement (xmlDocPtr, xmlNodePtr )
void xmlDocDumpFormatMemory (xmlDocPtr, unsigned char **, int *, int )
xmlNodePtr xmlNewChild (xmlNodePtr, xmlNsPtr, unsigned char *,
unsigned char *)
void xmlFreeDoc (xmlDocPtr)
void xmlFree (xmlDocPtr)

def testNewDoc():
cdef xmlNodePtr n
cdef xmlDocPtr doc
cdef unsigned char* xmlbuff
cdef int buffersize

doc = xmlNewDoc(<unsigned char *> "1.0")

## The following three lines cause a segfault
# n = xmlNewNode(None, <unsigned char *> "root")
# xmlNodeSetContent(n, <unsigned char *> "content")
# xmlDocSetRootElement(doc, n)

xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1)
xmlFrag = <char* > xmlbuff
print "%d bytes in string" % len(xmlFrag)
print "[%s]" % xmlFrag



vic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top