1997-07-02 11:16:15 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1997-07-31 12:06:38 -07:00
|
|
|
(* Copyright 1997 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
1997-07-02 11:16:15 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
type extern_flags =
|
|
|
|
No_sharing
|
|
|
|
| Closures
|
|
|
|
|
|
|
|
external to_channel: out_channel -> 'a -> extern_flags list -> unit
|
2004-01-01 08:42:43 -08:00
|
|
|
= "caml_output_value"
|
1997-07-31 12:06:38 -07:00
|
|
|
external to_string: 'a -> extern_flags list -> string
|
2004-01-01 08:42:43 -08:00
|
|
|
= "caml_output_value_to_string"
|
1997-07-02 11:16:15 -07:00
|
|
|
external to_buffer_unsafe:
|
1997-11-19 02:02:22 -08:00
|
|
|
string -> int -> int -> 'a -> extern_flags list -> int
|
2004-01-01 08:42:43 -08:00
|
|
|
= "caml_output_value_to_buffer"
|
1997-07-02 11:16:15 -07:00
|
|
|
|
|
|
|
let to_buffer buff ofs len v flags =
|
2002-07-12 02:47:54 -07:00
|
|
|
if ofs < 0 || len < 0 || ofs > String.length buff - len
|
1997-07-02 11:16:15 -07:00
|
|
|
then invalid_arg "Marshal.to_buffer: substring out of bounds"
|
|
|
|
else to_buffer_unsafe buff ofs len v flags
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
external from_channel: in_channel -> 'a = "caml_input_value"
|
|
|
|
external from_string_unsafe: string -> int -> 'a
|
|
|
|
= "caml_input_value_from_string"
|
|
|
|
external data_size_unsafe: string -> int -> int = "caml_marshal_data_size"
|
1997-07-02 11:16:15 -07:00
|
|
|
|
|
|
|
let header_size = 20
|
|
|
|
let data_size buff ofs =
|
2002-07-12 02:47:54 -07:00
|
|
|
if ofs < 0 || ofs > String.length buff - header_size
|
1997-07-02 11:16:15 -07:00
|
|
|
then invalid_arg "Marshal.data_size"
|
|
|
|
else data_size_unsafe buff ofs
|
1997-07-31 12:06:38 -07:00
|
|
|
let total_size buff ofs = header_size + data_size buff ofs
|
1997-07-02 11:16:15 -07:00
|
|
|
|
|
|
|
let from_string buff ofs =
|
2002-07-12 02:47:54 -07:00
|
|
|
if ofs < 0 || ofs > String.length buff - header_size
|
1997-07-02 11:16:15 -07:00
|
|
|
then invalid_arg "Marshal.from_size"
|
|
|
|
else begin
|
|
|
|
let len = data_size_unsafe buff ofs in
|
2002-07-12 02:47:54 -07:00
|
|
|
if ofs > String.length buff - (header_size + len)
|
1997-07-02 11:16:15 -07:00
|
|
|
then invalid_arg "Marshal.from_string"
|
|
|
|
else from_string_unsafe buff ofs
|
|
|
|
end
|