summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2025-09-25 05:50:05 +0900
committerKoichi Sasada <ko1@atdot.net>2025-10-23 13:08:26 +0900
commitbc00c4468e0054ca896d2b83d3020180915f64cf (patch)
tree3942c12dbba8254925400f16c022661dcbb7ffb0 /variable.c
parent45907b1b00d09ce2c40f5073ff540d8b63217d96 (diff)
use `SET_SHAREABLE`
to adopt strict shareable rule. * (basically) shareable objects only refer shareable objects * (exception) shareable objects can refere unshareable objects but should not leak reference to unshareable objects to Ruby world
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/variable.c b/variable.c
index 5fc98fb087..bab423e950 100644
--- a/variable.c
+++ b/variable.c
@@ -321,6 +321,7 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name)
}
name = rb_str_new_frozen(name);
+ RB_OBJ_SET_SHAREABLE(name);
// Set the temporary classpath to the given name:
RB_VM_LOCKING() {
@@ -432,6 +433,7 @@ rb_set_class_path_string(VALUE klass, VALUE under, VALUE name)
str = build_const_pathname(str, name);
}
+ RB_OBJ_SET_SHAREABLE(str);
RCLASS_SET_CLASSPATH(klass, str, permanent);
}
@@ -1552,7 +1554,7 @@ obj_transition_too_complex(VALUE obj, st_table *table)
break;
default:
{
- VALUE fields_obj = rb_imemo_fields_new_complex_tbl(obj, table);
+ VALUE fields_obj = rb_imemo_fields_new_complex_tbl(obj, table, RB_OBJ_SHAREABLE_P(obj));
RBASIC_SET_SHAPE_ID(fields_obj, shape_id);
rb_obj_replace_fields(obj, fields_obj);
}
@@ -1731,7 +1733,7 @@ static VALUE
imemo_fields_complex_from_obj(VALUE owner, VALUE source_fields_obj, shape_id_t shape_id)
{
attr_index_t len = source_fields_obj ? RSHAPE_LEN(RBASIC_SHAPE_ID(source_fields_obj)) : 0;
- VALUE fields_obj = rb_imemo_fields_new_complex(owner, len + 1);
+ VALUE fields_obj = rb_imemo_fields_new_complex(owner, len + 1, RB_OBJ_SHAREABLE_P(owner));
rb_field_foreach(source_fields_obj, imemo_fields_complex_from_obj_i, (st_data_t)fields_obj, false);
RBASIC_SET_SHAPE_ID(fields_obj, shape_id);
@@ -1742,7 +1744,7 @@ imemo_fields_complex_from_obj(VALUE owner, VALUE source_fields_obj, shape_id_t s
static VALUE
imemo_fields_copy_capa(VALUE owner, VALUE source_fields_obj, attr_index_t new_size)
{
- VALUE fields_obj = rb_imemo_fields_new(owner, new_size);
+ VALUE fields_obj = rb_imemo_fields_new(owner, new_size, RB_OBJ_SHAREABLE_P(owner));
if (source_fields_obj) {
attr_index_t fields_count = RSHAPE_LEN(RBASIC_SHAPE_ID(source_fields_obj));
VALUE *fields = rb_imemo_fields_ptr(fields_obj);
@@ -2227,7 +2229,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
return;
}
- new_fields_obj = rb_imemo_fields_new(dest, RSHAPE_CAPACITY(dest_shape_id));
+ new_fields_obj = rb_imemo_fields_new(dest, RSHAPE_CAPACITY(dest_shape_id), RB_OBJ_SHAREABLE_P(dest));
VALUE *src_buf = rb_imemo_fields_ptr(fields_obj);
VALUE *dest_buf = rb_imemo_fields_ptr(new_fields_obj);
rb_shape_copy_fields(new_fields_obj, dest_buf, dest_shape_id, src_buf, src_shape_id);
@@ -3797,6 +3799,7 @@ static void
set_namespace_path(VALUE named_namespace, VALUE namespace_path)
{
struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace);
+ RB_OBJ_SET_SHAREABLE(namespace_path);
RB_VM_LOCKING() {
RCLASS_WRITE_CLASSPATH(named_namespace, namespace_path, true);
@@ -3875,7 +3878,8 @@ const_set(VALUE klass, ID id, VALUE val)
set_namespace_path(val, build_const_path(parental_path, id));
}
else if (!parental_path_permanent && NIL_P(val_path)) {
- RCLASS_SET_CLASSPATH(val, build_const_path(parental_path, id), false);
+ VALUE path = build_const_path(parental_path, id);
+ RCLASS_SET_CLASSPATH(val, path, false);
}
}
}
@@ -4488,7 +4492,7 @@ static attr_index_t
class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool concurrent, VALUE *new_fields_obj, bool *new_ivar_out)
{
const VALUE original_fields_obj = fields_obj;
- fields_obj = original_fields_obj ? original_fields_obj : rb_imemo_fields_new(klass, 1);
+ fields_obj = original_fields_obj ? original_fields_obj : rb_imemo_fields_new(klass, 1, true);
shape_id_t current_shape_id = RBASIC_SHAPE_ID(fields_obj);
shape_id_t next_shape_id = current_shape_id; // for too_complex