From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id DAADA7FE44 for ; Mon, 4 Jul 2016 18:04:20 +0200 (CEST) IronPort-PHdr: 9a23:aNeABh0YC+X5YpjusmDT+DRfVm0co7zxezQtwd8ZsegTLPad9pjvdHbS+e9qxAeQG96Ks7Qe0aGH6ujJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL2PbrnD61zMOABK3bVMzfbWtXNSIxJXun8mJuLTrKz1SgzS8Zb4gZD6Xli728vcsvI15N6wqwQHIqHYbM85fxGdvOE7B102kvpT4r9Zf9HFbsvclv9NbXL/hN/AzRLlcSTAnKHwd5cvxtBCFQxHZtVUGVWBDuRpSAhPZ6wn6abdvvSbg/r522DObJtHxVbByWTOv4KpxYAP1zS0KLTo49ifbh5oj3+pgvBu9qkknkMbva4aPOa8mcw== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=christoph.hoeger@tu-berlin.de; spf=None smtp.mailfrom=christoph.hoeger@tu-berlin.de; spf=None smtp.helo=postmaster@mail.tu-berlin.de Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@tu-berlin.de) identity=pra; client-ip=130.149.7.33; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="christoph.hoeger@tu-berlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@tu-berlin.de) identity=mailfrom; client-ip=130.149.7.33; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="christoph.hoeger@tu-berlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail.tu-berlin.de) identity=helo; client-ip=130.149.7.33; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="postmaster@mail.tu-berlin.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DhAACRiHpXhyEHlYJbhD5Suy+HUzsRAQEBAQEBAQERAQEBCgsJCSEvgjKCRA8BewImAl8NBgIBAYgsBJoCj2KPcIEBhx8IiVYLLYJaBZkTgTGWXYVjkAo0gVcBAQgCAUQRC4FObIkMAQEB X-IPAS-Result: A0DhAACRiHpXhyEHlYJbhD5Suy+HUzsRAQEBAQEBAQERAQEBCgsJCSEvgjKCRA8BewImAl8NBgIBAYgsBJoCj2KPcIEBhx8IiVYLLYJaBZkTgTGWXYVjkAo0gVcBAQgCAUQRC4FObIkMAQEB X-IronPort-AV: E=Sophos;i="5.26,575,1459807200"; d="scan'208";a="183748554" Received: from mail.tu-berlin.de ([130.149.7.33]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2016 18:04:20 +0200 X-tubIT-Incoming-IP: 91.66.20.202 Received: from ip5b4214ca.dynamic.kabel-deutschland.de ([91.66.20.202] helo=[192.168.178.42]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-5) with esmtpsa [TLSv1.2:DHE-RSA-AES128-SHA:128] for id 1bK6M6-0004B8-6t; Mon, 04 Jul 2016 18:04:19 +0200 To: caml users From: =?UTF-8?Q?Christoph_H=c3=b6ger?= Organization: =?UTF-8?Q?Technische_Universit=c3=a4t_Berlin?= Message-ID: <03f0318e-3268-da14-d6e9-6efdcfcab567@tu-berlin.de> Date: Mon, 4 Jul 2016 18:04:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.7.4.155416 X-PMX-Spam: Gauge=IIIIIII, Probability=0%, Report='' Subject: [Caml-list] Garbage collector woes 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