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 AA5E2BBC4 for ; Mon, 30 Jan 2006 14:12:42 +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 k0UDCg1q028757 for ; Mon, 30 Jan 2006 14:12:42 +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 OAA01179 for ; Mon, 30 Jan 2006 14:12:41 +0100 (MET) Received: from mail.physik.uni-muenchen.de (mail.physik.uni-muenchen.de [192.54.42.129]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0UDCeLO004347 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 30 Jan 2006 14:12:41 +0100 Received: from localhost (unknown [127.0.0.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id BBEC520017; Mon, 30 Jan 2006 14:12:40 +0100 (CET) Received: from mail.physik.uni-muenchen.de ([127.0.0.1]) by localhost (mail.physik.uni-muenchen.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 00941-01-13; Mon, 30 Jan 2006 14:12:40 +0100 (CET) Received: from mailhost.cip.physik.uni-muenchen.de (kaiser.cip.physik.uni-muenchen.de [141.84.136.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id A217C20004; Mon, 30 Jan 2006 14:12:40 +0100 (CET) Received: from aso.cip.physik.uni-muenchen.de (eiger.cip.physik.uni-muenchen.de [141.84.136.54]) by mailhost.cip.physik.uni-muenchen.de (Postfix) with ESMTP id E84D926E89; Mon, 30 Jan 2006 14:12:39 +0100 (CET) Received: by aso.cip.physik.uni-muenchen.de (Postfix, from userid 3092) id C4CD6783F3; Mon, 30 Jan 2006 14:12:39 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by aso.cip.physik.uni-muenchen.de (Postfix) with ESMTP id A569F80432; Mon, 30 Jan 2006 14:12:39 +0100 (CET) Date: Mon, 30 Jan 2006 14:12:39 +0100 (CET) From: Thomas Fischbacher To: Damien Doligez Cc: caml users Subject: On Store_field() In-Reply-To: <02FDC6F0-122C-42BA-A2F4-15E2B08248C8@inria.fr> Message-ID: References: <20060119.093955.97297811.garrigue@math.nagoya-u.ac.jp> <1137640656.8943.183.camel@rosella> <02FDC6F0-122C-42BA-A2F4-15E2B08248C8@inria.fr> X-BOFH: Daemons did it MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: amavisd-new at physik.uni-muenchen.de X-Miltered: at concorde with ID 43DE10CA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43DE10C9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; damien:01 val:01 ocaml:01 lacks:01 pointers:01 alloc:01 alloc:01 pointer:01 behaves:01 trivial:01 patching:01 debugging:01 ocaml:01 rebuilding:01 cip:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Thu, 19 Jan 2006, Damien Doligez wrote: > >However I strongly recommend instead > > > > StoreField(v,n,(value)(void*)p); > > This is the only way. Always use Store_field, Store_double_field, > and Store_double_val. What you *actually* forgot to tell people is that OCaml unfortunately lacks a macro with which one can store C pointers to alloc_final allocated blocks. If one writes to those using e.g. ml_vector = alloc_final(2, finalize_vector, 1, 10); Store_field(ml_vector, 1,(value)vector); with vector being a C pointer to a structure, this may or may not lead to random crashes at very unexpected places - because (as I think now) the Store_field macro will be over-eager trying to tell the GC about the value stored - which it should just ignore in this particular case! Indeed, this has been discussed before, I think: http://groups.google.de/group/fa.caml/msg/60ace9405fcf60c0?dmode=source&hl=de So, I would strongly suggest introducing a macro that behaves like this: #define Store_c_field(block,offset,x) (Field(block,offset)=(value)x) so that one could then use Store_c_field(ml_vector, 1,vector); I actually just spent a full week tracking down precisely this issue in a not particularly trivial C library interface I am building right now. After looking in the weirdest places, ensuring it's not an issue with the library wrapped, or the trickier pieces of my own code, I even started patching debugging code into the OCaml bytecode's GC and rebuilding... So, *please* do the world a great favour and tell people about that issue in the C interface documentation! -- Thomas Fischbacher tf@cip.physik.uni-muenchen.de (Yes, grumpy. Did not sleep over the weekend due to this issue...)