Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshal an object? #2780

Closed
vicuna opened this issue Jun 8, 2001 · 2 comments
Closed

Marshal an object? #2780

vicuna opened this issue Jun 8, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jun 8, 2001

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" ;;

@vicuna
Copy link
Author

vicuna commented Jun 12, 2001

Comment author: administrator

Is it ever possible to marshal an object?

Currently, no.

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.

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Jun 12, 2001

Comment author: administrator

Not supported currently.

@vicuna vicuna closed this as completed Jun 12, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant