1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1997 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)typeextern_flags=No_sharing|Closures|Compat_32(* note: this type definition is used in 'runtime/debugger.c' *)externalto_channel:out_channel->'a->extern_flagslist->unit="caml_output_value"externalto_bytes:'a->extern_flagslist->bytes="caml_output_value_to_bytes"externalto_string:'a->extern_flagslist->string="caml_output_value_to_string"externalto_buffer_unsafe:bytes->int->int->'a->extern_flagslist->int="caml_output_value_to_buffer"letto_bufferbuffofslenvflags=ifofs<0||len<0||ofs>Bytes.lengthbuff-lentheninvalid_arg"Marshal.to_buffer: substring out of bounds"elseto_buffer_unsafebuffofslenvflags(* The functions below use byte sequences as input, never using any
mutation. It makes sense to use non-mutated [bytes] rather than
[string], because we really work with sequences of bytes, not
a text representation.
*)externalfrom_channel:in_channel->'a="caml_input_value"externalfrom_bytes_unsafe:bytes->int->'a="caml_input_value_from_bytes"externaldata_size_unsafe:bytes->int->int="caml_marshal_data_size"letheader_size=16letdata_sizebuffofs=ifofs<0||ofs>Bytes.lengthbuff-header_sizetheninvalid_arg"Marshal.data_size"elsedata_size_unsafebuffofslettotal_sizebuffofs=header_size+data_sizebuffofsletfrom_bytesbuffofs=ifofs<0||ofs>Bytes.lengthbuff-header_sizetheninvalid_arg"Marshal.from_bytes"elsebeginletlen=data_size_unsafebuffofsinifofs>Bytes.lengthbuff-(header_size+len)theninvalid_arg"Marshal.from_bytes"elsefrom_bytes_unsafebuffofsendletfrom_stringbuffofs=(* Bytes.unsafe_of_string is safe here, as the produced byte
sequence is never mutated *)from_bytes(Bytes.unsafe_of_stringbuff)ofs