Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-4244: Add the function name to the result cache key #5317

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions libpromises/eval_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,14 @@ bool EvalContextFunctionCacheGet(const EvalContext *ctx,
return false;
}

Rval *rval = FuncCacheMapGet(ctx->function_cache, args);
// 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);
Fixed Show fixed Hide fixed
Rval *rval = FuncCacheMapGet(ctx->function_cache, key);
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
RlistDestroy(key);
if (rval)
{
if (rval_out)
Expand All @@ -2863,7 +2870,14 @@ void EvalContextFunctionCachePut(EvalContext *ctx,

Rval *rval_copy = xmalloc(sizeof(Rval));
*rval_copy = RvalCopy(*rval);
FuncCacheMapInsert(ctx->function_cache, RlistCopy(args), rval_copy);

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);
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved

FuncCacheMapInsert(ctx->function_cache, key, rval_copy);
Fixed Show fixed Hide fixed
}

/* cfPS and associated machinery */
Expand Down
51 changes: 51 additions & 0 deletions tests/acceptance/01_vars/02_functions/cache_name.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#######################################################
#
# Test that the function result cache checks function name
#
#######################################################

body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => { default("$(this.promise_filename)") };
version => "1.0";
}

#######################################################


bundle agent init
{
vars:
"agent_regex" string => ".*cf-agent.*";
}

#######################################################

bundle common test
{
meta:
"description" -> { "CFE-4244" }
string => "Test that the function result cache checks function name";

vars:
"res1" data => findprocesses("${init.agent_regex}");

classes:
# must not reuse result from previous line
# is reused, produces a type error
"_pass" expression => processexists("${init.agent_regex}");
}


#######################################################

bundle agent check
{
methods:
_pass::
"pass" usebundle => dcs_pass("$(this.promise_filename)");

!_pass::
"pass" usebundle => dcs_fail("$(this.promise_filename)");
}
Loading