You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 381 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
Is it ever possible to marshal an object? At run-time you have the dynamic
type of the object so you should be able to resolve any questions about
what the object actually is. But even simple programs (see below) that
marshal objects choke with Invalid_Argument("Object value") (or somesuch).
I've tried ocaml 2.04 and 3.01. Is there any hope or is this just not
supported?
- Wes
(* this code fails at run-time )
class myclass =
object
method name = "hello";
val info : int = 32;
end
let m = new myclass ;;
let oc = open_out_bin "output" ;;
let _ = Marshal.to_channel oc m [Marshal.Closures] ;; ( we die here *)
let _ = Printf.printf "Done!\n" ;;
The text was updated successfully, but these errors were encountered:
At run-time you have the dynamic
type of the object so you should be able to resolve any questions about
what the object actually is.
Like functions, objects contain both data and code (via the vtable
pointers). Marshalling data is easy, but marshalling code isn't.
Actually sending the code along the wire requires position-independent
code, which OCaml doesn't generate currently, and can result in quite
large amounts of data. Marshalling just a reference to the code (or
to the class), like Java does, is quite tricky, at least if you want
to make sure that the code at the other end will match.
The Marshall.Closures flag sort of solves the issue for pure functions
(but requires that the reader program be exactly identical to the
writer program, which is a strong restriction in practice), but there
are additional issues for objects related to the structure of vtables
that render this approach ineffective for objects (currently).
JoCaml (a distributed extension of OCaml based on the join-calculus)
does something along these lines, but the solution is tricky and quite
specific to JoCaml (it needs a bidirectional connection between the
sender and the receiver, as far as I can remember, so it doesn't
extend to marshalling to files). We're still scratching our heads
trying to design a more general solution, but don't hold your breath.
In the meantime, you could work around the problem by marshalling a
pure data structure extracted from the objects, and reconstructing the
objects from the data structure on the reader side.
Original bug ID: 381
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Is it ever possible to marshal an object? At run-time you have the dynamic
type of the object so you should be able to resolve any questions about
what the object actually is. But even simple programs (see below) that
marshal objects choke with Invalid_Argument("Object value") (or somesuch).
I've tried ocaml 2.04 and 3.01. Is there any hope or is this just not
supported?
(* this code fails at run-time )
class myclass =
object
method name = "hello";
val info : int = 32;
end
let m = new myclass ;;
let oc = open_out_bin "output" ;;
let _ = Marshal.to_channel oc m [Marshal.Closures] ;; ( we die here *)
let _ = Printf.printf "Done!\n" ;;
The text was updated successfully, but these errors were encountered: