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 TAA12734; Tue, 18 May 2004 19:22:02 +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 TAA12714 for ; Tue, 18 May 2004 19:22:01 +0200 (MET DST) Received: from us17.unix.fas.harvard.edu (us17.unix.fas.harvard.edu [140.247.35.197]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4IHM0EV011837 for ; Tue, 18 May 2004 19:22:00 +0200 Received: from [140.247.133.39] (roam133-39.student.harvard.edu [140.247.133.39]) by us17.unix.fas.harvard.edu (8.12.11/8.12.11) with ESMTP id i4IHLxlj004724 for ; Tue, 18 May 2004 13:21:59 -0400 Mime-Version: 1.0 (Apple Message framework v613) In-Reply-To: <20040518121147.GA20094@redhat.com> References: <1084869517.19838.409.camel@pelican.wigram> <20040518090635.GA6918@bourg.inria.fr> <1084875941.19838.446.camel@pelican.wigram> <20040518121147.GA20094@redhat.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Michael Hamburg Subject: Re: [Caml-list] Automatic wrapper generator Date: Tue, 18 May 2004 13:21:54 -0400 To: caml-list X-Mailer: Apple Mail (2.613) X-Miltered: at nez-perce with ID 40AA4638.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 hvs:99 avs:99 high-level:01 wrappers:01 behave:01 deallocate:01 perl's:01 interfacing:01 finalization:01 segfault:01 low-level:01 high-level:01 crm:99 consultancy:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > It sounds very similar to Perl4caml, which offers two levels of > interface. At the lowest level you get to manipulate SVs, HVs and AVs > directly from OCaml [1]. You have to convert strings/ints to SVs when > calling Perl code (using sv_of_string, etc.), and when returning > values you have to convert them from SVs to OCaml native types (using > string_of_sv, etc.). For some libraries I've written high-level > wrappers which do all this conversion for you, allowing you to use > objects and modules which look just like OCaml native objects [2]. > > Perl uses reference counting. I still haven't worked out a scheme to > make reference counting behave well with the OCaml garbage collector, > so the current version of Perl4caml will never deallocate Perl objects > (there is an experimental makefile flag to turn deallocation on, but > this sometimes causes programs to crash). I've tried wrapping the > Perl objects in custom blocks, but it doesn't work, and I'd appreciate > some help sorting it out! I don't know how Perl's reference-counting scheme works, but I'm working on interfacing O'Caml with Cocoa, which also uses ref-counts. I've basically made O'Caml incref any object allocated on its heap, and decref it as a finalization step. Conversely, O'Caml objects in C get added to the global roots. I still have to do more testing, but it seems that this doesn't crash, nor does it leak much memory. I say much because such a scheme cannot detect loops. I think you'd have to mod the garbage collector to do so. As of now, there's also no way to safely break a known loop, since decrefing an object may cause it to go away before O'Caml can finalize it, which would cause a segfault. An interface change to the Cocoa wrapper of O'Caml objects might fix this. Mike > Rich. > > [1] The low-level interface: > http://www.merjis.com/developers/perl4caml/html/Perl.html > > [2] Example of a high-level wrapper: > http://www.merjis.com/developers/perl4caml/html/Pl_HTML_Element.html > http://www.merjis.com/developers/perl4caml/html/ > Pl_HTML_Element.html_element.html > > -- > Richard Jones. http://www.annexia.org/ http://www.j-london.com/ > Merjis Ltd. http://www.merjis.com/ - improving website return on > investment > http://www.winwinsales.co.uk/ - CRM improvement consultancy ------------------- 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