diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-12-22 15:31:58 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-12-22 15:31:58 -0500 |
| commit | 2a12cb869ba7ae81513e771bb0dab670a80f0e32 (patch) | |
| tree | 185d04899cbe0cf69ce6aa1195e53d51e54ea3b1 /stdlib | |
| parent | 46b61d3ed2ae5bd5f74c9d580f5501b1226d9f4e (diff) | |
Bugfixes for table updates and array concat updates
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/structs.c | 10 | ||||
| -rw-r--r-- | stdlib/tables.h | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/stdlib/structs.c b/stdlib/structs.c index 624fe933..46fd9d14 100644 --- a/stdlib/structs.c +++ b/stdlib/structs.c @@ -25,7 +25,7 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type) if (type->StructInfo.num_fields == 1) return generic_hash(obj, type->StructInfo.fields[0].type); - uint32_t field_hashes[type->StructInfo.num_fields] = {}; + uint64_t field_hashes[type->StructInfo.num_fields] = {}; ptrdiff_t byte_offset = 0; ptrdiff_t bit_offset = 0; for (int i = 0; i < type->StructInfo.num_fields; i++) { @@ -45,7 +45,13 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type) } if (field.type->align && byte_offset % field.type->align > 0) byte_offset += field.type->align - (byte_offset % field.type->align); - field_hashes[i] = generic_hash(obj + byte_offset, field.type); + + if (field.type->metamethods.hash == NULL && (size_t)field.type->size < sizeof(uint64_t)) { + memcpy(&field_hashes[i], obj + byte_offset, (size_t)field.type->size); + } else { + field_hashes[i] = generic_hash(obj + byte_offset, field.type); + } + byte_offset += field.type->size; } } diff --git a/stdlib/tables.h b/stdlib/tables.h index 50ecc453..405cc7df 100644 --- a/stdlib/tables.h +++ b/stdlib/tables.h @@ -36,7 +36,7 @@ void *Table$get(Table_t t, const void *key, const TypeInfo_t *type); val_t *nonnull_var = Table$get(t, &k, info_expr); \ nonnull_var ? nonnull_expr : null_expr; }) #define Table$get_or_setdefault(table_expr, key_t, val_t, key_expr, default_expr, info_expr) ({ \ - Table_t *t = &table_expr; const key_t k = key_expr; \ + Table_t *t = table_expr; const key_t k = key_expr; \ val_t *v = Table$get(*t, &k, info_expr); \ v ? v : (val_t*)Table$reserve(t, &k, (val_t[1]){default_expr}, info_expr); }) #define Table$get_or_default(table_expr, key_t, val_t, key_expr, default_expr, info_expr) ({ \ |
