123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475(**************************************************************************)(* *)(* 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|Compression(* 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)ofsletcompression_supported()=lets=to_string()[Compression]inmatchs.[3]with|'\xBD'->true|'\xBE'->false|_->assertfalse