From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 644D0BBC1 for ; Thu, 10 Apr 2008 18:21:02 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlkBAEvb/UeAKgEfiGdsb2JhbACRTQEBAQ8mmWw X-IronPort-AV: E=Sophos;i="4.25,636,1199660400"; d="scan'208";a="10711002" Received: from mail.cs.rice.edu ([128.42.1.31]) by mail1-smtp-roc.national.inria.fr with ESMTP; 10 Apr 2008 18:21:01 +0200 Received: from mail.cs.rice.edu (localhost.localdomain [127.0.0.1]) by mail.cs.rice.edu (Postfix) with ESMTP id C18012C2D36; Thu, 10 Apr 2008 11:21:00 -0500 (CDT) X-Virus-Scanned: by amavis-2.4.0 at mail.cs.rice.edu Received: from mail.cs.rice.edu ([127.0.0.1]) by mail.cs.rice.edu (mail.cs.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Tzj6LMmf05dV; Thu, 10 Apr 2008 11:20:53 -0500 (CDT) Received: from [10.121.20.238] (nat-168-7-229-185.rice.edu [168.7.229.185]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.cs.rice.edu (Postfix) with ESMTP id 1E3FB2C2AD6; Thu, 10 Apr 2008 11:20:53 -0500 (CDT) Message-ID: <47FE3E65.7030907@rice.edu> Date: Thu, 10 Apr 2008 11:20:53 -0500 From: Raj Bandyopadhyay User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Question about CAMLparamx macros Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; segfaults:01 ocaml:01 oldify:01 camlparam:01 camlreturn:01 ocaml:01 pointers:01 foo:01 runtime:01 foo:01 exn:01 ,...:98 char:01 macros:01 macros:01 Hi 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 e.g. 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? Thanks Raj