Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000381OCaml-OCaml generalpublic2001-06-08 15:202001-06-12 16:21
Assigned To 
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000381: Marshal an object?
DescriptionIs 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

    - Wes

(* this code fails at run-time *)
class myclass =
        method name = "hello";
        val info : int = 32;
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" ;;

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
administrator (administrator)
2001-06-12 16:18

> 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

administrator (administrator)
2001-06-12 16:21

Not supported currently.

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue
2017-02-23 16:36 doligez Category OCaml general => -OCaml general

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker