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 OAA19779; Sun, 21 Oct 2001 14:25:46 +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 OAA19908 for ; Sun, 21 Oct 2001 14:25:45 +0200 (MET DST) Received: from comtv.ru (mail.comtv.ru [217.10.32.3]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f9LCPhn02761; Sun, 21 Oct 2001 14:25:43 +0200 (MET DST) Received: from [10.2.64.72] (HELO oyster2) by comtv.ru (CommuniGate Pro SMTP 3.4.7) with ESMTP id 979319; Sun, 21 Oct 2001 16:25:36 +0400 Date: Sun, 21 Oct 2001 16:27:08 +0400 (MSD) From: malc X-Sender: malc@oyster To: Daniel de Rauglaudre cc: caml-list@inria.fr Subject: Re: [Caml-list] Troubles with C->Caml In-Reply-To: <20011021052337.A1404@verdot.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 21 Oct 2001, Daniel de Rauglaudre wrote: > Hi, > > On Sun, Oct 21, 2001 at 03:36:04AM +0400, malc wrote: > > > result = alloc_small (1, 2); > > Field (result, 0) = ; > > Field (result, 1) = Extract_exception (res); > > FAQ. When calling allocating functions, the GC may move the values of > the heap. The variable "res", of type "value", is actually a pointer > to the heap. After the call to "alloc_small", its pointed value may > have been moved by the GC, but "res" still points to the old area. Well, the real code contains all the necessary CAMLxxx decorations, and yet it still coredumps. And belive me, i read everything i could find on the subject before posting the question. Furthermore i found that C code in OCaml distribution is very inconsistent w.r.t CAMLxxx macros, and its hard to draw any conclusions from there. > > The OCaml documentation explains you this point. You have to add > specific code in the beginning and at the end of your function to tell > the GC that you are using some variables of type "value". The functions > to call have names CAMLparam, CAMLlocal, CAMLreturn, things like that, > defined in "caml/memory.h". > > Read the documentation carefully because if you don't program it > correctly, you can get memory fault at any time later. value func (value param) { CAMLparam1 (param); CAMLlocal2 (result, err); char *p = String_val (param); void *h = af (p); err = yaf (); if (some_condition) { /* raise exception */ ... } else { if (Is_exception_result (err)) { result = alloc_small (2, 1); Field (result, 0) = (value)h; Field (result, 1) = Extract_exception (err); CAMLreturn (result); } result = alloc_small (1, 0); Field (result, 0) = (value)h; CAMLreturn (result); } } The decorations are there ditto coredump. -- mailto:malc@pulsesoft.com ------------------- 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