Implement realloc (#7)

* Implement realloc

* Bump version
This commit is contained in:
Yota Toyama
2021-03-03 00:08:24 -08:00
committed by GitHub
parent 4a79029a6c
commit 77a22ba136
2 changed files with 10 additions and 2 deletions

View File

@@ -1,8 +1,11 @@
[package] [package]
name = "bdwgc-alloc" name = "bdwgc-alloc"
description = "impl GlobalAlloc for bdwgc" description = "impl GlobalAlloc for bdwgc"
version = "0.5.2" version = "0.6.0"
authors = ["swgillespie <sean.william.g@gmail.com>", "Yota Toyama <raviqqe@gmail.com>"] authors = [
"swgillespie <sean.william.g@gmail.com>",
"Yota Toyama <raviqqe@gmail.com>"
]
repository = "https://github.com/raviqqe/bdwgc-alloc" repository = "https://github.com/raviqqe/bdwgc-alloc"
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"

View File

@@ -22,6 +22,7 @@ extern "C" {
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int; fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
fn GC_init(); fn GC_init();
fn GC_malloc(size: size_t) -> *mut c_void; 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_register_my_thread(stack_base: *const GcStackBase) -> c_int;
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase); fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
fn GC_unregister_my_thread(); fn GC_unregister_my_thread();
@@ -79,4 +80,8 @@ unsafe impl GlobalAlloc for Allocator {
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
GC_free(ptr as *mut c_void) 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
}
} }