diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-05-06 23:14:57 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-05-06 23:14:57 -0400 |
| commit | 1b89eea1cf6126a2f80f51dcc83782ce70265f7e (patch) | |
| tree | ac53bc3b6960c524ff7d1e8649dc6fa14f27694f /src/stdlib/tables.c | |
| parent | a63a7383a3aa25f1562464c94c356b7aacbbb0a6 (diff) | |
Bugfix for serialization of sets and tables with fallbacks
Diffstat (limited to 'src/stdlib/tables.c')
| -rw-r--r-- | src/stdlib/tables.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c index 061c3391..8e3afe45 100644 --- a/src/stdlib/tables.c +++ b/src/stdlib/tables.c @@ -767,10 +767,13 @@ public void Table$serialize(const void *obj, FILE *out, Table_t *pointers, const size_t offset = value_offset(type); for (int64_t i = 0; i < len; i++) { _serialize(t->entries.data + i*t->entries.stride, out, pointers, type->TableInfo.key); - _serialize(t->entries.data + i*t->entries.stride + offset, out, pointers, type->TableInfo.value); + if (type->TableInfo.value->size > 0) + _serialize(t->entries.data + i*t->entries.stride + offset, out, pointers, type->TableInfo.value); } - Optional$serialize(&t->fallback, out, pointers, Optional$info(sizeof(void*), __alignof__(void*), Pointer$info("&", type))); + assert(fputc(t->fallback != NULL ? 1 : 0, out) != EOF); + if (t->fallback) + Table$serialize(t->fallback, out, pointers, type); } #ifdef __GNUC__ @@ -787,11 +790,15 @@ public void Table$deserialize(FILE *in, void *outval, List_t *pointers, const Ty char key[type->TableInfo.key->size]; _deserialize(in, key, pointers, type->TableInfo.key); char value[type->TableInfo.value->size]; - _deserialize(in, value, pointers, type->TableInfo.value); + if (type->TableInfo.value->size > 0) + _deserialize(in, value, pointers, type->TableInfo.value); Table$set(&t, key, value, type); } - Optional$deserialize(in, &t.fallback, pointers, Optional$info(sizeof(void*), __alignof__(void*), Pointer$info("&", type))); + if (fgetc(in) != 0) { + t.fallback = GC_MALLOC(sizeof(Table_t)); + Table$deserialize(in, t.fallback, pointers, type); + } *(Table_t*)outval = t; } |
