Skip to content

Commit

Permalink
Add a way to access the custom pointer on OCaml blocks
Browse files Browse the repository at this point in the history
Useful for bigarrays and other custom types.
  • Loading branch information
g2p committed Dec 20, 2020
1 parent 7c1203b commit 0370079
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ impl<'a, T> OCaml<'a, T> {
pub unsafe fn raw(&self) -> RawOCaml {
self.raw
}

/// 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<U>(&self) -> *const U {
ocaml_sys::field(self.raw, 1) as *const U
}
}

impl OCaml<'static, ()> {
Expand Down

0 comments on commit 0370079

Please sign in to comment.