@@ -326,6 +326,7 @@ mod fuzz_dummy {
326
326
use ffi:: * ;
327
327
use self :: std:: ptr;
328
328
use self :: std:: boxed:: Box ;
329
+ use std:: mem;
329
330
330
331
extern "C" {
331
332
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn ;
@@ -335,20 +336,31 @@ mod fuzz_dummy {
335
336
336
337
// Contexts
337
338
/// Creates a dummy context, tracking flags to ensure proper calling semantics
338
- pub unsafe fn secp256k1_context_create ( flags : c_uint ) -> * mut Context {
339
+ pub unsafe fn secp256k1_context_preallocated_create ( _ptr : * mut c_void , flags : c_uint ) -> * mut Context {
339
340
let b = Box :: new ( Context ( flags as i32 ) ) ;
340
341
Box :: into_raw ( b)
341
342
}
342
343
344
+ /// Return dummy size of context struct.
345
+ pub unsafe fn secp256k1_context_preallocated_size ( _flags : c_uint ) -> usize {
346
+ mem:: size_of :: < Context > ( )
347
+ }
348
+
349
+ /// Return dummy size of context struct.
350
+ pub unsafe fn secp256k1_context_preallocated_clone_size ( cx : * mut Context ) -> usize {
351
+ mem:: size_of :: < Context > ( )
352
+ }
353
+
343
354
/// Copies a dummy context
344
- pub unsafe fn secp256k1_context_clone ( cx : * mut Context ) -> * mut Context {
345
- let b = Box :: new ( Context ( ( * cx) . 0 ) ) ;
346
- Box :: into_raw ( b)
355
+ pub unsafe fn secp256k1_context_preallocated_clone ( cx : * const Context , prealloc : * mut c_void ) -> * mut Context {
356
+ let ret = prealloc as * mut Context ;
357
+ * ret = ( * cx) . clone ( ) ;
358
+ ret
347
359
}
348
360
349
- /// Frees a dummy context
350
- pub unsafe fn secp256k1_context_destroy ( cx : * mut Context ) {
351
- Box :: from_raw ( cx) ;
361
+ /// "Destroys" a dummy context
362
+ pub unsafe fn secp256k1_context_preallocated_destroy ( cx : * mut Context ) {
363
+ ( * cx) . 0 = 0 ;
352
364
}
353
365
354
366
/// Asserts that cx is properly initialized
0 commit comments