Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

xmlreader bindings

I was just joking yesterday about how I need to write bindings for a C library before I can truly call myself an OCaml hax0r. So I wrote a wrapper for libxml's XmlTextReader.

It was pretty anticlimactic. Because the types are all verified at compile-time, you don't need to do any of the argument-checking that you do in Ruby bindings ("if the foo arg isn't an int, raise InvalidArgument", etc.) nor many of the casts (if something is a pointer, you can just pass it around directly). And because OCaml strings are represented in such a way that the pointers can be passed to C string functions directly, you can almost feed the parameters that the wrapper function gets directly into the underlying C function.

The only annoying stuff is the actual building: there are ton of confusing ways to build the libraries and they all break in subtle ways. Every OCaml package I've seen seems to use a different build system (autoconf, autoconf lookalike, OCamlMakefile, hand-hacked Makefile), too.
Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 3 comments