caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Samuel Hornus <Samuel.Hornus@inria.fr>
To: O Caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Segfault in C++ stub with many 'new' allocations
Date: Sat, 17 Nov 2012 20:18:05 +0100	[thread overview]
Message-ID: <43A673FD-DC80-4406-8984-A74B181BC825@inria.fr> (raw)
In-Reply-To: <50A7E138.9090601@etorok.net>


On 17 nov. 2012, at 20:10, Török Edwin wrote:

> On 11/17/2012 08:42 PM, Samuel Hornus wrote:
>> 
>> Regarding my first question, if it can help, here is the relevant part of my C++ code:
>> extern "C" value ann_create_bd_tree_flat_ba (value ba, value n, value dim)
>> {
>>    CAMLparam3(ba,n,dim);
>>    ANNbd_tree * ptr = create_bd_tree_flat((ANNcoord*)Caml_ba_data_val(ba), Int_val(n), Int_val(dim));
>>    CAMLreturn ((value)ptr);
> 
> I don't think this is safe. Shouldn't the return value be wrapped in a custom block?
> If the GC tries to interpret this as an OCaml value (which it isn't) it might crash.

Currently, as advised in F. Monier webpage http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php#ref_finalise, I wrap the pointer, in the OCaml code, inside an abstract OCaml type with a finalizer. Could there still be problems with the GC ?
That being said, my crash happens *inside* the C++ constructor, well before the garbage collection may have kicked in. The same code, compiled as a pure C++ program works without problem, even with millions of points.
Is it possible that C++ called from OCaml has a limited memory allocation space?
-- 
Sam

  reply	other threads:[~2012-11-17 19:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-17 18:29 Samuel Hornus
2012-11-17 18:35 ` Kakadu
2012-11-17 18:42   ` Samuel Hornus
2012-11-17 19:10     ` Török Edwin
2012-11-17 19:18       ` Samuel Hornus [this message]
2012-11-17 19:50       ` Markus Mottl
2012-11-17 19:46 ` Markus Mottl
2012-11-17 22:45   ` Samuel Hornus

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=43A673FD-DC80-4406-8984-A74B181BC825@inria.fr \
    --to=samuel.hornus@inria.fr \
    --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).