Browse thread
Bigarrays alloc'ed from C not surviving function return
- Eric Hielscher
[
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: | 2010-02-15 (20:47) |
From: | Eric Hielscher <hielscher@g...> |
Subject: | Bigarrays alloc'ed from C not surviving function return |
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