Browse thread
[Caml-list] Troubles with C->Caml
-
malc
-
Daniel de Rauglaudre
-
malc
- Joerg Czeranski
- Dmitry Bely
-
malc
-
Daniel de Rauglaudre
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Joerg Czeranski <jc@j...> |
| Subject: | Re: [Caml-list] Troubles with C->Caml |
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