diff --git a/src/ffi.rs b/src/ffi.rs index ba136bb7b..6bd3f875b 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -326,6 +326,7 @@ mod fuzz_dummy { use ffi::*; use self::std::ptr; use self::std::boxed::Box; + use std::mem; extern "C" { pub static secp256k1_ecdh_hash_function_default: EcdhHashFn; @@ -335,20 +336,31 @@ mod fuzz_dummy { // Contexts /// Creates a dummy context, tracking flags to ensure proper calling semantics - pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context { + pub unsafe fn secp256k1_context_preallocated_create(_ptr: *mut c_void, flags: c_uint) -> *mut Context { let b = Box::new(Context(flags as i32)); Box::into_raw(b) } + /// Return dummy size of context struct. + pub unsafe fn secp256k1_context_preallocated_size(_flags: c_uint) -> usize { + mem::size_of::() + } + + /// Return dummy size of context struct. + pub unsafe fn secp256k1_context_preallocated_clone_size(cx: *mut Context) -> usize { + mem::size_of::() + } + /// Copies a dummy context - pub unsafe fn secp256k1_context_clone(cx: *mut Context) -> *mut Context { - let b = Box::new(Context((*cx).0)); - Box::into_raw(b) + pub unsafe fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context { + let ret = prealloc as *mut Context; + *ret = (*cx).clone(); + ret } - /// Frees a dummy context - pub unsafe fn secp256k1_context_destroy(cx: *mut Context) { - Box::from_raw(cx); + /// "Destroys" a dummy context + pub unsafe fn secp256k1_context_preallocated_destroy(cx: *mut Context) { + (*cx).0 = 0; } /// Asserts that cx is properly initialized