caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Garbage collector woes
@ 2016-07-04 16:04 Christoph Höger
  2016-07-04 16:21 ` Jeremy Yallop
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Höger @ 2016-07-04 16:04 UTC (permalink / raw)
  To: caml users

Dear all,

I have a program using OCaml callbacks, one of these callbacks looks is
the following:

/* Callbacks */
CAMLprim iconv(void* user_data, double t, double const *x, double *cond) {
  CAMLparam0();
  CAMLlocal3(ml_t, ml_x, ml_cond);
  const value desc = *((value*)user_data);

  /* Wrap the values in fresh big arrays */
  ml_t = caml_copy_double(t);
  ml_x = caml_ba_alloc_dims(CAML_BA_FLOAT64 | CAML_BA_C_LAYOUT, 1,
(double*)x, Int_val(N(desc)));
  ml_cond = caml_ba_alloc_dims(CAML_BA_FLOAT64 | CAML_BA_C_LAYOUT, 1,
cond, Int_val(MFIT(desc)));

  /* call the OCaml callback */
  caml_callback3(ICONV(desc), ml_t, ml_x, ml_cond);
  CAMLreturn0;
}

all arguments are allocated directly in C-code, user-data is a
registered global root. I am running 4.02.3 .

However at some point in my example, the x and cond arguments are
overwritten on the stack, resulting in a segmentation fault in the ocaml
callback.

Is it possible that the GC overwrites values in this stackframe, even
though the function is announced via CAMLparam0 ? How do I write
C-functions that call back into OCaml then?

thanks alot,

Christoph
-- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-04 17:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04 16:04 [Caml-list] Garbage collector woes Christoph Höger
2016-07-04 16:21 ` Jeremy Yallop
2016-07-04 17:06   ` Christoph Höger
2016-07-04 17:44     ` Jeremy Yallop

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).