summaryrefslogtreecommitdiff
path: root/imemo.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2025-08-26 09:19:07 +0200
committerJean Boussier <jean.boussier@gmail.com>2025-08-26 13:44:59 +0200
commit14bdf4b57dcd3169a8717dc893fd1e1be897deeb (patch)
treecf7e21a3c2f7d6bd9fa53788b3bbecd2c2a3ea80 /imemo.c
parent59c996797e16f45a3b91baa04083c2da3a1edfcb (diff)
Ensure T_OBJECT and T_IMEMO/fields have identical layout
Diffstat (limited to 'imemo.c')
-rw-r--r--imemo.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/imemo.c b/imemo.c
index 2fde22a3db..b4ca1fdced 100644
--- a/imemo.c
+++ b/imemo.c
@@ -116,11 +116,11 @@ imemo_fields_new(VALUE owner, size_t capa)
if (rb_gc_size_allocatable_p(embedded_size)) {
VALUE fields = rb_imemo_new(imemo_fields, owner, embedded_size);
RUBY_ASSERT(IMEMO_TYPE_P(fields, imemo_fields));
+ FL_SET_RAW(fields, OBJ_FIELD_EMBED);
return fields;
}
else {
VALUE fields = rb_imemo_new(imemo_fields, owner, sizeof(struct rb_fields));
- FL_SET_RAW(fields, OBJ_FIELD_EXTERNAL);
IMEMO_OBJ_FIELDS(fields)->as.external.ptr = ALLOC_N(VALUE, capa);
return fields;
}
@@ -135,8 +135,9 @@ rb_imemo_fields_new(VALUE owner, size_t capa)
static VALUE
imemo_fields_new_complex(VALUE owner, size_t capa)
{
- VALUE fields = imemo_fields_new(owner, sizeof(struct rb_fields));
+ VALUE fields = imemo_fields_new(owner, 1);
IMEMO_OBJ_FIELDS(fields)->as.complex.table = st_init_numtable_with_size(capa);
+ FL_UNSET_RAW(fields, OBJ_FIELD_EMBED);
return fields;
}
@@ -165,6 +166,7 @@ VALUE
rb_imemo_fields_new_complex_tbl(VALUE owner, st_table *tbl)
{
VALUE fields = imemo_fields_new(owner, sizeof(struct rb_fields));
+ FL_UNSET_RAW(fields, OBJ_FIELD_EMBED);
IMEMO_OBJ_FIELDS(fields)->as.complex.table = tbl;
st_foreach(tbl, imemo_fields_trigger_wb_i, (st_data_t)fields);
return fields;
@@ -258,7 +260,7 @@ rb_imemo_memsize(VALUE obj)
if (rb_shape_obj_too_complex_p(obj)) {
size += st_memsize(IMEMO_OBJ_FIELDS(obj)->as.complex.table);
}
- else if (FL_TEST_RAW(obj, OBJ_FIELD_EXTERNAL)) {
+ else if (!FL_TEST_RAW(obj, OBJ_FIELD_EMBED)) {
size += RSHAPE_CAPACITY(RBASIC_SHAPE_ID(obj)) * sizeof(VALUE);
}
break;
@@ -536,7 +538,7 @@ imemo_fields_free(struct rb_fields *fields)
if (rb_shape_obj_too_complex_p((VALUE)fields)) {
st_free_table(fields->as.complex.table);
}
- else if (FL_TEST_RAW((VALUE)fields, OBJ_FIELD_EXTERNAL)) {
+ else if (!FL_TEST_RAW((VALUE)fields, OBJ_FIELD_EMBED)) {
xfree(fields->as.external.ptr);
}
}