From 7527b952cf8d1ce0dbbbbac326ffbd50401ab1ae Mon Sep 17 00:00:00 2001 From: Gabriel de Perthuis Date: Sun, 20 Dec 2020 09:53:41 +0100 Subject: [PATCH] Add a way to access the custom pointer on OCaml blocks Useful for bigarrays and other custom types. --- src/value.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/value.rs b/src/value.rs index c084473..33fbb33 100644 --- a/src/value.rs +++ b/src/value.rs @@ -113,6 +113,20 @@ impl<'a, T> OCaml<'a, T> { { RustT::from_ocaml(*self) } + + /// Meant to match Data_custom_val from mlvalues.h + /// + /// # Safety + /// + /// Casts to an arbitrary pointer type, take care before + /// dereferencing + /// + /// Similar to raw(), the resulting pointer can become invalid + /// after any call into the OCaml runtime, for example allocating + /// OCaml values or calling OCaml functions + pub unsafe fn custom_ptr_val(&self) -> *const U { + ocaml_sys::field(self.raw, 1) as *const U + } } impl OCaml<'static, ()> {