matcher: Fix relying on GC'ed milist in deinit function
When the GC calls the matchers deinit function, the milist (also an GC-able object) might already have been deinitialized, so we can't use the count values from there. Maybe milist should actually be refcounted? It doesn't build cycles and doesn't reference other GC objects. This would simplify it and remove the now duplicated count data.
This commit is contained in:
parent
6d77715e0d
commit
42fe4f6b33
2 changed files with 8 additions and 2 deletions
|
|
@ -24,6 +24,8 @@ apfl_matcher_new(struct gc *gc, struct matcher_instruction_list *milist)
|
|||
{
|
||||
struct matcher matcher = {
|
||||
.instructions = milist,
|
||||
.value_count = 0,
|
||||
.capture_count = 0,
|
||||
.values = NULL,
|
||||
.captures = NULL,
|
||||
.result = false,
|
||||
|
|
@ -32,10 +34,12 @@ apfl_matcher_new(struct gc *gc, struct matcher_instruction_list *milist)
|
|||
if (!init_values_list(gc->allocator, &matcher.values, milist->value_count)) {
|
||||
goto error;
|
||||
}
|
||||
matcher.value_count = milist->value_count;
|
||||
|
||||
if (!init_values_list(gc->allocator, &matcher.captures, milist->capture_count)) {
|
||||
goto error;
|
||||
}
|
||||
matcher.capture_count = milist->capture_count;
|
||||
|
||||
struct matcher *gc_matcher = apfl_gc_new_matcher(gc);
|
||||
if (gc_matcher == NULL) {
|
||||
|
|
@ -54,8 +58,8 @@ error:
|
|||
void
|
||||
apfl_matcher_deinit(struct apfl_allocator allocator, struct matcher *matcher)
|
||||
{
|
||||
FREE_LIST(allocator, matcher->values, matcher->instructions->value_count);
|
||||
FREE_LIST(allocator, matcher->captures, matcher->instructions->capture_count);
|
||||
FREE_LIST(allocator, matcher->values, matcher->value_count);
|
||||
FREE_LIST(allocator, matcher->captures, matcher->capture_count);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ extern "C" {
|
|||
|
||||
struct matcher {
|
||||
struct matcher_instruction_list *instructions;
|
||||
size_t value_count;
|
||||
size_t capture_count;
|
||||
struct apfl_value *values;
|
||||
struct apfl_value *captures;
|
||||
bool result;
|
||||
|
|
|
|||
Loading…
Reference in a new issue