Skip to content

Commit

Permalink
refactor: Move default callbacks to util.h
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Dec 3, 2021
1 parent 4c94c55 commit a4875e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
11 changes: 0 additions & 11 deletions src/gen_ecmult_gen_static_prec_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@
#include "ecmult_gen.h"
#include "ecmult_gen_prec_impl.h"

static void default_error_callback_fn(const char* str, void* data) {
(void)data;
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
abort();
}

static const secp256k1_callback default_error_callback = {
default_error_callback_fn,
NULL
};

int main(int argc, char **argv) {
secp256k1_ge_storage* table;
int inner;
Expand Down
28 changes: 0 additions & 28 deletions src/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,6 @@
} \
} while(0)

#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS
#include <stdlib.h>
#include <stdio.h>
static void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
(void)data;
fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
abort();
}
static void secp256k1_default_error_callback_fn(const char* str, void* data) {
(void)data;
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
abort();
}
#else
void secp256k1_default_illegal_callback_fn(const char* str, void* data);
void secp256k1_default_error_callback_fn(const char* str, void* data);
#endif

static const secp256k1_callback default_illegal_callback = {
secp256k1_default_illegal_callback_fn,
NULL
};

static const secp256k1_callback default_error_callback = {
secp256k1_default_error_callback_fn,
NULL
};

struct secp256k1_context_struct {
secp256k1_ecmult_gen_context ecmult_gen_ctx;
secp256k1_callback illegal_callback;
Expand Down
27 changes: 27 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *
cb->fn(text, (void*)cb->data);
}

#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS
static void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
(void)data;
fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
abort();
}
static void secp256k1_default_error_callback_fn(const char* str, void* data) {
(void)data;
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
abort();
}
#else
void secp256k1_default_illegal_callback_fn(const char* str, void* data);
void secp256k1_default_error_callback_fn(const char* str, void* data);
#endif

static const secp256k1_callback default_illegal_callback = {
secp256k1_default_illegal_callback_fn,
NULL
};

static const secp256k1_callback default_error_callback = {
secp256k1_default_error_callback_fn,
NULL
};


#ifdef DETERMINISTIC
#define TEST_FAILURE(msg) do { \
fprintf(stderr, "%s\n", msg); \
Expand Down

0 comments on commit a4875e3

Please sign in to comment.