From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DAFF3BB9C for ; Thu, 19 Jan 2006 15:53:00 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0JEr0sT032292 for ; Thu, 19 Jan 2006 15:53:00 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA07538 for ; Thu, 19 Jan 2006 15:52:59 +0100 (MET) Received: from mallaury.nerim.net (smtp-104-thursday.noc.nerim.net [62.4.17.104]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0JEqxqk006197 for ; Thu, 19 Jan 2006 15:52:59 +0100 Received: from karryall.dnsalias.org (oandrieu.pck.nerim.net [213.41.240.180]) by mallaury.nerim.net (Postfix) with ESMTP id A4DB94F405; Thu, 19 Jan 2006 15:52:50 +0100 (CET) Received: by karryall.dnsalias.org (Postfix, from userid 500) id 4E775596F6A; Thu, 19 Jan 2006 15:52:59 +0100 (CET) From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17359.42955.268490.985894@karryall.dnsalias.org> Date: Thu, 19 Jan 2006 15:52:59 +0100 To: Thomas Fischbacher Cc: Subject: Re: [Caml-list] C interface style question In-Reply-To: References: <20060119.093955.97297811.garrigue@math.nagoya-u.ac.jp> <1137640656.8943.183.camel@rosella> <02FDC6F0-122C-42BA-A2F4-15E2B08248C8@inria.fr> X-Mailer: VM 7.19 under Emacs 21.4.1 X-Miltered: at concorde with ID 43CFA7CC.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43CFA7CB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 nerim:01 caml-list:01 damien:01 val:01 ocaml:01 doubles:01 aligned:01 ocaml's:01 config:01 ifdef:01 ifdef:01 wrote:01 doligez:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Thomas Fischbacher [Thursday 19 January 2006] : > > > On Thu, 19 Jan 2006, Damien Doligez wrote: > > > > StoreField(v,n,(value)(void*)p); > > > > This is the only way. Always use Store_field, > > Store_double_field, and Store_double_val. > > One more question about this: can I interface a C function in such > a way that it uses an OCaml float array to store its output data, > i.e. pass &(Double_field(ml_output,0)) as a double* "output > parameter"? You can only do this on platform that accept doubles aligned on word boundaries (such as x86). On those platforms, OCaml's config.h undefines ARCH_ALIGN_DOUBLE. So your code might look like this : ,---- | double *c_array; | #ifdef ARCH_ALIGN_DOUBLE | c_array = /* allocate temporary storage and copy the caml float array */ | #else | c_array = (double *) ml_array; | #endif | | /* use c_array */ | | #ifdef ARCH_ALIGN_DOUBLE | free (c_array); | #endif `---- (And the part that "uses c_array" must not make any (caml) allocation) -- Olivier