From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 915D7BBAF for ; Wed, 2 Jun 2010 18:39:00 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.53,348,1272837600"; d="scan'208";a="51647192" Received: from peermanence.saclay.inria.fr (HELO [195.83.212.205]) ([195.83.212.205]) by mail3-relais-sop.national.inria.fr with ESMTP; 02 Jun 2010 18:39:00 +0200 Message-ID: <4C06897D.3010008@inria.fr> Date: Wed, 02 Jun 2010 18:40:29 +0200 From: Fabrice Le Fessant User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Mathias Kende Cc: caml-list@inria.fr Subject: Re: [Caml-list] Difference between ocamlc and ocamlopt when marshalling reference References: <1275480999.5099.19.camel@bohrium.pps.jussieu.fr> In-Reply-To: <1275480999.5099.19.camel@bohrium.pps.jussieu.fr> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; ocamlc:01 ocamlopt:01 marshalling:01 bytecode:01 pointer:01 bytecode:01 marshalling:01 ocamlc:01 ocamlopt:01 printf:01 printf:01 cheers:01 beginner's:01 ocaml:01 bug:01 Hi, The main difference is that "p" is a closure in bytecode, but just a pointer in native code: in bytecode, "p" references "r", and so a closure is needed; in native code, the reference to "r" in "p" is a direct access to the module structure, and so "p" does not need to keep a reference to "r". So, when you marshal "p" in bytecode, you follow the closure and the reference, that are stored in "s", and they are duplicated when "s" is unmarshalled. I think Marshal.Closures is only expected for hacking anyway, so you should not really assume anything on its behavior ;-) --Fabrice Mathias Kende wrote, On 06/02/2010 02:16 PM: > Hi, > > I found a difference on the way global references used inside a function > are handled with respect to marshalling between ocamlc and ocamlopt. > > See the exemple below : > > -------------- a.ml --------------- > let r = ref 0 > let p () = Printf.printf "%d\n" !r > let s = Marshal.to_string p [Marshal.Closures] > let () = r := 1 > let q : unit -> unit = Marshal.from_string s 0 > let () = q () > ----------------------------------- > $ ocamlc a.ml > $ ./a.out > 0 > $ ocamlopt a.ml > $ ./a.out > 1 > ----------------------------------- > > I am not sure which semantic is the "good" one. They are both > interesting, but having only one is definitely simpler. > > Is this a known problem ? is there fundamental reasons in the compilers > for which it can not be changed ? > > Cheers, > > Mathias > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Fabrice LE FESSANT Chercheur, Equipe ASAP (As Scalable As Possible) http://www.lefessant.net/ INRIA-Futurs, Bat P - 112 Parc Orsay Université 2-4, rue Jacques Monod F-91893 Orsay Cedex, FRANCE