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 IAA16617; Mon, 9 Jul 2001 08:59:20 +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 IAA16619 for ; Mon, 9 Jul 2001 08:59:19 +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.10.0) with ESMTP id f696xHL29316 for ; Mon, 9 Jul 2001 08:59:18 +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 PAA22296; Mon, 9 Jul 2001 15:59:00 +0900 (JST) To: avv@quasar.ipa.nw.ru Cc: caml-list@inria.fr Subject: Re: [Caml-list] GC and interoperability with C In-Reply-To: <3B493A40.1B2985FE@quasar.ipa.nw.ru> References: <3B493A40.1B2985FE@quasar.ipa.nw.ru> 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: <20010709155900C.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 09 Jul 2001 15:59:00 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > From what I see in the documentation, I see no way to 'lock' an OCaml > value on the heap so that it can be safely accessed from C code, and > then 'unlock' it, say, in the finalization function of some > Custom_block. In contrast to Python, e.g., where you just increment and > decrement the reference count. Yes, Python uses (used?) reference counting. More clever (and faster) GC's, like that of caml, have to move things around. > If this is right, the interaction of OCaml to C becomes one-way, you > cannot safely access OCaml world from arbitrary C code. Yes, you can. You just have to register a pointer with the GC, and everytime the target is moved around, the pointer will be updated. See void register_global_root (value *); void remove_global_root (value *); in memory.h. After that, you must be careful of always accessing values through the pointer, not directly. Jacques Garrigue ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr