Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ctypes_ptr.ml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(*
* Copyright (c) 2013 Jeremy Yallop.
*
* This file is distributed under the terms of the MIT License.
* See the file LICENSE for details.
*)(* Boxed pointers to C memory locations . *)[@@@warning"-9"]moduleRaw=structincludeNativeintletof_nativeintx=xletto_nativeintx=xletnull=zeroendtypevoidp=Raw.tmoduleFat:sig(** A fat pointer, which holds a reference to the reference type, the C memory
location, and an OCaml object. *)type(_,_)t(** [make ?managed ~reftyp raw] builds a fat pointer from the reference
type [reftyp], the C memory location [raw], and (optionally) an OCaml
value, [managed]. The [managed] argument may be used to manage the
lifetime of the C object; a typical use it to attach a finaliser to
[managed] which releases the memory associated with the C object whose
address is stored in [raw_ptr]. *)valmake:managed:'m->reftyp:'typ->voidp->('m,'typ)tvalis_null:(_,_)t->boolvalreftype:(_,'typ)t->'typvalmanaged:('m,_)t->'mvalset_managed:('m,_)t->'m->unitvalcoerce:('m,_)t->'typ->('m,'typ)t(** Return the raw pointer address. The function is unsafe in the sense
that it dissociates the address from the value which manages the memory,
which may trigger associated finalisers, invalidating the address. *)valunsafe_raw_addr:(_,_)t->voidpvaladd_bytes:('m,'typ)t->int->('m,'typ)tvalcompare:(_,'typ)t->(_,'typ)t->intvaldiff_bytes:(_,'typ)t->(_,'typ)t->intend=structtype('m,'typ)t={reftyp:'typ;raw:voidp;mutablemanaged:'m;}letmake~managed~reftypraw={reftyp;raw;managed}letis_null{raw}=Raw.(comparezero)raw=0letreftype{reftyp}=reftypletmanaged{managed}=managedletset_managedpm=p.managed<-mletcoercepreftyp={pwithreftyp}letunsafe_raw_addr{raw}=rawletadd_bytespbytes={pwithraw=Raw.(addp.raw(of_intbytes))}letcomparelr=Raw.comparel.rawr.rawletdiff_byteslr=Raw.(to_int(subr.rawl.raw))end