From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,MAILTO_TO_SPAM_ADDR, MSGID_MULTIPLE_AT autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 90037BC37 for ; Sat, 8 Aug 2009 16:15:59 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcCAAYlfUrLOwGUkWdsb2JhbACaSgEBAQEJCwoHEwSgXZIahBcFgic X-IronPort-AV: E=Sophos;i="4.43,346,1246831200"; d="scan'208";a="44471535" Received: from outbound.icp-qv1-irony-out3.iinet.net.au ([203.59.1.148]) by mail4-smtp-sop.national.inria.fr with ESMTP; 08 Aug 2009 16:15:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAH4lfUp8qHif/2dsb2JhbAC7WpIahBcFgic X-IronPort-AV: E=Sophos;i="4.43,346,1246809600"; d="scan'208";a="488885852" Received: from unknown (HELO ivanz27oq2f1va) ([124.168.120.159]) by outbound.icp-qv1-irony-out3.iinet.net.au with ESMTP; 08 Aug 2009 22:15:54 +0800 From: "ivan chollet" To: "'Edgar Friendly'" Cc: References: <000301ca1809$1658efa0$430acee0$@chollet@free.fr> <4A7D7DAF.6070904@gmail.com> In-Reply-To: <4A7D7DAF.6070904@gmail.com> Subject: RE: [Caml-list] ocaml sefault in bytecode: unanswered questions Date: Sat, 8 Aug 2009 16:15:44 +0200 Message-ID: <000001ca1832$b950eb80$2bf2c280$@chollet@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcoYLD6E7DEbUqiuTKCjRYldBZJ7vwABfrEg Content-Language: fr X-Spam: no; 0.00; ocaml:01 bytecode:01 iter:01 myfun:01 semantically:01 iter:01 myfun:01 semantically:01 ocaml:01 bytecode:01 segfault:01 runtime:01 pointers:01 notation:01 pointers:01 Yes, makes sense. But it would mean that "List.iter myfun !myref" is not = semantically equivalent to "List.iter myfun (let l=3D!myref in l)", = therefore the expressions "let l=3D!myref in l" and "!myref" are not = semantically equivalent. That would be very strange! -----Original Message----- From: Edgar Friendly [mailto:thelema314@gmail.com]=20 Sent: samedi 8 ao=C3=BBt 2009 15:29 To: ivan chollet Cc: 'Cedric Auger'; caml-list@yquem.inria.fr Subject: Re: [Caml-list] ocaml sefault in bytecode: unanswered questions ivan chollet wrote: > You basically state that stuff like =E2=80=9Clet l =3D !myref in = List.iter myfun l=E2=80=9D > (where myfun modifies !myref) wouldn't produce segfault.=20 > Why? It would mean that doing "let l =3D !myref" creates a brand new = OCaml > entity, l, ie a brand new allocation on the heap, and then, messing = around > with !myref inside myfun would be of course 100% safe. Is that what = OCaml > runtime does? when you have [myref : list ref =3D ref [1;2]], this is in memory as: myref -> {contents: _a} _a -> (1,_b) _b -> (2,0) I've given names to the intermediate pointers -- the notation above shows names as pointers to data structures. [myref] is a pointer to a record, whose contents point to the head of the list [1;2]. So there's already two levels of indirection. When you do [let l =3D !myref], [l] gets assigned [_a], so it points to the head of the list. List.iter traverses the list not even knowing that [myref] exists, so if the function [myfun] modifies [myref], it won't affect List.iter. Does this make sense? E