}
/* Caller must make sure id is allocated */
-int expr__add_id_val(struct expr_parse_ctx *ctx, const char *name, double val)
+int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val)
{
- double *val_ptr = NULL, *old_val = NULL;
+ struct expr_id_data *data_ptr = NULL, *old_data = NULL;
char *old_key = NULL;
int ret;
if (val != 0.0) {
- val_ptr = malloc(sizeof(double));
- if (!val_ptr)
+ data_ptr = malloc(sizeof(*data_ptr));
+ if (!data_ptr)
return -ENOMEM;
- *val_ptr = val;
+ data_ptr->val = val;
}
- ret = hashmap__set(&ctx->ids, name, val_ptr,
- (const void **)&old_key, (void **)&old_val);
+ ret = hashmap__set(&ctx->ids, id, data_ptr,
+ (const void **)&old_key, (void **)&old_data);
free(old_key);
- free(old_val);
+ free(old_data);
return ret;
}
int expr__get_id(struct expr_parse_ctx *ctx, const char *id, double *val_ptr)
{
- double *data;
+ struct expr_id_data *data;
if (!hashmap__find(&ctx->ids, id, (void **)&data))
return -1;
- *val_ptr = (data == NULL) ? 0.0 : *data;
+ *val_ptr = (data == NULL) ? 0.0 : data->val;
return 0;
}
int expr__find_other(const char *expr, const char *one,
struct expr_parse_ctx *ctx, int runtime)
{
- double *old_val = NULL;
+ struct expr_id_data *old_val = NULL;
char *old_key = NULL;
int ret = __expr__parse(NULL, ctx, expr, EXPR_OTHER, runtime);
unsigned long *evlist_used)
{
struct evsel *ev, *current_leader = NULL;
- double *val_ptr;
+ struct expr_id_data *val_ptr;
int i = 0, matched_events = 0, events_to_match;
const int idnum = (int)hashmap__size(&pctx->ids);