English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Question about CAMLparamx macros
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-04-10 (16:21)
From: Raj Bandyopadhyay <rajb@r...>
Subject: Question about CAMLparamx macros

I am programming using the OCaml-C interface, and occasionally, my 
program segfaults in the OCaml function 'caml_oldify_local_roots()'

 From previous experience, I know that this usually means that I'm not 
using the CAMLparam/CAMLreturn macros correctly somewhere, causing the 
OCaml gc to find NULL pointers.

My question is, when do I have to use or not use these macros? I know I 
need to use these when my C function accepts AND returns OCaml 'value' 
types, but what about the following cases?

1) When the C function takes a value as parameter or creates a value 
local variable, but returns something else e.g.
char *foo(value v, int x)

2) When the C function does not create a value local variable explicitly 
or takes a value as a parameter but returns the result of a callback to 
the OCaml runtime
value foo(int x) {return caml_callback_exn(*caml_named_value(...),...)}
Do I have to use the CAMLparamx/CAMLlocalx/CAMLreturnx macros in the 
above cases? Would it cause problems if I used them anyway?