Skip to content

Commit

Permalink
Expose recover_handle_mut, used by macros
Browse files Browse the repository at this point in the history
  • Loading branch information
tizoc committed Dec 27, 2023
1 parent d7714c7 commit 0572cf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ macro_rules! expand_exported_function {
} => {
#[no_mangle]
pub extern "C" fn $name( $($arg: $typ),* ) -> $crate::expand_exported_function_return!($($rtyp)*) {
let $cr = unsafe { &mut $crate::OCamlRuntime::recover_handle() };
let $cr = unsafe { &mut $crate::OCamlRuntime::recover_handle_mut() };
$crate::expand_rooted_args_init!($cr, $($original_args)*);
$crate::expand_exported_function_body!(
@body $body
Expand Down
9 changes: 5 additions & 4 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ impl OCamlRuntime {
panic!("Rust code that is called from an OCaml program should not try to initialize the runtime.");
}

#[doc(hidden)]
#[inline(always)]
pub(crate) unsafe fn recover_handle_mut() -> &'static mut Self {
pub unsafe fn recover_handle_mut() -> &'static mut Self {
static mut RUNTIME: OCamlRuntime = OCamlRuntime { _private: () };
&mut RUNTIME
}

#[inline(always)]
pub(crate) unsafe fn recover_handle() -> &'static Self {
unsafe fn recover_handle() -> &'static Self {
Self::recover_handle_mut()
}

Expand Down Expand Up @@ -132,12 +133,12 @@ impl OCamlDomainLock {
}

#[inline(always)]
pub(crate) fn recover_handle<'a>(&self) -> &'a OCamlRuntime {
fn recover_handle<'a>(&self) -> &'a OCamlRuntime {
unsafe { OCamlRuntime::recover_handle() }
}

#[inline(always)]
pub(crate) fn recover_handle_mut<'a>(&self) -> &'a mut OCamlRuntime {
fn recover_handle_mut<'a>(&self) -> &'a mut OCamlRuntime {
unsafe { OCamlRuntime::recover_handle_mut() }
}
}
Expand Down

0 comments on commit 0572cf1

Please sign in to comment.