Previous week Up Next week


Here is the latest Caml Weekly News, for the week of February 23 to March 02, 2010.

  1. graph of function dependances
  2. OCaml bindings to hivex (Windows Registry hive library)
  3. How to pass C pointers to Caml
  4. Other Caml News

graph of function dependances


Grégoire Seux asked and Grégoire Seux replied:
> i am wondering if there exists a way to get a graphic visualiation of the
> dependances between functions defined in an ocaml file.
> For instance:
> let f x= x+1
> let g x= f x -1
> > let h x y = g x + (f x)
> should displayed that h relies on f and g definition.
> Maybe this not a pure ocaml-related question (more general) but i would need
> such a tool for my ocaml sources.

Oug seems to do what you need (and much more):

OCaml bindings to hivex (Windows Registry hive library)


Richard Jones announced:
Should anyone be crazy enough to want to examine or modify Windows
Registry 'hive' (binary) files directly, they can now do so from
OCaml, since we added OCaml bindings to our hivex library:;a=commitdiff;h=095c395082d1aad1e8558aa25514ad911e6d193c

There are example programs in the second link.

We also used OCaml for two other parts of this project: Firstly it is
used to generate the language binding boilerplate code for all
supported languages.  Secondly we used OCaml + bitstring to analyze
the undocumented hive files themselves.;a=blob;f=generator/;hb=HEAD;a=tree;f=lib/tools;hb=HEAD

How to pass C pointers to Caml


Jianzhou Zhao asked and Florent Monnier replied:
> I have been calling OCaml code from C in my project.
> The C code has some pointers to C structures.
> I got 'seg fault' when calling the OCaml function receiving
> C structure pointers.
> 18.7 at
> gives the examples that pass int into OCaml. These examples work for me.
> But, Does OCaml support to pass C structure pointers to OCaml?

Yes it does. Just cast your pointer to the type value.

In this tutorial there is an example "Pointers to C structures":

the pointer to a C struct is wrapped on the ocaml side by an abstract type
called "t" here, and it is provided back to C with print_t / dump_ptr.
Goswin von Brederlow then said and Florent Monnier replied:
> The problem with this trivial approach is that ocaml can store the
> pointer somewhere. When the C pointer is freeed then ocaml has a
> dangling pointer. Worse, if the GC allocates a new heap then the pointer
> might suddenly point into the heap and then BOOM.

A lot of bindings wrap C pointer, it is known to be a technic that does work.
Dangerous that's true, be if you are very careful, it works.
What you can do is set the pointer to NULL when the struct is freed, and then
each function that uses this struct pointer can first check if the pointer is
NULL or not before to use it, and if it's NULL raise an exception.

> It is better to put the pointer into an abstract or custom block.

You can do this too.

Other Caml News

From the ocamlcore planet blog:
Thanks to Alp Mestan, we now include in the Caml Weekly News the links to the
recent posts from the ocamlcore planet blog at

OPA internships (continued):

OCaml Data Notation:


Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.

Alan Schmitt