Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions cf-agent/verify_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ PromiseResult VerifyMethod(EvalContext *ctx, const Rval call, const Attributes *

PromiseBanner(ctx, pp);

const Bundle *bp = EvalContextResolveBundleExpression(ctx, PromiseGetPolicy(pp), BufferData(method_name), "agent");
Bundle *bp = (Bundle *) EvalContextResolveBundleExpression(ctx, PromiseGetPolicy(pp), BufferData(method_name), "agent");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still casting const pointer to non-const. Maybe you'll need to create another function.


if (!bp)
{
bp = EvalContextResolveBundleExpression(ctx, PromiseGetPolicy(pp), BufferData(method_name), "common");
bp = (Bundle *) EvalContextResolveBundleExpression(ctx, PromiseGetPolicy(pp), BufferData(method_name), "common");
}

PromiseResult result = PROMISE_RESULT_NOOP;
Expand Down Expand Up @@ -169,6 +169,7 @@ PromiseResult VerifyMethod(EvalContext *ctx, const Rval call, const Attributes *

BundleResolve(ctx, bp);

bp->calling_bundle = (Bundle *) PromiseGetBundle(pp);
result = ScheduleAgentOperations(ctx, bp);

GetReturnValue(ctx, bp, pp);
Expand Down
6 changes: 6 additions & 0 deletions libpromises/eval_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,12 @@ void EvalContextStackPushPromiseFrame(EvalContext *ctx, const Promise *owner)

EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "bundle", PromiseGetBundle(owner)->name, CF_DATA_TYPE_STRING, "source=promise");
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "namespace", PromiseGetNamespace(owner), CF_DATA_TYPE_STRING, "source=promise");
if (PromiseGetBundle(owner)->calling_bundle != NULL)
{
char *calling_bundle_name = StringFormat("%s:%s", PromiseGetBundle(owner)->calling_bundle->ns, PromiseGetBundle(owner)->calling_bundle->name);
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "calling_bundle", calling_bundle_name, CF_DATA_TYPE_STRING, "source=promise");
free(calling_bundle_name);
}

// Recompute `with`
for (size_t i = 0; i < SeqLength(owner->conlist); i++)
Expand Down
1 change: 1 addition & 0 deletions libpromises/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ Bundle *PolicyAppendBundle(Policy *policy,
bundle->custom_sections = SeqNew(10, BundleSectionDestroy);
bundle->all_promises = SeqNew(10, NULL);
bundle->evaluation_order = evaluation_order;
bundle->calling_bundle = NULL;

return bundle;
}
Expand Down
1 change: 1 addition & 0 deletions libpromises/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ typedef struct
struct Bundle_
{
Policy *parent_policy;
struct Bundle_ *calling_bundle;

char *type;
char *name;
Expand Down
65 changes: 65 additions & 0 deletions tests/acceptance/01_vars/01_basic/calling_bundle.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Test $(this.calling_bundle)

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

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

bundle agent init
{
methods:
"a"
usebundle => new_namespace:A,
useresult => "return_var";
}

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

bundle agent check
{
vars:
"expected"
string => "default:init/new_namespace:A/B";

classes:
"ok"
expression => strcmp("$(init.return_var[1])", "$(expected)");

reports:
DEBUG::
"$(this.promise_filename) expected dirname $(init.return_var[1]), actual $(expected)";

ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}

body file control
{
namespace => "new_namespace";
}


bundle agent A
{
methods:
"b"
usebundle => new_namespace:B,
useresult => "return_var";

reports:
"$(this.calling_bundle)/$(return_var[1])"
bundle_return_value_index => "1";

}

bundle agent B
{
reports:
"$(this.calling_bundle)/$(this.bundle)"
bundle_return_value_index => "1";
}
Loading