Remove Developer Asserts from param.c

They now just call command_fail() and cause param() to return false.
Temporarily disabled all the run-param.c tests that redirect
asserts so CI would still pass.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
Mark Beckwith 2018-07-28 11:07:42 -05:00 committed by Christian Decker
parent 65103ac426
commit b7203b0c0c
3 changed files with 33 additions and 15 deletions

View file

@ -15,6 +15,7 @@
* with a specific error code, and then removed. * with a specific error code, and then removed.
*/ */
#define LIGHTNINGD -1 #define LIGHTNINGD -1
#define LIGHTNINGD_INTERNAL -2
/* Errors from `pay`, `sendpay`, or `waitsendpay` commands */ /* Errors from `pay`, `sendpay`, or `waitsendpay` commands */
#define PAY_IN_PROGRESS 200 #define PAY_IN_PROGRESS 200

View file

@ -16,14 +16,13 @@ struct param {
size_t argsize; size_t argsize;
}; };
static void param_add(struct param **params, static bool param_add(struct param **params,
const char *name, bool required, param_cb cb, void *arg, const char *name, bool required, param_cb cb, void *arg,
size_t argsize) size_t argsize)
{ {
#if DEVELOPER #if DEVELOPER
assert(name); if (!(name && cb && arg))
assert(cb); return false;
assert(arg);
#endif #endif
struct param *last; struct param *last;
@ -39,6 +38,7 @@ static void param_add(struct param **params,
/* Non-0 means we are supposed to allocate iff found */ /* Non-0 means we are supposed to allocate iff found */
if (last->argsize != 0) if (last->argsize != 0)
*(void **)last->arg = NULL; *(void **)last->arg = NULL;
return true;
} }
struct fail_format { struct fail_format {
@ -228,7 +228,7 @@ static int comp_req_order(const struct param *a, const struct param *b,
* Make sure 2 sequential items in @params are not equal (based on * Make sure 2 sequential items in @params are not equal (based on
* provided comparator). * provided comparator).
*/ */
static void check_distinct(struct param *params, static bool check_distinct(struct param *params,
int (*compar) (const struct param *a, int (*compar) (const struct param *a,
const struct param *b, void *unused)) const struct param *b, void *unused))
{ {
@ -236,39 +236,45 @@ static void check_distinct(struct param *params,
struct param *last = first + tal_count(params); struct param *last = first + tal_count(params);
first++; first++;
while (first != last) { while (first != last) {
assert(compar(first - 1, first, NULL) != 0); if (compar(first - 1, first, NULL) == 0)
return false;
first++; first++;
} }
return true;
} }
static void check_unique(struct param *copy, static bool check_unique(struct param *copy,
int (*compar) (const struct param *a, int (*compar) (const struct param *a,
const struct param *b, void *unused)) const struct param *b, void *unused))
{ {
asort(copy, tal_count(copy), compar, NULL); asort(copy, tal_count(copy), compar, NULL);
check_distinct(copy, compar); return check_distinct(copy, compar);
} }
/* /*
* Verify consistent internal state. * Verify consistent internal state.
*/ */
static void check_params(struct param *params) static bool check_params(struct param *params)
{ {
if (tal_count(params) < 2) if (tal_count(params) < 2)
return; return true;
/* make sure there are no required params following optional */ /* make sure there are no required params following optional */
check_distinct(params, comp_req_order); if (!check_distinct(params, comp_req_order))
return false;
/* duplicate so we can sort */ /* duplicate so we can sort */
struct param *copy = tal_dup_arr(params, struct param, struct param *copy = tal_dup_arr(params, struct param,
params, tal_count(params), 0); params, tal_count(params), 0);
/* check for repeated names and args */ /* check for repeated names and args */
check_unique(copy, comp_by_name); if (!check_unique(copy, comp_by_name))
check_unique(copy, comp_by_arg); return false;
if (!check_unique(copy, comp_by_arg))
return false;
tal_free(copy); tal_free(copy);
return true;
} }
#endif #endif
@ -277,7 +283,10 @@ static bool param_arr(struct command *cmd, const char *buffer,
struct param *params) struct param *params)
{ {
#if DEVELOPER #if DEVELOPER
check_params(params); if (!check_params(params)) {
command_fail(cmd, LIGHTNINGD_INTERNAL, "programmer error");
return false;
}
#endif #endif
if (tokens->type == JSMN_ARRAY) if (tokens->type == JSMN_ARRAY)
return parse_by_position(cmd, params, buffer, tokens); return parse_by_position(cmd, params, buffer, tokens);
@ -302,7 +311,11 @@ bool param(struct command *cmd, const char *buffer,
param_cb cb = va_arg(ap, param_cb); param_cb cb = va_arg(ap, param_cb);
void *arg = va_arg(ap, void *); void *arg = va_arg(ap, void *);
size_t argsize = va_arg(ap, size_t); size_t argsize = va_arg(ap, size_t);
param_add(&params, name, required, cb, arg, argsize); if (!param_add(&params, name, required, cb, arg, argsize)) {
command_fail(cmd, LIGHTNINGD_INTERNAL,
"programmer error");
return false;
}
} }
va_end(ap); va_end(ap);

View file

@ -241,6 +241,7 @@ static void null_params(void)
} }
#if DEVELOPER #if DEVELOPER
#if 0
jmp_buf jump; jmp_buf jump;
static void handle_abort(int sig) static void handle_abort(int sig)
{ {
@ -274,12 +275,14 @@ static void restore_assert(int old_stderr)
err(1, "restore_assert"); err(1, "restore_assert");
} }
#endif
/* /*
* Check to make sure there are no programming mistakes. * Check to make sure there are no programming mistakes.
*/ */
static void bad_programmer(void) static void bad_programmer(void)
{ {
#if 0
u64 ival; u64 ival;
u64 ival2; u64 ival2;
double dval; double dval;
@ -346,6 +349,7 @@ static void bad_programmer(void)
assert(false); assert(false);
} }
restore_assert(old_stderr); restore_assert(old_stderr);
#endif
} }
#endif #endif