caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Joerg Czeranski <jc@joerch.org>
To: malc@pulsesoft.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Troubles with C->Caml
Date: Mon, 5 Nov 2001 18:56:56 +0100 (CET)	[thread overview]
Message-ID: <200111051756.SAA24522@kiste.thiemo.net> (raw)
In-Reply-To: <Pine.LNX.4.21.0110211611550.477-100000@oyster>

On Sun, 21 Oct 2001 16:27:08 +0400 (MSD) malc <malc@pulsesoft.com> wrote:
>
> 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.

Hi,

I don't remember whether somebody has answered this,
but I think you should never copy an O'Caml pointer into a
variable that's not in CAMLlocal...(), e.g.
"char *p = String_val (param);" copies the pointer param into
the local variable p.  When the GC moves param, p points to
garbage.  (Same for h.)

On the other hand you can't declare p with CAMLparam..., so
you probably have to write "String_val (param)" wherever you'd
use p.

I'm not sure whether the documentation mentions this, and
I think it's not completely obvious.

regards,
jörch
-------------------
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


      parent reply	other threads:[~2001-11-05 17:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-20 23:36 malc
2001-10-21  3:23 ` Daniel de Rauglaudre
2001-10-21 12:27   ` malc
2001-10-21 13:10     ` Dmitry Bely
2001-11-05 17:56     ` Joerg Czeranski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200111051756.SAA24522@kiste.thiemo.net \
    --to=jc@joerch.org \
    --cc=caml-list@inria.fr \
    --cc=malc@pulsesoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).