From: Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Bless me Father, for I have used Obj.magic
Date: Thu, 22 Dec 2011 23:07:37 +0100 [thread overview]
Message-ID: <4EF3AA29.7000800@inria.fr> (raw)
In-Reply-To: <20111222212429.GA8156@yeeloong.happyleptic.org>
[-- Attachment #1: Type: text/plain, Size: 918 bytes --]
On 12/22/2011 10:24 PM, rixed@happyleptic.org wrote:
> I have these types:
>
> type t = { operation : t1 -> t2 ;
> some_fields : of_some_types }
> type t_priv = { t : t ;
> some_other_fields : of_some_other_types }
> Should I fear some backfire?
You might one day forget this [Obj.magic], and access the field [t] that
has not yet been initialized, and get a segfault.
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 .. }
and use it as the initial value for uninitialized values.
let t_priv = { t = dummy_t; ... }
in
let t = make_operations t_priv in
t_priv.t <- t
The good thing is that, since it is uniq in your program, you can test
if t_priv was initialized easily:
if t_priv.t == dummy_t then failwith "t_priv not yet constructed !"
--Fabrice
[-- Attachment #2: fabrice_le_fessant.vcf --]
[-- Type: text/x-vcard, Size: 380 bytes --]
begin:vcard
fn:Fabrice LE FESSANT
n:LE FESSANT;Fabrice
org:INRIA Saclay -- Ile-de-France;P2P & OCaml
adr;quoted-printable:;;Parc Orsay Universit=C3=A9 ;Orsay CEDEX;;91893;France
email;internet:fabrice.le_fessant@inria.fr
title;quoted-printable:Charg=C3=A9 de Recherche
tel;work:+33 1 74 85 42 14
tel;fax:+33 1 74 85 42 49
url:http://fabrice.lefessant.net/
version:2.1
end:vcard
next prev parent reply other threads:[~2011-12-22 22:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-22 21:24 rixed
2011-12-22 22:07 ` Fabrice Le Fessant [this message]
2011-12-22 22:19 ` rixed
2011-12-22 23:29 ` Thierry Martinez
2011-12-23 12:04 ` rixed
2011-12-23 12:26 ` Fabrice Le Fessant
2011-12-30 11:41 ` Damien Doligez
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=4EF3AA29.7000800@inria.fr \
--to=fabrice.le_fessant@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