1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1997 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the GNU Library General Public License, with *)
10 (* the special exception on linking described in file ../../LICENSE. *)
12 (***********************************************************************)
14 (* $Id: marshal.ml 6338 2004-05-27 15:28:05Z doligez $ *)
20 external to_string: 'a -> extern_flags list -> string
21 = "caml_output_value_to_string"
23 let to_channel chan v flags =
24 output_string chan (to_string v flags)
26 external to_buffer_unsafe:
27 string -> int -> int -> 'a -> extern_flags list -> int
28 = "caml_output_value_to_buffer"
30 let to_buffer buff ofs len v flags =
31 if ofs < 0 || len < 0 || ofs + len > String.length buff
32 then invalid_arg "Marshal.to_buffer: substring out of bounds"
33 else to_buffer_unsafe buff ofs len v flags
35 let to_buffer' ~buf ~pos ~len v ~mode = to_buffer buf pos len v mode
37 external from_string_unsafe: string -> int -> 'a
38 = "caml_input_value_from_string"
39 external data_size_unsafe: string -> int -> int = "caml_marshal_data_size"
42 let data_size buff ofs =
43 if ofs < 0 || ofs > String.length buff - header_size
44 then invalid_arg "Marshal.data_size"
45 else data_size_unsafe buff ofs
46 let total_size buff ofs = header_size + data_size buff ofs
48 let from_string buff ofs =
49 if ofs < 0 || ofs > String.length buff - header_size
50 then invalid_arg "Marshal.from_size"
52 let len = data_size_unsafe buff ofs in
53 if ofs > String.length buff - (header_size + len)
54 then invalid_arg "Marshal.from_string"
55 else from_string_unsafe buff ofs
58 let from_channel = Pervasives.input_value