caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Garbage collector woes
Date: Mon, 4 Jul 2016 18:04:17 +0200	[thread overview]
Message-ID: <03f0318e-3268-da14-d6e9-6efdcfcab567@tu-berlin.de> (raw)

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

             reply	other threads:[~2016-07-04 16:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-04 16:04 Christoph Höger [this message]
2016-07-04 16:21 ` Jeremy Yallop
2016-07-04 17:06   ` Christoph Höger
2016-07-04 17:44     ` Jeremy Yallop

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=03f0318e-3268-da14-d6e9-6efdcfcab567@tu-berlin.de \
    --to=christoph.hoeger@tu-berlin.de \
    --cc=caml-list@inria.fr \
    /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).