On Tue, Aug 26, 2014 at 09:10:11AM +0200, Pino Toscano wrote: > Hi, > > On Tuesday 26 August 2014 09:34:42 Shahar Havivi wrote: > > I am trying to add xmlXPathRegisterNs() to v2v/xml-c.c but I get a seg > > fault, the signature should be: > > http://xmlsoft.org/html/libxml-xpathInternals.html#xmlXPathRegisterNs > > > > I think I am wrong in CAMLparam and CAMLlocal..., > > Following is the patch: > > > > ====================================================================== > > diff --git a/v2v/xml-c.c b/v2v/xml-c.c > > index 4c9bc77..a917c24 100644 > > --- a/v2v/xml-c.c > > +++ b/v2v/xml-c.c > > @@ -141,6 +141,16 @@ v2v_xml_xpath_new_context (value docv) > > } > > > > value > > +v2v_xml_xpath_register_ns (value prefix, value uri, value xpathctx) > > +{ > > + CAMLparam3 (prefix, uri, xpathctx); > > + CAMLlocal1 (retval); > > + retval = xmlXPathRegisterNs (BAD_CAST String_val (prefix), BAD_CAST > > String_val (uri), xpathctx); > > + > > + CAMLreturn (retval); > > +} > > + > > First of all, you are using the xpathctx parameter directly as > parameter for xmlXPathRegisterNs, while it is an OCaml value which > wraps the actual object; see how it is done in e.g. > v2v_xml_xpath_eval_expression, using the Xpathctx_val macro. > > Second, the order of the arguments in your xmlXPathRegisterNs is wrong: > - yours: xmlXPathRegisterNs(prefix, uri, ctxt) > - actual function: xmlXPathRegisterNs(ctxt, prefix, uri)
This too. Notice that Val_foo() means convert foo to value, and Foo_val() means convert value to foo. In that file, only node_ptr/xmlNodePtr can be cast directly from value to the C type, and that's for a very special and peculiar reason. For everything else you have to convert between value and the C type (and vice versa) using the appropriate macro. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v _______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
