Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function for users to keep pointers alive #123

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/bdwgc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ extern "C" {
pub fn GC_ignore_warn_proc(proc: *mut u8, word: usize);

pub fn GC_finalized_total() -> u64;

pub fn GC_keep_alive(ptr: *mut u8);
}
10 changes: 5 additions & 5 deletions library/std/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ pub fn thread_registered() -> bool {
unsafe { bdwgc::GC_thread_is_registered() != 0 }
}

pub fn keep_alive<T>(ptr: *mut T) {
unsafe { bdwgc::GC_keep_alive(ptr as *mut u8) }
}

////////////////////////////////////////////////////////////////////////////////
// GC API
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -231,11 +235,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Gc<U>> for Gc<T> {}
#[cfg(all(not(bootstrap), not(test)))]
impl<T: ?Sized> Drop for Gc<T> {
fn drop(&mut self) {
unsafe {
// asm macro clobber by default, so this is enough to introduce a
// barrier.
core::arch::asm!("/* {0} */", in(reg) self);
}
keep_alive(self);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bdwgc
Submodule bdwgc updated 2 files
+7 −0 include/gc/gc.h
+5 −0 mark.c