本文整理汇总了C++中VarRefDestroy函数的典型用法代码示例。如果您正苦于以下问题:C++ VarRefDestroy函数的具体用法?C++ VarRefDestroy怎么用?C++ VarRefDestroy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VarRefDestroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_expand_list_nested
static void test_expand_list_nested(void **state)
{
EvalContext *ctx = *state;
{
VarRef *lval = VarRefParse("default:bundle.i");
EvalContextVariablePut(ctx, lval, "one", CF_DATA_TYPE_STRING, NULL);
VarRefDestroy(lval);
}
{
VarRef *lval = VarRefParse("default:bundle.inner[one]");
Rlist *list = NULL;
RlistAppendScalar(&list, "foo");
EvalContextVariablePut(ctx, lval, list, CF_DATA_TYPE_STRING_LIST, NULL);
RlistDestroy(list);
VarRefDestroy(lval);
}
Rlist *outer = NULL;
RlistAppendScalar(&outer, "@{inner[$(i)]}");
Rlist *expanded = ExpandList(ctx, "default", "bundle", outer, true);
assert_int_equal(1, RlistLen(expanded));
assert_string_equal("foo", RlistScalarValue(expanded));
RlistDestroy(outer);
RlistDestroy(expanded);
}
示例2: test_remove
static void test_remove(void)
{
VariableTable *t = ReferenceTable();
{
VarRef *ref = VarRefParse("scope1.array[one]");
assert_true(VariableTableRemove(t, ref));
assert_true(VariableTableGet(t, ref) == NULL);
assert_false(VariableTableRemove(t, ref));
assert_int_equal(11, VariableTableCount(t, NULL, NULL, NULL));
VarRefDestroy(ref);
}
{
VarRef *ref = VarRefParse("ns1:scope1.lval1");
assert_true(VariableTableRemove(t, ref));
assert_true(VariableTableGet(t, ref) == NULL);
assert_false(VariableTableRemove(t, ref));
assert_int_equal(10, VariableTableCount(t, NULL, NULL, NULL));
VarRefDestroy(ref);
}
VariableTableDestroy(t);
}
示例3: test_iterate_indices
static void test_iterate_indices(void)
{
VariableTable *t = ReferenceTable();
{
VarRef *ref = VarRefParse("default:scope1.array");
VariableTableIterator *iter = VariableTableIteratorNewFromVarRef(t, ref);
unsigned short number_of_entries = 0;
while (VariableTableIteratorNext(iter))
{
number_of_entries++;
}
assert_int_equal(4, number_of_entries);
VariableTableIteratorDestroy(iter);
VarRefDestroy(ref);
}
{
VarRef *ref = VarRefParse("default:scope1.array[two]");
VariableTableIterator *iter = VariableTableIteratorNewFromVarRef(t, ref);
unsigned short number_of_entries = 0;
while (VariableTableIteratorNext(iter))
{
number_of_entries++;
}
assert_int_equal(3, number_of_entries);
VariableTableIteratorDestroy(iter);
VarRefDestroy(ref);
}
}
示例4: GetReturnValue
static void GetReturnValue(EvalContext *ctx, const Bundle *callee, const Promise *caller)
{
char *result = PromiseGetConstraintAsRval(caller, "useresult", RVAL_TYPE_SCALAR);
if (result)
{
VarRef *ref = VarRefParseFromBundle("last-result", callee);
VariableTableIterator *iter = EvalContextVariableTableIteratorNew(ctx, ref->ns, ref->scope, ref->lval);
Variable *result_var = NULL;
while ((result_var = VariableTableIteratorNext(iter)))
{
assert(result_var->ref->num_indices == 1);
if (result_var->ref->num_indices != 1)
{
continue;
}
VarRef *new_ref = VarRefParseFromBundle(result, PromiseGetBundle(caller));
VarRefAddIndex(new_ref, result_var->ref->indices[0]);
EvalContextVariablePut(ctx, new_ref, result_var->rval.item, result_var->type, "source=bundle");
VarRefDestroy(new_ref);
}
VarRefDestroy(ref);
VariableTableIteratorDestroy(iter);
}
}
示例5: test_expand_promise_array_with_scalar_arg
static void test_expand_promise_array_with_scalar_arg(void **state)
{
EvalContext *ctx = *state;
{
VarRef *lval = VarRefParse("default:bundle.foo[one]");
EvalContextVariablePut(ctx, lval, "first", CF_DATA_TYPE_STRING, NULL);
VarRefDestroy(lval);
}
{
VarRef *lval = VarRefParse("default:bundle.bar");
EvalContextVariablePut(ctx, lval, "one", CF_DATA_TYPE_STRING, NULL);
VarRefDestroy(lval);
}
Policy *policy = PolicyNew();
Bundle *bundle = PolicyAppendBundle(policy, NamespaceDefault(), "bundle", "agent", NULL, NULL);
PromiseType *promise_type = BundleAppendPromiseType(bundle, "dummy");
Promise *promise = PromiseTypeAppendPromise(promise_type, "$(foo[$(bar)])", (Rval) { NULL, RVAL_TYPE_NOPROMISEE }, "any", NULL);
EvalContextStackPushBundleFrame(ctx, bundle, NULL, false);
EvalContextStackPushPromiseTypeFrame(ctx, promise_type);
ExpandPromise(ctx, promise, actuator_expand_promise_array_with_scalar_arg, NULL);
EvalContextStackPopFrame(ctx);
EvalContextStackPopFrame(ctx);
PolicyDestroy(policy);
}
示例6: xmalloc
PromiseIterator *PromiseIteratorNew(EvalContext *ctx, const Promise *pp, const Rlist *lists, const Rlist *containers)
{
PromiseIterator *iter = xmalloc(sizeof(PromiseIterator));
iter->vars = SeqNew(RlistLen(lists), DeleteAssoc);
iter->var_states = SeqNew(RlistLen(lists), NULL);
iter->has_null_list = false;
for (const Rlist *rp = lists; rp != NULL; rp = rp->next)
{
VarRef *ref = VarRefParseFromBundle(RlistScalarValue(rp), PromiseGetBundle(pp));
DataType dtype = CF_DATA_TYPE_NONE;
const void *value = EvalContextVariableGet(ctx, ref, &dtype);
if (!value)
{
Log(LOG_LEVEL_ERR, "Couldn't locate variable '%s' apparently in '%s'", RlistScalarValue(rp), PromiseGetBundle(pp)->name);
VarRefDestroy(ref);
continue;
}
VarRefDestroy(ref);
CfAssoc *new_var = NewAssoc(RlistScalarValue(rp), (Rval) { (void *)value, DataTypeToRvalType(dtype) }, dtype);
iter->has_null_list |= !AppendIterationVariable(iter, new_var);
}
for (const Rlist *rp = containers; rp; rp = rp->next)
{
VarRef *ref = VarRefParseFromBundle(RlistScalarValue(rp), PromiseGetBundle(pp));
DataType dtype = CF_DATA_TYPE_NONE;
const JsonElement *value = EvalContextVariableGet(ctx, ref, &dtype);
if (!value)
{
Log(LOG_LEVEL_ERR, "Couldn't locate variable '%s' apparently in '%s'", RlistScalarValue(rp), PromiseGetBundle(pp)->name);
VarRefDestroy(ref);
continue;
}
VarRefDestroy(ref);
assert(dtype == CF_DATA_TYPE_CONTAINER);
/* Mimics NewAssoc() but bypassing extra copying of ->rval: */
CfAssoc *new_var = xmalloc(sizeof(CfAssoc));
new_var->lval = xstrdup(RlistScalarValue(rp));
new_var->rval = (Rval) { ContainerToRlist(value), RVAL_TYPE_LIST };
new_var->dtype = CF_DATA_TYPE_STRING_LIST;
iter->has_null_list |= !AppendIterationVariable(iter, new_var);
}
// We now have a control list of list-variables, with internal state in state_ptr
return iter;
}
示例7: CopyLocalizedReferencesToBundleScope
static void CopyLocalizedReferencesToBundleScope(EvalContext *ctx,
const Bundle *bundle,
const Rlist *ref_names)
{
for (const Rlist *rp = ref_names; rp != NULL; rp = rp->next)
{
const char *mangled = RlistScalarValue(rp);
char *demangled = xstrdup(mangled);
DeMangleVarRefString(demangled, strlen(demangled));
if (strchr(RlistScalarValue(rp), CF_MAPPEDLIST))
{
VarRef *demangled_ref = VarRefParseFromBundle(demangled, bundle);
DataType value_type;
const void *value = EvalContextVariableGet(ctx, demangled_ref, &value_type);
if (!value)
{
ProgrammingError("Couldn't find extracted variable '%s'", mangled);
}
VarRef *mangled_ref = VarRefParseFromBundle(mangled, bundle);
switch (DataTypeToRvalType(value_type))
{
case RVAL_TYPE_LIST:
{
Rlist *list = RlistCopy(value);
RlistFlatten(ctx, &list);
EvalContextVariablePut(ctx, mangled_ref, list, value_type, "source=agent");
RlistDestroy(list);
}
break;
case RVAL_TYPE_CONTAINER:
case RVAL_TYPE_SCALAR:
EvalContextVariablePut(ctx, mangled_ref, value, value_type, "source=agent");
break;
case RVAL_TYPE_FNCALL:
case RVAL_TYPE_NOPROMISEE:
ProgrammingError("Illegal rval type in switch %d", DataTypeToRvalType(value_type));
}
VarRefDestroy(mangled_ref);
VarRefDestroy(demangled_ref);
}
free(demangled);
}
}
示例8: RunCmpCommand
static VersionCmpResult RunCmpCommand(EvalContext *ctx, const char *command, const char *v1, const char *v2, Attributes a,
const Promise *pp, PromiseResult *result)
{
Buffer *expanded_command = BufferNew();
{
VarRef *ref_v1 = VarRefParseFromScope("v1", PACKAGES_CONTEXT);
EvalContextVariablePut(ctx, ref_v1, v1, CF_DATA_TYPE_STRING, "source=promise");
VarRef *ref_v2 = VarRefParseFromScope("v2", PACKAGES_CONTEXT);
EvalContextVariablePut(ctx, ref_v2, v2, CF_DATA_TYPE_STRING, "source=promise");
ExpandScalar(ctx, NULL, PACKAGES_CONTEXT, command, expanded_command);
EvalContextVariableRemove(ctx, ref_v1);
VarRefDestroy(ref_v1);
EvalContextVariableRemove(ctx, ref_v2);
VarRefDestroy(ref_v2);
}
FILE *pfp = a.packages.package_commands_useshell ? cf_popen_sh(BufferData(expanded_command), "w") : cf_popen(BufferData(expanded_command), "w", true);
if (pfp == NULL)
{
cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Can not start package version comparison command '%s'. (cf_popen: %s)",
BufferData(expanded_command), GetErrorStr());
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
BufferDestroy(expanded_command);
return VERCMP_ERROR;
}
Log(LOG_LEVEL_VERBOSE, "Executing '%s'", BufferData(expanded_command));
int retcode = cf_pclose(pfp);
if (retcode == -1)
{
cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Error during package version comparison command execution '%s'. (cf_pclose: %s)",
BufferData(expanded_command), GetErrorStr());
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
BufferDestroy(expanded_command);
return VERCMP_ERROR;
}
BufferDestroy(expanded_command);
return retcode == 0;
}
示例9: test_expand_promise_slist
static void test_expand_promise_slist(void **state)
{
actuator_state = 0;
EvalContext *ctx = *state;
{
VarRef *lval = VarRefParse("default:bundle.foo");
Rlist *list = NULL;
RlistAppendScalar(&list, "a");
RlistAppendScalar(&list, "b");
EvalContextVariablePut(ctx, lval, list, CF_DATA_TYPE_STRING_LIST, NULL);
RlistDestroy(list);
VarRefDestroy(lval);
}
Policy *policy = PolicyNew();
Bundle *bundle = PolicyAppendBundle(policy, NamespaceDefault(), "bundle", "agent", NULL, NULL);
PromiseType *promise_type = BundleAppendPromiseType(bundle, "dummy");
Promise *promise = PromiseTypeAppendPromise(promise_type, "$(foo)", (Rval) { NULL, RVAL_TYPE_NOPROMISEE }, "any", NULL);
EvalContextStackPushBundleFrame(ctx, bundle, NULL, false);
EvalContextStackPushPromiseTypeFrame(ctx, promise_type);
ExpandPromise(ctx, promise, actuator_expand_promise_slist, NULL);
EvalContextStackPopFrame(ctx);
EvalContextStackPopFrame(ctx);
assert_int_equal(2, actuator_state);
PolicyDestroy(policy);
}
示例10: ExpandListEntry
static Rval ExpandListEntry(EvalContext *ctx,
const char *ns, const char *scope,
int expandnaked, Rval entry)
{
if (entry.type == RVAL_TYPE_SCALAR &&
IsNakedVar(entry.item, '@'))
{
if (expandnaked)
{
char naked[CF_MAXVARSIZE];
GetNaked(naked, entry.item);
if (!IsExpandable(naked))
{
VarRef *ref = VarRefParseFromScope(naked, scope);
DataType value_type = CF_DATA_TYPE_NONE;
const void *value = EvalContextVariableGet(ctx, ref, &value_type);
VarRefDestroy(ref);
if (value)
{
return ExpandPrivateRval(ctx, ns, scope, value,
DataTypeToRvalType(value_type));
}
}
}
else
{
return RvalNew(entry.item, RVAL_TYPE_SCALAR);
}
}
return ExpandPrivateRval(ctx, ns, scope, entry.item, entry.type);
}
示例11: PutVar
static bool PutVar(VariableTable *table, char *var_str)
{
VarRef *ref = VarRefParse(var_str);
Rval rval = (Rval) { var_str, RVAL_TYPE_SCALAR };
bool ret = VariableTablePut(table, ref, &rval, CF_DATA_TYPE_STRING, NULL, NULL);
VarRefDestroy(ref);
return ret;
}
示例12: VariableTableNew
static VariableTable *ReferenceTable(void)
{
VariableTable *t = VariableTableNew();
assert_false(PutVar(t, "scope1.lval1"));
assert_false(PutVar(t, "scope1.lval2"));
assert_false(PutVar(t, "scope2.lval1"));
{
VarRef *ref = VarRefParse("scope1.array[one]");
Rval rval = (Rval) {
"scope1.array[one]", RVAL_TYPE_SCALAR
};
assert_false(VariableTablePut(t, ref, &rval, DATA_TYPE_STRING, NULL, NULL));
VarRefDestroy(ref);
}
{
VarRef *ref = VarRefParse("scope1.array[two]");
Rval rval = (Rval) {
"scope1.array[two]", RVAL_TYPE_SCALAR
};
assert_false(VariableTablePut(t, ref, &rval, DATA_TYPE_STRING, NULL, NULL));
VarRefDestroy(ref);
}
{
VarRef *ref = VarRefParse("scope1.array[two][three]");
Rval rval = (Rval) {
"scope1.array[two][three]", RVAL_TYPE_SCALAR
};
assert_false(VariableTablePut(t, ref, &rval, DATA_TYPE_STRING, NULL, NULL));
VarRefDestroy(ref);
}
{
VarRef *ref = VarRefParse("scope1.array[two][four]");
Rval rval = (Rval) {
"scope1.array[two][four]", RVAL_TYPE_SCALAR
};
assert_false(VariableTablePut(t, ref, &rval, DATA_TYPE_STRING, NULL, NULL));
VarRefDestroy(ref);
}
assert_false(PutVar(t, "ns1:scope1.lval1"));
assert_false(PutVar(t, "ns1:scope1.lval2"));
assert_false(PutVar(t, "ns1:scope2.lval1"));
return t;
}
示例13: CheckToString
static void CheckToString(const char *str)
{
VarRef ref = VarRefParse(str);
char *out = VarRefToString(ref);
assert_string_equal(str, out);
free(out);
VarRefDestroy(ref);
}
示例14: KeepPromises
static void KeepPromises(EvalContext *ctx, const Policy *policy)
{
Rval retval;
Seq *constraints = ControlBodyConstraints(policy, AGENT_TYPE_MONITOR);
if (constraints)
{
for (size_t i = 0; i < SeqLength(constraints); i++)
{
Constraint *cp = SeqAt(constraints, i);
if (!IsDefinedClass(ctx, cp->classes, NULL))
{
continue;
}
VarRef *ref = VarRefParseFromScope(cp->lval, "control_monitor");
if (!EvalContextVariableGet(ctx, ref, &retval, NULL))
{
Log(LOG_LEVEL_ERR, "Unknown lval '%s' in monitor control body", cp->lval);
VarRefDestroy(ref);
continue;
}
VarRefDestroy(ref);
if (strcmp(cp->lval, CFM_CONTROLBODY[MONITOR_CONTROL_HISTOGRAMS].lval) == 0)
{
/* Keep accepting this option for backward compatibility. */
}
if (strcmp(cp->lval, CFM_CONTROLBODY[MONITOR_CONTROL_TCP_DUMP].lval) == 0)
{
MonNetworkSnifferEnable(BooleanFromString(retval.item));
}
if (strcmp(cp->lval, CFM_CONTROLBODY[MONITOR_CONTROL_FORGET_RATE].lval) == 0)
{
sscanf(retval.item, "%lf", &FORGETRATE);
Log(LOG_LEVEL_DEBUG, "forget rate %f", FORGETRATE);
}
}
}
}
示例15: TestGet
static void TestGet(VariableTable *t, const char *ref_str)
{
VarRef *ref = VarRefParse(ref_str);
Variable *v = VariableTableGet(t, ref);
assert_true(v != NULL);
assert_int_equal(0, VarRefCompare(ref, v->ref));
assert_string_equal(ref_str, RvalScalarValue(v->rval));
VarRefDestroy(ref);
}