caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Bigarrays alloc'ed from C not surviving function return
@ 2010-02-15 20:47 Eric Hielscher
  0 siblings, 0 replies; only message in thread
From: Eric Hielscher @ 2010-02-15 20:47 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-02-15 20:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-15 20:47 Bigarrays alloc'ed from C not surviving function return Eric Hielscher

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