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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 443F97FFB5 for ; Fri, 11 Mar 2016 16:05:27 +0100 (CET) IronPort-PHdr: 9a23:Zx25JR3Hhb6pE6XXsmDT+DRfVm0co7zxezQtwd8ZsegSKvad9pjvdHbS+e9qxAeQG96LtLQU2qGI4ujJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6NyZTmnL7js7ToICx2xxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP5Xz247bXianhL7+9vitMU7q3cY6Lod8JtLWKD+OqA5VqBwDTI8Mmlz6te4mwPESF6h/HIa3WIXiS1iBALC8FmuUI34tCD9t/E70i6QOtHeRr09Hzq4ufQ4ACT0gTsKYmZquFrcjdZ92fpW Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=francois.bobot@cea.fr; spf=None smtp.mailfrom=francois.bobot@cea.fr; spf=None smtp.helo=postmaster@sainfoin-out.extra.cea.fr Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of francois.bobot@cea.fr) identity=pra; client-ip=132.167.192.145; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="francois.bobot@cea.fr"; x-sender="francois.bobot@cea.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of francois.bobot@cea.fr) identity=mailfrom; client-ip=132.167.192.145; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="francois.bobot@cea.fr"; x-sender="francois.bobot@cea.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@sainfoin-out.extra.cea.fr) identity=helo; client-ip=132.167.192.145; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="francois.bobot@cea.fr"; x-sender="postmaster@sainfoin-out.extra.cea.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CiAQBy3eJWk5HAp4REGoQQbQG8JCGFbAKBLzwQAQEBAQEBAQEQAQEBAQcNCQkhL4ItghQBAQEDATIBBUARCxgJFg8JAwIBAgFFEwgCiBgIDiy8aB6JXH6EKBBOg24Fl0OFbYlzS4cAI4UwhzOHPjeCLhEIgUlpAYpQAQEB X-IPAS-Result: A0CiAQBy3eJWk5HAp4REGoQQbQG8JCGFbAKBLzwQAQEBAQEBAQEQAQEBAQcNCQkhL4ItghQBAQEDATIBBUARCxgJFg8JAwIBAgFFEwgCiBgIDiy8aB6JXH6EKBBOg24Fl0OFbYlzS4cAI4UwhzOHPjeCLhEIgUlpAYpQAQEB X-IronPort-AV: E=Sophos;i="5.24,320,1454972400"; d="scan'208";a="207248889" Received: from sainfoin-out.extra.cea.fr ([132.167.192.145]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Mar 2016 16:05:26 +0100 Received: from pisaure.intra.cea.fr (pisaure.intra.cea.fr [132.166.88.21]) by sainfoin.extra.cea.fr (8.15.2/8.15.2/CEAnet-Internet-out-2.4) with ESMTP id u2BF5Qnn001249 for ; Fri, 11 Mar 2016 16:05:26 +0100 Received: from pisaure.intra.cea.fr (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id B9378205C2D for ; Fri, 11 Mar 2016 16:05:57 +0100 (CET) Received: from muguet2.intra.cea.fr (muguet2.intra.cea.fr [132.166.192.7]) by pisaure.intra.cea.fr (Postfix) with ESMTP id B0F33200B5C for ; Fri, 11 Mar 2016 16:05:57 +0100 (CET) Received: from [10.8.32.80] (is222783.intra.cea.fr [10.8.32.80]) by muguet2.intra.cea.fr (8.15.2/8.15.2/CEAnet-Intranet-out-1.4) with ESMTP id u2BF5PU9027126 for ; Fri, 11 Mar 2016 16:05:26 +0100 To: caml-list@inria.fr References: <20160308154948.GA5919@frosties> <20160308190415.GA10232@frosties> From: =?UTF-8?Q?Fran=c3=a7ois_Bobot?= Message-ID: <56E2DEB5.8020304@cea.fr> Date: Fri, 11 Mar 2016 16:05:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:44.0) Gecko/20100101 Icedove/44.0 MIME-Version: 1.0 In-Reply-To: <20160308190415.GA10232@frosties> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] memory corruption with Weak.t in Gc.finalise On 08/03/2016 20:04, Goswin von Brederlow wrote: > On Tue, Mar 08, 2016 at 11:00:33AM -0500, Gabriel Scherer wrote: >> It's great that you have a minimal reproduction example. Could you >> create an issue on the issue tracker? >> http://caml.inria.fr/mantis/ >> >> Issues on the bugtracker are easier to keep track of than mails on the >> caml-list. > > If it is a bug in the compiler and not just my code then sure. > Perhaps a bug in your code, I haven't ran your code; just read it. >>> >>> class obj = object(self) >>> val weak = Weak.create 1 >>> initializer Weak.set weak 0 (Some self) >>> initializer setup weak >>> initializer Gc.finalise cleanup self >>> end >>> >>> let () = >>> Printf.printf "Creating object\n%!"; >>> ignore (new obj); >>> test () >>> >>> void test(void) { >>> CAMLparam0(); >>> CAMLlocal1(obj); >>> printf("%s\n", __PRETTY_FUNCTION__); >>> printf(" weak = 0x%lx\n", weak); >>> if (weak != 0) { >>> obj = Field(weak, 1); >>> printf(" obj = 0x%lx\n", obj); >>> if (obj != 0) { >>> printf(" tag = %d\n", Tag_val(obj)); >>> } If the weak pointer is unset, obj is not equal to 0 but to caml_weak_none (in 4.03/trunk caml_ephe_none). And I think you are in this case since `(new obj)` can be immediately garbage collected. caml_ephe_none should not be dereferenced: ``` static value ephe_dummy = 0; value caml_ephe_none = (value) &ephe_dummy; ``` Thank you for your mantis ticket http://caml.inria.fr/mantis/view.php?id=7173 that asks for a C API for weak pointers/ephemerons. Best, -- François