hello, I have problem to parse xml string with ffi and libxml2. My code is in the test file libxml-raw.scm : (c-declare #<<end #include <stdlib.h> #include <libxml/xmlreader.h> xmlTextReaderPtr create_reader(const char* buffer, size_t len) { return xmlReaderForMemory(buffer, len, "_.xml", NULL, 0); } int first_type_prime(xmlTextReaderPtr reader) { int type; if( reader != NULL ) { int cont = xmlTextReaderRead(reader); if( cont ) { type = xmlTextReaderNodeType(reader); printf("read %d\n", type); xmlFreeTextReader(reader); return type; } xmlFreeTextReader(reader); return -1; } } int first_type(const char* s, size_t len) { return first_type_prime(create_reader(s, len)); } end ) (c-define-type xmlTextReader "xmlTextReader") (c-define-type xmlTextReaderPtr (pointer xmlTextReader)) (define create-reader (c-lambda (nonnull-char-string unsigned-int) xmlTextReaderPtr "create_reader")) (define first-type-prime (c-lambda (xmlTextReaderPtr) int "first_type_prime")) (define first-type (c-lambda (nonnull-char-string unsigned-int) int "first_type")) Two test functions are defined here : The first-type function take xml body and create the parser within the c body. The first-type-prime uses a pointer on xmlTextReader structure stored and the scheme-side. The first-type-prime function fails and I don't know what's going on : @ gsc-gambit Gambit v4.6.4
(compile-file "libxml-raw.scm" 'cc-options: "-Wno-write-strings -U___SINGLE_HOST -I/usr/local/include/libxml2" 'ld-options: "-L/usr/local/lib/ -lxml2") "/usr/users/cydu/programming/scheme/modules/xml/libxml-raw.o1" (load "libxml-raw")
"/usr/users/cydu/programming/scheme/modules/xml/libxml-raw.o1"
(define r (create-reader "<xml>toto</xml>" 15))
r #<xmlTextReader* #2 0x801781300> (first-type-prime r)
_.xml:1: parser error : Char 0x0 out of allowed range <xml ^ _.xml:1: parser error : Couldn't find end of Start Tag xml <xml ^ read 0 0
while this call works :
(first-type "<xml>toto</xml>" 15) read 1 1
Any idea what's happened ? thanks a lot cyrille