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 JAA28390; Mon, 13 May 2002 09:21:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 JAA28533 for ; Mon, 13 May 2002 09:20:59 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g4D7Ktr20950 for ; Mon, 13 May 2002 09:20:57 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id QAA13641; Mon, 13 May 2002 16:20:35 +0900 (JST) To: la@iki.fi Cc: caml-list@inria.fr Subject: Re: [Caml-list] NULL as a caml value In-Reply-To: <20020512234522.A5687@kruuna.Helsinki.FI> References: <20020512234522.A5687@kruuna.Helsinki.FI> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020513162035N.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 13 May 2002 16:20:35 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Lauri Alanko > The docs weren't very clear on this, so I just wanted to check: is > (value)NULL a legal caml value? Checking from the sources, it seems that the > GC does leave alone all pointers that don't point to within the caml-managed > heap. However, the docs state that only "memory allocated by malloc" can be > turned directly into an abstract caml value. So may I rely on NULL working? > It would ease dealing with many C interfaces. Yes, NULL is valid, as are all word-aligned addresses outside of the Caml heap. Of course it should be given an abstract type, since there is nothing you can do with it inside Caml. Note however that the statement about "memory allocated by malloc" being safe is to be taken carefully, since people have already reported strange bugs with the following scenario: * allocate a data structure with malloc * get a direct pointer to it in caml * free the structure * expand the caml heap, unfortunately including the free-ed malloc block * your pointer is now seen as a pointer inside the caml-heap, and followed by the GC, directly into a segmentation fault... This is a rather improbable scenario, but better know it in advance. Better to limit direct pointers to structure that are not going to be free-ed, and use boxed ones otherwise. Cheers, Jacques Garrigue ------------------- 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