Skip to content

Commit

Permalink
lone: fix unknown auxiliary value handling
Browse files Browse the repository at this point in the history
This function would overwrite existing unknown auxiliary values.
Fix it by placing them in a subtable. Also only assign that table
to the unknown key of the main table if unknown values were found.
This allows it to be garbage collected later if it's not needed.
  • Loading branch information
matheusmoreira committed Dec 3, 2023
1 parent cc769b8 commit 2fd118d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions source/lone/modules/intrinsic/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <lone/linux.h>

static void lone_auxiliary_value_to_table(struct lone_lisp *lone, struct lone_value *table, struct lone_auxiliary_vector *auxiliary)
static void lone_auxiliary_value_to_table(struct lone_lisp *lone, struct lone_value *table, struct lone_value *unknowns, struct lone_auxiliary_vector *auxiliary)
{
struct lone_value *key, *value;

Expand Down Expand Up @@ -117,10 +117,10 @@ static void lone_auxiliary_value_to_table(struct lone_lisp *lone, struct lone_va
value = lone_integer_create(lone, auxiliary->value.as.integer);
break;
default:
key = lone_intern_c_string(lone, "unknown");
value = lone_list_create(lone,
lone_integer_create(lone, auxiliary->type),
lone_integer_create(lone, auxiliary->value.as.integer));
key = lone_integer_create(lone, auxiliary->type);
value = lone_integer_create(lone, auxiliary->value.as.integer);
lone_table_set(lone, unknowns, key, value);
return;
}

lone_table_set(lone, table, key, value);
Expand All @@ -129,10 +129,15 @@ static void lone_auxiliary_value_to_table(struct lone_lisp *lone, struct lone_va
static struct lone_value *lone_auxiliary_vector_to_table(struct lone_lisp *lone, struct lone_auxiliary_vector *auxiliary_vector)
{
struct lone_value *table = lone_table_create(lone, 32, 0);
struct lone_value *unknowns = lone_table_create(lone, 2, 0);
size_t i;

for (i = 0; auxiliary_vector[i].type != AT_NULL; ++i) {
lone_auxiliary_value_to_table(lone, table, &auxiliary_vector[i]);
lone_auxiliary_value_to_table(lone, table, unknowns, &auxiliary_vector[i]);
}

if (unknowns->table.count) {
lone_table_set(lone, table, lone_intern_c_string(lone, "unknown"), unknowns);
}

return table;
Expand Down

0 comments on commit 2fd118d

Please sign in to comment.