Created
October 30, 2018 12:52
-
-
Save mseri/36a92226d8358ff7dac45c7621c6bb9e to your computer and use it in GitHub Desktop.
How pkcs11 is solving the issue of ctypes Carray lifetimes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Reachable_ptr : sig | |
type 'a t | |
val typ : 'a Ctypes_static.typ -> 'a t Ctypes_static.typ | |
val setf : ('b, 'c) Ctypes.structured -> | |
('a t, ('b, 'c) Ctypes.structured) Ctypes.field -> 'a Ctypes.ptr -> unit | |
val getf : ('b, 'c) Ctypes.structured -> | |
('a t, ('b, 'c) Ctypes.structured) Ctypes.field -> 'a Ctypes.ptr | |
end = struct | |
type 'a t = 'a ptr | |
let typ = Ctypes.ptr | |
(** Add a GC dependency from one object to another: | |
while [from] is reachable, [to_] is reachable too. *) | |
let add_gc_link ~from ~to_ = | |
let r = ref (Some (Obj.repr to_)) in | |
let finaliser _ = r := None in | |
Gc.finalise finaliser from | |
let setf s f v = | |
add_gc_link ~from:s ~to_:v; | |
Ctypes.setf s f v | |
let getf = Ctypes.getf | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment