123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119open!Import(* WARNING:
We use non-memory-safe things throughout the [Trusted] module.
Most of it is only safe in combination with the type signature (e.g. exposing
[val copy : 'a t -> 'b t] would be a big mistake). *)moduleTrusted:sigtype'atvalempty:'atvalunsafe_create_uninitialized:len:int->'atvalcreate_obj_array:len:int->'atvalcreate:len:int->'a->'atvalsingleton:'a->'atvalget:'at->int->'avalset:'at->int->'a->unitvalswap:_t->int->int->unitvalunsafe_get:'at->int->'avalunsafe_set:'at->int->'a->unitvalunsafe_set_omit_phys_equal_check:'at->int->'a->unitvalunsafe_set_int:'at->int->int->unitvalunsafe_set_int_assuming_currently_int:'at->int->int->unitvalunsafe_set_assuming_currently_int:'at->int->'a->unitvallength:'at->intvalunsafe_blit:('at,'at)Blit.blitvalcopy:'at->'atvalunsafe_truncate:'at->len:int->unitvalunsafe_clear_if_pointer:_t->int->unitend=structtype'at=Obj_array.tletempty=Obj_array.emptyletunsafe_create_uninitialized~len=Obj_array.create_zero~lenletcreate_obj_array~len=Obj_array.create_zero~lenletcreate~lenx=Obj_array.create~len(Caml.Obj.reprx)letsingletonx=Obj_array.singleton(Caml.Obj.reprx)letswaptij=Obj_array.swaptijletgetarri=Caml.Obj.obj(Obj_array.getarri)letsetarrix=Obj_array.setarri(Caml.Obj.reprx)letunsafe_getarri=Caml.Obj.obj(Obj_array.unsafe_getarri)letunsafe_setarrix=Obj_array.unsafe_setarri(Caml.Obj.reprx)letunsafe_set_intarrix=Obj_array.unsafe_set_intarrixletunsafe_set_int_assuming_currently_intarrix=Obj_array.unsafe_set_int_assuming_currently_intarrixletunsafe_set_assuming_currently_intarrix=Obj_array.unsafe_set_assuming_currently_intarri(Caml.Obj.reprx)letlength=Obj_array.lengthletunsafe_blit=Obj_array.unsafe_blitletcopy=Obj_array.copyletunsafe_truncate=Obj_array.truncateletunsafe_set_omit_phys_equal_checktix=Obj_array.unsafe_set_omit_phys_equal_checkti(Caml.Obj.reprx)letunsafe_clear_if_pointer=Obj_array.unsafe_clear_if_pointerendincludeTrustedletinitl~f=ifl<0theninvalid_arg"Uniform_array.init"elseletres=unsafe_create_uninitialized~len:linfori=0tol-1dounsafe_setresi(fi)done;resletof_arrayarr=init~f:(Array.unsafe_getarr)(Array.lengtharr)letmapa~f=init~f:(funi->f(unsafe_getai))(lengtha)letitera~f=fori=0tolengtha-1dof(unsafe_getai)doneletto_listt=List.init~f:(gett)(lengtht)letof_listl=letlen=List.lengthlinletres=unsafe_create_uninitialized~leninList.iteril~f:(funix->setresix);res(* It is not safe for [to_array] to be the identity function because we have code that
relies on [float array]s being unboxed, for example in [bin_write_array]. *)letto_arrayt=Array.init(lengtht)~f:(funi->unsafe_getti)includeSexpable.Of_sexpable1(Array)(structtypenonrec'at='atletto_sexpable=to_arrayletof_sexpable=of_arrayend)includeBlit.Make1(structtypenonrec'at='atletlength=lengthletcreate_like~lent=iflen=0thenemptyelse(assert(lengtht>0);create~len(gett0));;letunsafe_blit=unsafe_blitend)