caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Marshal.to_string and mutable values
@ 2005-09-15 14:45 Frédéric Gava
  2005-09-15 15:13 ` [Caml-list] " Ingo Bormuth
  0 siblings, 1 reply; 5+ messages in thread
From: Frédéric Gava @ 2005-09-15 14:45 UTC (permalink / raw)
  To: caml-list

Hi all,

A personnal parallel application crash (but works before) and I am
very surprised to find that the pb is in Marshal.to_string. Take for
example:

let a = ref 0;;

(* no pb *)
Marshal.to_string a [Marshal.Closures];;
-: string = "..."

(* minor pb *)
Marshal.to_string (fun _ -> a) [Marshal.Closures];;
Exception: Invalid_argument "output_value: abstract value (outside heap)"
????
I do not use an abstract value here. But ok, there is peraps side effects
after the serialization of the function.

(* less minor pb *)
let f () =
 let b = ref 0 in b:=!b+1; 1 ;;

Marshal.to_string f [Marshal.Closures];;
Exception: Invalid_argument "output_value: abstract value (outside heap)"
????
I can save this function (with its closure). The reference is completely
local. For my purpose, a processor could not send to another processor a
function wich used some imperative features (for best complexity). That is
so bad...

Those examples comes from "Development of applications with OCaml" by
Chailloux and al. And they suppose to works... and in latest versions of
ocaml, they worked.

Anybody have an idea ? I suppose it is not a bug but I do not know why it is
a pb.

Frédéric Gava



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Marshal.to_string and mutable values
  2005-09-15 14:45 Marshal.to_string and mutable values Frédéric Gava
@ 2005-09-15 15:13 ` Ingo Bormuth
  2005-09-15 15:49   ` Frédéric Gava
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Bormuth @ 2005-09-15 15:13 UTC (permalink / raw)
  To: caml-list; +Cc: ingo

On 2005-09-15 16:45, Frédéric Gava wrote:
> 
> Anybody have an idea ? I suppose it is not a bug but I do not know why it is
> a pb.
>

As far as I unserstand, those things are working in compiled programms only,
but not in the toplevel.

The manual says:

  /---
  | If flags contains Marshal.Closures, functional values will be marshaled as a
  | position in the code of the program. In this case, the output of marshaling
  | can only be read back in processes that run exactly the same program, with
  | exactly the same compiled code. (This is checked at un-marshaling time, using
  | an MD5 digest of the code transmitted along with the code position.)
  \--
  
This cannot be done in toplevel.

-- 
   +--------------------------------------------------------+
   | Ingo Bormuth,  voicebox & telefax: +49-12125-10226517  |
   | GnuPG key 86326EC9 at http://ibormuth.efil.de/contact  |
   +--------------------------------------------------------+


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Marshal.to_string and mutable values
  2005-09-15 15:13 ` [Caml-list] " Ingo Bormuth
@ 2005-09-15 15:49   ` Frédéric Gava
  2005-09-15 15:54     ` Jon Harrop
  0 siblings, 1 reply; 5+ messages in thread
From: Frédéric Gava @ 2005-09-15 15:49 UTC (permalink / raw)
  To: caml-list

Hi,

> As far as I unserstand, those things are working in compiled programms
only,
> but not in the toplevel.

ok. Excuse me for this stupid question (but the error messages are not
clear). My true question is: why does it not work in the toplevel ? Why is
it not possible to load a special Marshal module for the toplevel ? I would
be nice to have your program (in my case, parallel programs) that works
in the toplevel (for debugging) and as compiled programs.

To debug a program, I used many times the toplevel. And in my case, I need
to  serialized functions. In the compiled program, it works but not in the
toplevel. But before have a program which works
I need the toplevel...paradox....

Frédéric Gava



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Marshal.to_string and mutable values
  2005-09-15 15:49   ` Frédéric Gava
@ 2005-09-15 15:54     ` Jon Harrop
  2005-09-15 16:55       ` Mark Shinwell
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Harrop @ 2005-09-15 15:54 UTC (permalink / raw)
  To: caml-list

On Thursday 15 September 2005 16:49, Frédéric Gava wrote:
> ok. Excuse me for this stupid question (but the error messages are not
> clear). My true question is: why does it not work in the toplevel ?

Marshal probably marshals the environment of a closure with a pointer to the 
position of the code (the code itself is not available to Marshal). Clearly, 
that pointer only makes sense in a compiled program and not in the top-level, 
e.g. when loading your marshalled value from a fresh top-level, your function 
does not exist.

> Why is 
> it not possible to load a special Marshal module for the toplevel ? I would
> be nice to have your program (in my case, parallel programs) that works
> in the toplevel (for debugging) and as compiled programs.

Yes. INRIA have put a lot of effort into making ocaml, ocamlc and ocamlopt as 
compatible as possible. However, there are still discrepancies. Floating 
point arithmetic is another one.

> To debug a program, I used many times the toplevel. And in my case, I need
> to  serialized functions. In the compiled program, it works but not in the
> toplevel. But before have a program which works
> I need the toplevel...paradox....

Can you get rid of the closures in your Marshalled value? Failing that, maybe 
metaocaml could work - you might be able to marshal "code" values instead of 
closures.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Marshal.to_string and mutable values
  2005-09-15 15:54     ` Jon Harrop
@ 2005-09-15 16:55       ` Mark Shinwell
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Shinwell @ 2005-09-15 16:55 UTC (permalink / raw)
  To: Jon Harrop; +Cc: caml-list

On Thu, Sep 15, 2005 at 04:54:46PM +0100, Jon Harrop wrote:
> On Thursday 15 September 2005 16:49, Fr?d?ric Gava wrote:
> > ok. Excuse me for this stupid question (but the error messages are not
> > clear). My true question is: why does it not work in the toplevel ?
> 
> Marshal probably marshals the environment of a closure with a pointer to the 
> position of the code (the code itself is not available to Marshal). Clearly, 
> that pointer only makes sense in a compiled program and not in the top-level, 
> e.g. when loading your marshalled value from a fresh top-level, your function 
> does not exist.

It is indeed a problem relating to a disparity between the toplevel and
the compiled versions, but the failure is not for the above reason.  I
encountered the same problem, albeit from a different angle[*], during the
implementation of Fresh O'Caml some months ago.  At that time I asked
Damien Doligez about it and he said:

"When the toplevel compiles code on the fly, the resulting code is not
recognized as such by the Marshal module, but the code pointers in the
closures are seen as generic out-of-heap pointers, and trigger the
Invalid_argument exception."

Even so, I still don't fully understand why this is the case (perhaps
someone could elaborate? ;)

Mark

[*] Traversing arbitrary values at runtime.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-09-15 16:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-15 14:45 Marshal.to_string and mutable values Frédéric Gava
2005-09-15 15:13 ` [Caml-list] " Ingo Bormuth
2005-09-15 15:49   ` Frédéric Gava
2005-09-15 15:54     ` Jon Harrop
2005-09-15 16:55       ` Mark Shinwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).