From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pBMMMNTp009661 for ; Thu, 22 Dec 2011 23:22:23 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUBAOas807UGyoFk2dsb2JhbABDrDAiAQEBAQkJCwkUAyKBcgEBBAEnE0QLC0YUiFYCtzaIdYI3YwSVAIVfjFU X-IronPort-AV: E=Sophos;i="4.71,395,1320620400"; d="scan'208";a="124377815" Received: from smtp5-g21.free.fr ([212.27.42.5]) by mail4-smtp-sop.national.inria.fr with ESMTP; 22 Dec 2011 23:22:17 +0100 Received: from yeeloong (unknown [82.67.194.89]) by smtp5-g21.free.fr (Postfix) with SMTP id C9157D48471 for ; Thu, 22 Dec 2011 23:22:09 +0100 (CET) Received: by yeeloong (sSMTP sendmail emulation); Thu, 22 Dec 2011 23:19:59 +0100 Date: Thu, 22 Dec 2011 23:19:59 +0100 From: rixed@happyleptic.org To: caml-list@inria.fr Message-ID: <20111222221958.GD8156@yeeloong.happyleptic.org> References: <20111222212429.GA8156@yeeloong.happyleptic.org> <4EF3AA29.7000800@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4EF3AA29.7000800@inria.fr> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] Bless me Father, for I have used Obj.magic -[ Thu, Dec 22, 2011 at 11:07:37PM +0100, Fabrice Le Fessant ]---- > You might one day forget this [Obj.magic], and access the field [t] that > has not yet been initialized, and get a segfault. As the only place where this 0 value exists is in the constructor and it can easily be shown that the function never returns a semi-initialized t, then this looks quite unprobable here. But I welcome the warning nonetheless :-) > My advise would be to first create a dummy [t] record: > > let dummy_t = { operation = (fun _ -> failwith "t not initialized"); > some_fields = ... some dummy initializer .. } Yes, this was my initial intention as well. Unfortunately, my actual types are much more complex than what's shown in the example; especially a value of type t2 is quite hairy to construct and there are lots of operations having lots of complex output types (records of records of functions of records...) That's why I had this TODO note in the margin commanding to "build a dummy t to get rid of the option type" for so long, until I had this terrible idea of using Obj.magic.