Previous week Up Next week

Hello

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

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/84610ecfc72c6461#

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):
 http://home.gna.org/oug/index.en.html
			

OCaml bindings to hivex (Windows Registry hive library)

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/15fb6de8a3705037#

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:

http://libguestfs.org/hivex.3.html
http://git.annexia.org/?p=hivex.git;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.

http://git.annexia.org/?p=hivex.git;a=blob;f=generator/generator.ml;hb=HEAD
http://git.annexia.org/?p=hivex.git;a=tree;f=lib/tools;hb=HEAD
			

How to pass C pointers to Caml

Archive: http://groups.google.com/group/fa.caml/browse_thread/thread/fcaa97c95d2036c7#

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 http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html
> 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":
http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_ptr

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 http://planet.ocamlcore.org/.

OPA internships (continued):
  http://dutherenverseauborddelatable.wordpress.com/2010/02/26/opa-internships-continued/

OCaml Data Notation:
  https://forge.ocamlcore.org/projects/odn/

CCSS:
  https://forge.ocamlcore.org/projects/ccss/
      

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