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 Apr 14, 2021
1 parent e79f58b commit 7527b95
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 @@ -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<U>(&self) -> *const U {
ocaml_sys::field(self.raw, 1) as *const U
}
}

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

0 comments on commit 7527b95

Please sign in to comment.