Skip to content

Commit

Permalink
Moved asserts to top of EvalContextFunctionCache functions
Browse files Browse the repository at this point in the history
Two reasons for this:
 1. CONTRIBUTING.md says to do this at the top
 2. the `ctx` argument was actually used before the assert

Ticket: None
Changelog: None
Signed-off-by: Lars Erik Wik <[email protected]>
(cherry picked from commit eec9776)
  • Loading branch information
larsewi committed Sep 14, 2023
1 parent 83d0a55 commit cac8b32
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libpromises/eval_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -2832,16 +2832,17 @@ bool EvalContextFunctionCacheGet(const EvalContext *ctx,
const FnCall *fp ARG_UNUSED,
const Rlist *args, Rval *rval_out)
{
assert(fp != NULL);
assert(fp->name != NULL);
assert(ctx != NULL);

if (!(ctx->eval_options & EVAL_OPTION_CACHE_SYSTEM_FUNCTIONS))
{
return false;
}

// The cache key is made of the function name and all args values
Rlist *args_copy = RlistCopy(args);
assert(fp != NULL);
assert(fp->name != NULL);
assert(ctx != NULL);
Rlist *key = RlistPrepend(&args_copy, fp->name, RVAL_TYPE_SCALAR);
Rval *rval = FuncCacheMapGet(ctx->function_cache, key);
RlistDestroy(key);
Expand All @@ -2863,6 +2864,10 @@ void EvalContextFunctionCachePut(EvalContext *ctx,
const FnCall *fp ARG_UNUSED,
const Rlist *args, const Rval *rval)
{
assert(fp != NULL);
assert(fp->name != NULL);
assert(ctx != NULL);

if (!(ctx->eval_options & EVAL_OPTION_CACHE_SYSTEM_FUNCTIONS))
{
return;
Expand All @@ -2872,9 +2877,6 @@ void EvalContextFunctionCachePut(EvalContext *ctx,
*rval_copy = RvalCopy(*rval);

Rlist *args_copy = RlistCopy(args);
assert(fp != NULL);
assert(fp->name != NULL);
assert(ctx != NULL);
Rlist *key = RlistPrepend(&args_copy, fp->name, RVAL_TYPE_SCALAR);

FuncCacheMapInsert(ctx->function_cache, key, rval_copy);
Expand Down

0 comments on commit cac8b32

Please sign in to comment.