From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: berke@altern.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Marshalling objects (was: French interactive fiction, anyone ?)
Date: Thu, 20 Jun 2002 14:08:57 +0900 [thread overview]
Message-ID: <20020620140857P.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20020619175654.A14466@gogol.zorgol>
From: Berke Durak <berke@altern.org>
> Well, this is not exactly about marshalling code : I'm not asking
> Ocaml to be able to transfer pieces of code between different
> programs. Just being able to save an object and reload it in the same
> executable later would suffice : since Caml can save closures under
> the same constraints, the reason why objects can't be saved must be
> something else.
Actually I cannot remember any such reason.
I actually tried, just commenting out the Object_tag case in
byterun/extern.c, and it works!
There's a single glitch: as it just handles objects as normal data,
oid's are not updated. This means that equality on objects (which is
oid based) will be incorrect.
Can somebody comment about other possible problems?
I join some test code at the end of this mail, to run after commenting
out Object_tag.
On the other hand, objects are not just closures, and it would be nice
to be able to serialize their data in a code-independent way. Not so
unreasonable: class names are unique. This would require a bit of
runtime support, to be able to retrieve method tables.
Jacques Garrigue
(* objext.ml *)
class c (n : int) =
object (self)
method private n = n
method get_n = self#n
method show = string_of_int self#n
end
let () =
let o =
if Sys.file_exists "objext.dat" then
let ic = open_in "objext.dat" in
let o : c = input_value ic in
close_in ic;
Printf.printf "old value: %s\n" o#show;
let o' = new c (o#get_n + 1) in
Printf.printf "new value: %s\n" o'#show;
Printf.printf "old %s new\n" (if o = o' then "=" else "<>");
o'
else begin
print_endline "created objext.dat";
new c 0
end
in
let oc = open_out "objext.dat" in
Marshal.to_channel oc o [Marshal.Closures];
close_out oc
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-06-20 5:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-17 21:38 Berke Durak
2002-06-18 6:57 ` Alan Schmitt
2002-06-19 15:56 ` Berke Durak
2002-06-20 5:08 ` Jacques Garrigue [this message]
2002-06-20 7:16 ` Christopher Quinn
2002-06-20 7:41 ` Xavier Leroy
2002-06-20 14:39 ` Jacques Garrigue
2002-06-21 9:09 ` Jacques Garrigue
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=20020620140857P.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=berke@altern.org \
--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