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 QAA30232; Fri, 30 Jan 2004 16:36:43 +0100 (MET) 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 QAA29916 for ; Fri, 30 Jan 2004 16:36:42 +0100 (MET) 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 i0UFafv24092 for ; Fri, 30 Jan 2004 16:36:41 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id AAA20738; Sat, 31 Jan 2004 00:36:35 +0900 (JST) To: bhurt@spnz.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] CamlDL/Abstract pointers problem In-Reply-To: References: <20040130092031V.garrigue@kurims.kyoto-u.ac.jp> X-Mailer: Mew version 1.94.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040131003639K.garrigue@kurims.kyoto-u.ac.jp> Date: Sat, 31 Jan 2004 00:36:39 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 pointers:01 jacques:01 jacques:01 pointers:01 malloc:01 initialized:01 garbage:01 garbage:01 garrigue:01 garrigue:01 collector:02 objects:02 address:96 pointer:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Brian Hurt > On Fri, 30 Jan 2004, Jacques Garrigue wrote: > > > However, there is another scenario which could cause you problems: > > if for some reason your C pointer get freed, and later the ML heap is > > extended so that it includes the address of the pointer, then you may > > have some pointers left on the ML which will now be seen as ML > > pointers. > > ML doesn't memset memory it just allocated? This may be a problem- I > don't *think* the C standard requires malloc to memset the memory itself, > which means you might be getting garbage memory. That's not the problem: blocks used by ML are always initialized anyway. The trouble is that you may at some point in time pass to your ML program a pointer to some C structure outside of the heap. Since it is outside of the heap, the garbage collector does not attempt to visit it, and this creates no problem. But it may happen (if your structure is freed on the C side), that at some time in the future a new page is added to the heap, containing the location where was the C structure. If your pointer on the ML side is still around, this is now a pointer to somewhere in the heap, and the GC will attempt to visit it. Even if ML was to zero the page before using it, after putting some ML objects in the page, your pointer can easily end up pointing in the middle of some random data. 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