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 KAA19771; Thu, 26 Jul 2001 10:46:45 +0200 (MET DST) 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 KAA19767 for ; Thu, 26 Jul 2001 10:46:44 +0200 (MET DST) Received: from pltn13.pbi.net (mta7.pltn13.pbi.net [64.164.98.8]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6Q8khv16857 for ; Thu, 26 Jul 2001 10:46:43 +0200 (MET DST) Received: from checkerlap.d6.com ([64.163.214.244]) by mta7.pltn13.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0GH2005B7ODT6D@mta7.pltn13.pbi.net> for caml-list@inria.fr; Thu, 26 Jul 2001 01:46:42 -0700 (PDT) Date: Thu, 26 Jul 2001 01:48:24 -0700 From: Chris Hecker Subject: [Caml-list] register_global_root, malloc, etc. X-Sender: def6@shell16.ba.best.com To: caml-list@inria.fr Message-id: <4.3.2.7.2.20010726013540.027fa990@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Say I've got the following C struct: struct foo { int something; value callback; }; If I'm writing a module in C and want to have an abstract type that corresponds to that struct (allocated with new/malloc/etc. from C), is the following code correct? CAMLlocal1(result); foo *p = new foo; p->callback = Val_unit; register_global_root(&(p->callback)); result = alloc_small(1,Abstract_tag); Field(result,0) = (value)p; CAMLreturn(result); Then, later, I can just assign another closure passed to a C function (and CAMLparam'ed) to p->callback without worrying about it, like this: value set_callback( value fooval, value callback ) { CAMLparam2(fooval,callback); foo *p = (foo *)Field(fooval,0); p->callback = callback; CAMLreturn(Val_unit); } Is that correct? Should I use Custom_tag and register all the finalization functions and whatnot for my abstract type, or is Abstract_tag good enough assuming I've got a free_foo function that users of the module are supposed to call to deallocate the abstract type? free_foo should call remove_global_root before deleting the memory, right? But I don't need to do anything to explicitly delete the callback or the Abstract_tag block that was passed in since the GC will handle it? Thanks, Chris ------------------- 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