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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 603A4BC0B for ; Wed, 24 Jan 2007 18:23:03 +0100 (CET) Received: from orion.metastack.com (no-dns-yet.demon.co.uk [80.177.38.218] (may be forged)) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0OHN2rE015396 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 24 Jan 2007 18:23:03 +0100 Received: from treble (cpc2-cmbg6-0-0-cust535.cmbg.cable.ntl.com [81.107.34.24]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id l0OGeMIj014814 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 24 Jan 2007 16:40:24 GMT From: "David Allsopp" To: "OCaml List" Subject: Interfacing with C question... Date: Wed, 24 Jan 2007 17:23:36 -0000 Organization: MetaStack Solutions Ltd. Message-ID: <002d01c73fdc$6254d430$6a7ba8c0@treble> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 Thread-Index: Acc/3GFHUzBwqo6FQ/WuxyzbNV6fJQ== X-Miltered: at discorde with ID 45B795F6.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; interfacing:01 val:01 val:01 macros:01 int:01 int:01 closure:01 closure:01 caml:02 caml:02 callback:02 callback:02 variables:02 declaring:02 string:02 Sorry if this an RADBOTFM case. Rule 2 in Chapter 18 of the manual states that all local variables of type value must be declared using CAMLlocal macros. However, later on when demonstrating caml_callback we get the statements: value* format_result_closure = caml_named_value("format_result"); return strdup(String_val(caml_callback(*format_result_closure, Val_int(n)))) (I've "simplified" the opening lines for clarity here - naturally it should be static and once only!). Two questions arise: 1. Presumably it's OK to cache values returned by caml_named_value without declaring them in a CAMLlocal "call" or by using register_global_root? 2. The result of caml_callback is passed straight to String_val. Therefore, if I expand the line to: value result = caml_callback(*format_result_closure, Val_int(n))); return strdup(String_val(result)); then does that work ok without using CAMLlocal1(result); Ta! David