diff options
Diffstat (limited to 'otherlibs/threads/marshal.ml')
-rw-r--r-- | otherlibs/threads/marshal.ml | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/otherlibs/threads/marshal.ml b/otherlibs/threads/marshal.ml index c71ca83d08..005e964372 100644 --- a/otherlibs/threads/marshal.ml +++ b/otherlibs/threads/marshal.ml @@ -16,6 +16,9 @@ type extern_flags = | Closures | Compat_32 +external to_bytes: 'a -> extern_flags list -> bytes + = "caml_output_value_to_string" + external to_string: 'a -> extern_flags list -> string = "caml_output_value_to_string" @@ -23,35 +26,34 @@ let to_channel chan v flags = output_string chan (to_string v flags) external to_buffer_unsafe: - string -> int -> int -> 'a -> extern_flags list -> int + bytes -> int -> int -> 'a -> extern_flags list -> int = "caml_output_value_to_buffer" let to_buffer buff ofs len v flags = - if ofs < 0 || len < 0 || ofs + len > String.length buff + if ofs < 0 || len < 0 || ofs + len > Bytes.length buff then invalid_arg "Marshal.to_buffer: substring out of bounds" else to_buffer_unsafe buff ofs len v flags -let to_buffer' ~buf ~pos ~len v ~mode = to_buffer buf pos len v mode - -external from_string_unsafe: string -> int -> 'a +external from_channel: in_channel -> 'a = "caml_input_value" +external from_bytes_unsafe: bytes -> int -> 'a = "caml_input_value_from_string" -external data_size_unsafe: string -> int -> int = "caml_marshal_data_size" +external data_size_unsafe: bytes -> int -> int = "caml_marshal_data_size" let header_size = 20 let data_size buff ofs = - if ofs < 0 || ofs > String.length buff - header_size + if ofs < 0 || ofs > Bytes.length buff - header_size then invalid_arg "Marshal.data_size" else data_size_unsafe buff ofs let total_size buff ofs = header_size + data_size buff ofs -let from_string buff ofs = - if ofs < 0 || ofs > String.length buff - header_size - then invalid_arg "Marshal.from_size" +let from_bytes buff ofs = + if ofs < 0 || ofs > Bytes.length buff - header_size + then invalid_arg "Marshal.from_bytes" else begin let len = data_size_unsafe buff ofs in - if ofs > String.length buff - (header_size + len) - then invalid_arg "Marshal.from_string" - else from_string_unsafe buff ofs + if ofs > Bytes.length buff - (header_size + len) + then invalid_arg "Marshal.from_bytes" + else from_bytes_unsafe buff ofs end -let from_channel = Pervasives.input_value +let from_string buff ofs = from_bytes (Bytes.unsafe_of_string buff) ofs |