From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 4DCCEBBAF for ; Mon, 15 Feb 2010 21:47:46 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmwHAAtCeUvRVaA0kWdsb2JhbACNf4M6ghOHQggVAQEBAQkLCgcTAyCuO4FMhBeIcgEBAwWEVgSDFA X-IronPort-AV: E=Sophos;i="4.49,479,1262559600"; d="scan'208";a="44855915" Received: from mail-pw0-f52.google.com ([209.85.160.52]) by mail3-smtp-sop.national.inria.fr with ESMTP; 15 Feb 2010 21:47:45 +0100 Received: by pwi10 with SMTP id 10so515620pwi.39 for ; Mon, 15 Feb 2010 12:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=xXvEXUF09ypLc0v/rx0+956mK+m4voUEqvvJgd3JDuo=; b=v+sajxRb7JN6ZkWU7NXSbOxI2KdZ+zcXLV3I9NKOQT+d/l0QCtAA4eE+0LwFFfwUv1 zZUvSISf3EL5PtwWm7oG8VtfL6blOcrfUP56lnNMq8jMdorUJoXKJho6eBtGo32DXYKC EBZoeuCqHVqcO18f9HWsDrorCCPhbmOed38Ls= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=lnyX1zIEF9nayR6RA8Veq0p6t0jf3AcmUXZ272TkR1Xcv4hNItHglY+0QxGPrhjV0Z ZYW80Sjp5mwEpWbahmHDRilZ3YVj0C8JACkMxhPcFxp94CO2vaQYnZ3KjqgAzrmMTUqp 4iN5brfTv4u+eVwM3/0O5CAINISbrUSxUrulQ= MIME-Version: 1.0 Received: by 10.143.21.20 with SMTP id y20mr1836600wfi.102.1266266864086; Mon, 15 Feb 2010 12:47:44 -0800 (PST) Date: Mon, 15 Feb 2010 15:47:44 -0500 Message-ID: Subject: Bigarrays alloc'ed from C not surviving function return From: Eric Hielscher To: caml-list@yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; bigarrays:01 ocaml:01 language's:01 runtime:01 bigarrays:01 camlparam:01 alloc:01 dims:01 alloc:01 bigarray:01 bigarray:01 dims:01 camlreturn:01 camlparam:01 camlreturn:01 Hi all, I'm using the C interface to glue OCaml to another language's runtime (don't ask). For the most part everything seems to be working for me, except I'm getting a strange problem when it comes to bigarrays which I've allocated in C land. Basically, the setup is: value func1(value args) { CAMLparam1(args); CAMLlocal1(ba); // stuff like alloc shape, fill dims array, etc. ba = alloc_bigarray(BIGARRAY_INT32 | BIGARRAY_C_LAYOUT, 1, shape, dims); // other stuff CAMLreturn(ba); } value func2(value args) { CAMLparam1(args); CAMLlocal5(blah); // stuff blah1 = func1(args); // stuff like alloc blah5, etc. Store_field(blah5, 3, blah1); CAMLreturn(blah5); } It appears to me that the bigarray allocation is creating some data on a stack which then gets reclaimed, as I can't access the bigarray anymore in func2 (using Data_bigarray_val(blah1) causes a seg fault). I checked the implementation of caml_ba_alloc to make sure that I wasn't passing in anything which was allocated on the stack of func1 that was getting placed directly into the bigarray struct but that seems to be fine. Any thoughts? -- Eric Hielscher "Het zal me worst wezen." http://ehielscher.org