0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-11 11:16:09 -05:00

secp256k1_context_set_{error,illegal}_callback: Restore default handler by passing NULL as function argument

This commit is contained in:
Luke Dashjr 2015-09-01 01:44:02 +00:00
parent 9aac008038
commit c9d7c2a484
2 changed files with 9 additions and 4 deletions

View file

@ -179,14 +179,14 @@ void secp256k1_context_destroy(
* Args: ctx: an existing context object (cannot be NULL) * Args: ctx: an existing context object (cannot be NULL)
* In: fun: a pointer to a function to call when an illegal argument is * In: fun: a pointer to a function to call when an illegal argument is
* passed to the API, taking a message and an opaque pointer * passed to the API, taking a message and an opaque pointer
* (cannot be NULL). * (NULL restores a default handler that calls abort).
* data: the opaque pointer to pass to fun above. * data: the opaque pointer to pass to fun above.
*/ */
void secp256k1_context_set_illegal_callback( void secp256k1_context_set_illegal_callback(
secp256k1_context_t* ctx, secp256k1_context_t* ctx,
void (*fun)(const char* message, void* data), void (*fun)(const char* message, void* data),
void* data void* data
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); ) SECP256K1_ARG_NONNULL(1);
/** Set a callback function to be called when an internal consistency check /** Set a callback function to be called when an internal consistency check
* fails. The default is crashing. * fails. The default is crashing.
@ -200,14 +200,15 @@ void secp256k1_context_set_illegal_callback(
* *
* Args: ctx: an existing context object (cannot be NULL) * Args: ctx: an existing context object (cannot be NULL)
* In: fun: a pointer to a function to call when an interal error occurs, * In: fun: a pointer to a function to call when an interal error occurs,
* taking a message and an opaque pointer (cannot be NULL). * taking a message and an opaque pointer (NULL restores a default
* handler that calls abort).
* data: the opaque pointer to pass to fun above. * data: the opaque pointer to pass to fun above.
*/ */
void secp256k1_context_set_error_callback( void secp256k1_context_set_error_callback(
secp256k1_context_t* ctx, secp256k1_context_t* ctx,
void (*fun)(const char* message, void* data), void (*fun)(const char* message, void* data),
void* data void* data
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); ) SECP256K1_ARG_NONNULL(1);
/** Parse a variable-length public key into the pubkey object. /** Parse a variable-length public key into the pubkey object.
* *

View file

@ -95,11 +95,15 @@ void secp256k1_context_destroy(secp256k1_context_t* ctx) {
} }
void secp256k1_context_set_illegal_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) { void secp256k1_context_set_illegal_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) {
if (!fun)
fun = default_illegal_callback_fn;
ctx->illegal_callback.fn = fun; ctx->illegal_callback.fn = fun;
ctx->illegal_callback.data = data; ctx->illegal_callback.data = data;
} }
void secp256k1_context_set_error_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) { void secp256k1_context_set_error_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) {
if (!fun)
fun = default_error_callback_fn;
ctx->error_callback.fn = fun; ctx->error_callback.fn = fun;
ctx->error_callback.data = data; ctx->error_callback.data = data;
} }