1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192(***************************************************************************)(* bytearray.ml : functions for efficient marshaling to and from bigarrays *)(* *)(* Copyright 1999-2011, Jérôme Vouillon *)(* *)(* This library is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as *)(* published by the Free Software Foundation, either version 2 of the *)(* License, or (at your option) any later version. A special linking *)(* exception to the GNU Lesser General Public License applies to this *)(* library, see the LICENSE file for more information. *)(***************************************************************************)openBigarraytypet=(char,int8_unsigned_elt,c_layout)Array1.ttypetf=(float,float64_elt,c_layout)Array1.tletlength=Bigarray.Array1.dimletcreatel=Bigarray.Array1.createBigarray.charBigarray.c_layoutlletcreatefl=Bigarray.Array1.createBigarray.float64Bigarray.c_layoutlexternalunsafe_blit_from_string:string->int->t->int->int->unit="ml_blit_string_to_bigarray"[@@noalloc]letof_strings=letl=String.lengthsinleta=createlinunsafe_blit_from_strings0a0l;aletmmap_of_stringfds=letl=String.lengthsinletba=#ifOCAML_VERSION>=(4,6,0)Bigarray.array1_of_genarray(Unix.map_filefdBigarray.charBigarray.c_layouttrue[|l|])#elseBigarray.Array1.map_filefdBigarray.charBigarray.c_layouttruel#endifinunsafe_blit_from_strings0ba0l;baletrecprefix_recaia'i'l=l=0||(a.{i}=a'.{i'}&&prefix_reca(i+1)a'(i'+1)(l-1))letprefixaa'i=letl=lengthainletl'=lengtha'ini<=l'-l&&prefix_reca0a'illetblit_from_stringsiajl=ifl<0||i<0||i>String.lengths-l||j<0||j>lengtha-ltheninvalid_arg"Bytearray.blit_from_string"elseunsafe_blit_from_stringsiajlexternalmarshal:'a->Marshal.extern_flagslist->t="ml_marshal_to_bigarray"externalmarshal_to_buffer:t->int->'a->Marshal.extern_flagslist->int="ml_marshal_to_bigarray_buffer"externalunmarshal:t->int->'a="ml_unmarshal_from_bigarray"externalunsafe_blit_from_floatarray:floatarray->int->tf->int->int->unit="ml_blit_floatarray_to_bigarray"[@@noalloc]externalunsafe_blit_to_floatarray:tf->int->floatarray->int->int->unit="ml_blit_bigarray_to_floatarray"[@@noalloc]letto_floatarrayal=letfa=Obj.obj(Obj.new_blockObj.double_array_tagl)inunsafe_blit_to_floatarraya0fa0l;faletto_this_floatarrayfaal=unsafe_blit_to_floatarraya0fa0l;faletof_floatarrayfa=letl=Array.lengthfainleta=createflinunsafe_blit_from_floatarrayfa0a0l;a