caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus.mottl@gmail.com>
To: "Török Edwin" <edwin+ml-ocaml@etorok.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Segfault in C++ stub with many 'new' allocations
Date: Sat, 17 Nov 2012 14:50:56 -0500	[thread overview]
Message-ID: <CAP_800ohy77t5SQ7VLmpWWEkxsq4r_z4DcH+OkGXgTRK64sjdg@mail.gmail.com> (raw)
In-Reply-To: <50A7E138.9090601@etorok.net>

On Sat, Nov 17, 2012 at 2:10 PM, Török Edwin <edwin+ml-ocaml@etorok.net> wrote:
> 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.

The GC will never follow pointers that point outside the OCaml heap.
When done correctly (which requires great care), you can therefore
pass around pointers to C-land.  You'll, of course, then have to
manually deallocate C/C++-heap objects by making the appropriate calls
(free / delete).  Just make sure you never pass around pointers to
memory that has already been deallocated.  Otherwise OCaml might
eventually claim it and cause crashes when following pointers.

Regards,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com

  parent reply	other threads:[~2012-11-17 19:50 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
2012-11-17 19:50       ` Markus Mottl [this message]
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=CAP_800ohy77t5SQ7VLmpWWEkxsq4r_z4DcH+OkGXgTRK64sjdg@mail.gmail.com \
    --to=markus.mottl@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=edwin+ml-ocaml@etorok.net \
    /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).