From 77a22ba136c0cf6dd265e2c9c526451c4bbc6a4f Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Wed, 3 Mar 2021 00:08:24 -0800 Subject: [PATCH] Implement realloc (#7) * Implement realloc * Bump version --- Cargo.toml | 7 +++++-- src/lib.rs | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4eee4e2..36b67c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "bdwgc-alloc" description = "impl GlobalAlloc for bdwgc" -version = "0.5.2" -authors = ["swgillespie ", "Yota Toyama "] +version = "0.6.0" +authors = [ + "swgillespie ", + "Yota Toyama " +] repository = "https://github.com/raviqqe/bdwgc-alloc" edition = "2018" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index fcb2d15..2b5a1e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ extern "C" { fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int; fn GC_init(); fn GC_malloc(size: size_t) -> *mut c_void; + fn GC_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void; fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int; fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase); fn GC_unregister_my_thread(); @@ -79,4 +80,8 @@ unsafe impl GlobalAlloc for Allocator { unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { GC_free(ptr as *mut c_void) } + + unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, size: usize) -> *mut u8 { + GC_realloc(ptr as *mut c_void, size) as *mut u8 + } }