Skip to content

Commit

Permalink
lib/filterx: refactor _pull_variable_from_message
Browse files Browse the repository at this point in the history
The variable registration should not be _pull's responsibility.

Signed-off-by: Szilard Parrag <[email protected]>
  • Loading branch information
OverOrion committed Oct 10, 2024
1 parent fb32316 commit 1fc9f8e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/filterx/expr-variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ _pull_variable_from_message(FilterXVariableExpr *self, FilterXEvalContext *conte
return NULL;
}

FilterXObject *msg_ref;
if (log_msg_is_value_from_macro(value))
msg_ref = filterx_message_value_new(value, value_len, t);
return filterx_message_value_new(value, value_len, t);
else
msg_ref = filterx_message_value_new_borrowed(value, value_len, t);

filterx_scope_register_variable(context->scope, self->handle, msg_ref);
return msg_ref;
return filterx_message_value_new_borrowed(value, value_len, t);
}

/* NOTE: unset on a variable that only exists in the LogMessage, without making the message writable */
Expand Down Expand Up @@ -84,7 +80,14 @@ _eval(FilterXExpr *s)
}

if (!filterx_variable_handle_is_floating(self->handle))
return _pull_variable_from_message(self, context, context->msgs[0]);
{
FilterXObject *msg_ref = _pull_variable_from_message(self, context, context->msgs[0]);
if(!msg_ref)
return NULL;
filterx_scope_register_variable(context->scope, self->handle, msg_ref);
return msg_ref;
}
error:
filterx_eval_push_error("No such variable", s, self->variable_name);
return NULL;
}
Expand Down

0 comments on commit 1fc9f8e

Please sign in to comment.