[xml] Segfaults on FreeBSD when using XPath....



-----BEGIN PGP SIGNED MESSAGE-----

Hello,
I'm currently trying to get into XPath parsing but even stumble
across the example by Gary Pennington by I found in the mailing
list archive (I basically want to parse a XML config file into a tree
so I can access individual nodes (parameters in this case) by their
path, so normal DOM won't do):

#include <stdio.h>
#include "libxml/parser.h"
#include "libxml/tree.h"
#include "libxml/xmlmemory.h"
#include "libxml/xpath.h"


extern int xmlDoValidityCheckingDefaultValue;


int
main(int argc, char **argv)
{
        xmlDocPtr doc;
        xmlNodePtr root;
        xmlXPathContextPtr ctx;
        xmlXPathObjectPtr path;
        const xmlChar *prop;


        if (argc != 2) {
                printf("usage:%s <filename>\n", argv[0]);
                exit(-1);
        }
        xmlKeepBlanksDefault(1);


        doc = xmlParseFile(argv[1]);
        printf("mem used =%d\n", xmlMemUsed());
        /* xmlMemDisplay(stdout); */
        root = xmlDocGetRootElement(doc);
        printf("Document root element name is %s\n", root->name);
        /*
         * Try to find root element using xpath...
         */
        xmlXPathInit();
        ctx = xmlXPathNewContext(doc);
        path = xmlXPathEvalExpression((const xmlChar
*)"id(\"calvin\")", ctx);
        printf("Document root element name is %s\n",
                path->nodesetval->nodeTab[0]->name);
        path = xmlXPathEvalExpression((const xmlChar
*)"count(/*/cpu_set_default)", ctx);
        printf("Document contains %.0f cpu_set_default elements\n",
                path->floatval);
        path = xmlXPathEvalExpression((const xmlChar *)
                "//cpu_set_default", ctx);
        root = path->nodesetval->nodeTab[0];
        printf("cpu_set_default Element name is %s\n",
                root->name);
        printf("Attribute created=%s\n",
                prop = xmlGetProp(root, (const xmlChar *)"created"));
        free(prop);
        xmlSetProp(root, (const xmlChar *)"created", (const xmlChar
*)"26");
        xmlXPathFreeObject(path);
        xmlXPathFreeContext(ctx);
        /*
         *Dump the document to stdout
         */
         /* xmlDocDump(stdout, doc); */
        xmlFreeDoc(doc);
        /* xmlMemDisplay(stdout); */
        printf("mem used =%d\n", xmlMemUsed());
        return (0);
}



it compiles perfectly smooth using:
gcc -L/usr/local/lib -I/usr/local/include -lxml2 -o test_xpath 
libxml_xpath_example.c

but at runtime the following occurs:

mem used =0
Memory list not compiled (MEM_LIST not defined !)
Document root element name is monitoring
Segmentation fault (core dumped)

i.e. it will display the first node and the memory used (0
for some reason) and then, as soon as xmlXPathInit() is called, it
ends up with a segfault. I'm using the FreeBSD port of libxml-2.3.8
and wonder whether this is a FreeBSD issue or related to some general
libxml bug. Any help would be greatly appreciated.



TIA & Best regards,
 Gabriel

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5i

iQEVAwUBOx+2wcZa2WpymlDxAQGKrwf9EArggl3HNLPSPC0UevWLTJFEAuxGcZVR
7Zm1O3XH4Bh/ebvPd4gioecljYgk8+TJCBy3n4ZF/1yI+5oTyTLik9Np9Q0E01g2
zHz74KqSJrXo7juNWwVC/f0GPEUOFj7OkhzYpxQCA0BaktCNzVRUtT1k1iodbklT
o0XRIMzlZWA3PX8GS/Rt0esjdHKNRWJc6sQ0w92GjJsIdEv9+47HiiF3aEACr++X
ZL/+eut8dS/9Uj27fu+3YlEATrWgW/iD/byiXnLnrMgcSbSxIA9hSpePxH01yQ0o
2il0gwTcYZYiBvjaKQP54yHQjk+uD2VOiSlO+Mz5R8ntqFJYhCOCEg==
=xC7Y
-----END PGP SIGNATURE-----





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