From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 194E17EE20 for ; Sat, 17 Nov 2012 20:50:57 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of markus.mottl@gmail.com) identity=pra; client-ip=74.125.82.52; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="markus.mottl@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of markus.mottl@gmail.com designates 74.125.82.52 as permitted sender) identity=mailfrom; client-ip=74.125.82.52; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="markus.mottl@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f52.google.com) identity=helo; client-ip=74.125.82.52; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="postmaster@mail-wg0-f52.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AswCAA/qp1BKfVI0jWdsb2JhbABFhVkBvUsIIwEBAQEJCQsJEgYjgh4BAQUMNAEUBx0BAwwGBQsNLiEBAREBBQEcBhOHegEDD6EJjDOCeIQmChknDVmIdQEFDIs/aYUNA4hai02BVYsygzAWKYQv X-IronPort-AV: E=Sophos;i="4.83,270,1352070000"; d="scan'208";a="181980208" Received: from mail-wg0-f52.google.com ([74.125.82.52]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Nov 2012 20:50:56 +0100 Received: by mail-wg0-f52.google.com with SMTP id fg15so1940014wgb.9 for ; Sat, 17 Nov 2012 11:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=639Ki46UyCndSaaIE/VC8iqfLLcF+dwLt0cLaVqp9J0=; b=jFM+WpowWC13Q9D4HB2k65/d9KqUiZXIrRcNSXQc56QaqFKRkhnFbNLSLNRKKnnewR WILZ/11uO31CjVdCTQ7NmRS/dvE2TE6WsSC+hlTHk3MKyZLWTMDo15HjBWOYY5XWKwml Z9gaLagM+d7+DUvBFmBD05Kwli/SEPYMNvrpdT3G6POGTUL1wTaZ0ER57AJh+2wUFUZT iI5AVUV9cmZwxUif/I7X7CWySWjNiXw8bzpe/QSVdyPp5IW4m5MqSoGa4/oj/cFSU52c 2iod2lyU8uWdpA2BOabJj6GX4lGd+pqPu8nVMljQpqUIANmtaeOeCjjYwHEFslPaIqW4 eZfw== MIME-Version: 1.0 Received: by 10.216.139.201 with SMTP id c51mr2779488wej.206.1353181856673; Sat, 17 Nov 2012 11:50:56 -0800 (PST) Received: by 10.180.165.143 with HTTP; Sat, 17 Nov 2012 11:50:56 -0800 (PST) In-Reply-To: <50A7E138.9090601@etorok.net> References: <70435661-3754-4815-9EEF-B52F33D29B5F@inria.fr> <0BEF3A04-3297-4084-BE4D-13ACCC4D431E@inria.fr> <50A7E138.9090601@etorok.net> Date: Sat, 17 Nov 2012 14:50:56 -0500 Message-ID: From: Markus Mottl To: =?ISO-8859-1?Q?T=F6r=F6k_Edwin?= Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Segfault in C++ stub with many 'new' allocations On Sat, Nov 17, 2012 at 2:10 PM, T=F6r=F6k Edwin wrote: > I don't think this is safe. Shouldn't the return value be wrapped in a cu= stom block? > If the GC tries to interpret this as an OCaml value (which it isn't) it m= ight 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 --=20 Markus Mottl http://www.ocaml.info markus.mottl@gmail.com