From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA10066; Thu, 29 Jan 2004 16:52:14 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA11032 for ; Thu, 29 Jan 2004 16:52:13 +0100 (MET) From: ronniec95@lineone.net Received: from mk-smarthost-3.mail.uk.tiscali.com (mk-smarthost-3.mail.uk.tiscali.com [212.74.114.39]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i0TFqDP06792 for ; Thu, 29 Jan 2004 16:52:13 +0100 (MET) Received: from mk-cpfront-1.mail.uk.tiscali.com ([212.74.114.3]:63688 helo=mk-cpfrontend.uk.tiscali.com) by mk-smarthost-3.mail.uk.tiscali.com with esmtp (Exim 4.24) id 1AmESh-000Flc-NE; Thu, 29 Jan 2004 15:52:11 +0000 Received: from [141.228.156.225] by mk-cpfrontend.uk.tiscali.com with HTTP; Thu, 29 Jan 2004 15:52:10 +0000 Date: Thu, 29 Jan 2004 15:52:10 +0000 Message-ID: <40169E8D00006A9F@mk-cpfrontend-1.mail.uk.tiscali.com> In-Reply-To: <20040129150209.GB30750@redhat.com> Subject: Re: [Caml-list] CamlDL/Abstract pointers problem To: "Richard Jones" Cc: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Loop: caml-list@inria.fr X-Spam: no; 0.00; ronniec:01 lineone:01 caml-list:01 pointers:01 2004:99 ronniec:01 lineone:01 caml-list:01 pointers:01 2004:99 val:01 camlparam:01 camllocal:01 alloc:01 camlreturn:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I understand that bit ok. But what I wanted to know is why CAMLIDL was no= t doing this for me... as I said in my original email, I'm quite happy hand= writing all this stuff (Abstract_tag/Custom_tag all ok for me )- it works fine, but is quite dull! I specifically wanted to know what it is about camlidl which stops it gen= erating the correct code for this. Ronnie >-- Original Message -- >Date: Thu, 29 Jan 2004 15:02:09 +0000 >To: ronniec95@lineone.net >Cc: caml-list@inria.fr >Subject: Re: [Caml-list] CamlDL/Abstract pointers problem >From: Richard Jones > > >On Thu, Jan 29, 2004 at 01:06:39PM +0000, ronniec95@lineone.net wrote: > All I want to do is just give Ocaml a pointer to something I've created= > in C and pass it back to other C functions later; don't want it to do anything > with it (including mo >ing it around the ocaml heap).\ It's my understanding that you can't just pass a pointer back to OCaml and cast it to a value. OCaml will think that the pointer points to an OCaml heap object, and hence try to examine / move / delete it in the g >rbage collector. Instead you need to do one of two things: either set the bottom bit to 1, in which case OCaml will treat it as a plain integer, or else wrap it up in a box, as in the code below. The Abstract_tag tells the garbage collector not to >look inside the box. static value Val_voidptr (void *ptr) { CAMLparam0 (); CAMLlocal1 (rv); rv =3D alloc (1, Abstract_tag); Field(rv, 0) =3D (value) ptr; CAMLreturn (rv); } #define Voidptr_val(type,rv) ((type *) Field ((rv), 0)) >ou need to call Val_voidptr to wrap up your C void* pointer into an OCaml box, and Voidptr_val to unwrap and get your pointer back again. In any case you need to also add lots of calls to Gc.full_major () to your code, which will trigger an early >ore dump if there is some memory corruption. Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investme= nt If I have not seen as far as others, it is beca >se I have been standing in the footprints of giants. -- from Usenet ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners