Skip to content

Commit

Permalink
Eliminate usage of OBJ_FREEZE_RAW
Browse files Browse the repository at this point in the history
Previously it would bypass the `FL_ABLE` check, but
since shapes introduction, it started having a different
behavior than `OBJ_FREEZE`, as it would onyl set the `FL_FREEZE`
flag, but not update the shape.

I have no indication of this causing a bug yet, but it seems
like a trap waiting to happen.
  • Loading branch information
byroot committed Apr 16, 2024
1 parent 7380e3d commit f06670c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion class.c
Expand Up @@ -2273,7 +2273,7 @@ rb_freeze_singleton_class(VALUE x)
VALUE klass = RBASIC_CLASS(x);
if (klass && // no class when hidden from ObjectSpace
FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
OBJ_FREEZE_RAW(klass);
OBJ_FREEZE(klass);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compile.c
Expand Up @@ -10009,7 +10009,7 @@ compile_shareable_literal_constant(rb_iseq_t *iseq, LINK_ANCHOR *ret, enum rb_pa

case NODE_ZLIST:{
VALUE lit = rb_ary_new();
OBJ_FREEZE_RAW(lit);
OBJ_FREEZE(lit);
ADD_INSN1(ret, node, putobject, lit);
RB_OBJ_WRITTEN(iseq, Qundef, lit);
*value_p = lit;
Expand Down
4 changes: 2 additions & 2 deletions complex.c
Expand Up @@ -397,7 +397,7 @@ nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag)

RCOMPLEX_SET_REAL(obj, real);
RCOMPLEX_SET_IMAG(obj, imag);
OBJ_FREEZE_RAW((VALUE)obj);
OBJ_FREEZE((VALUE)obj);

return (VALUE)obj;
}
Expand Down Expand Up @@ -1717,7 +1717,7 @@ nucomp_loader(VALUE self, VALUE a)

RCOMPLEX_SET_REAL(dat, rb_ivar_get(a, id_i_real));
RCOMPLEX_SET_IMAG(dat, rb_ivar_get(a, id_i_imag));
OBJ_FREEZE_RAW(self);
OBJ_FREEZE(self);

return self;
}
Expand Down
4 changes: 2 additions & 2 deletions rational.c
Expand Up @@ -418,7 +418,7 @@ nurat_s_new_internal(VALUE klass, VALUE num, VALUE den)

RATIONAL_SET_NUM((VALUE)obj, num);
RATIONAL_SET_DEN((VALUE)obj, den);
OBJ_FREEZE_RAW((VALUE)obj);
OBJ_FREEZE((VALUE)obj);

return (VALUE)obj;
}
Expand Down Expand Up @@ -1847,7 +1847,7 @@ nurat_loader(VALUE self, VALUE a)
nurat_canonicalize(&num, &den);
RATIONAL_SET_NUM((VALUE)dat, num);
RATIONAL_SET_DEN((VALUE)dat, den);
OBJ_FREEZE_RAW(self);
OBJ_FREEZE(self);

return self;
}
Expand Down
6 changes: 3 additions & 3 deletions ruby.c
Expand Up @@ -706,11 +706,11 @@ ruby_init_loadpath(void)
p -= bindir_len;
archlibdir = rb_str_subseq(sopath, 0, p - libpath);
rb_str_cat_cstr(archlibdir, libdir);
OBJ_FREEZE_RAW(archlibdir);
OBJ_FREEZE(archlibdir);
}
else if (p - libpath >= libdir_len && !strncmp(p - libdir_len, libdir, libdir_len)) {
archlibdir = rb_str_subseq(sopath, 0, (p2 ? p2 : p) - libpath);
OBJ_FREEZE_RAW(archlibdir);
OBJ_FREEZE(archlibdir);
p -= libdir_len;
}
#ifdef ENABLE_MULTIARCH
Expand Down Expand Up @@ -741,7 +741,7 @@ ruby_init_loadpath(void)
#endif
rb_gc_register_address(&ruby_prefix_path);
ruby_prefix_path = PREFIX_PATH();
OBJ_FREEZE_RAW(ruby_prefix_path);
OBJ_FREEZE(ruby_prefix_path);
if (!archlibdir) archlibdir = ruby_prefix_path;
rb_gc_register_address(&ruby_archlibdir_path);
ruby_archlibdir_path = archlibdir;
Expand Down
6 changes: 3 additions & 3 deletions string.c
Expand Up @@ -379,7 +379,7 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t data, int exist
RSTRING(str)->len,
ENCODING_GET(str));
}
OBJ_FREEZE_RAW(str);
OBJ_FREEZE(str);
}
else {
if (!OBJ_FROZEN(str) || CHILLED_STRING_P(str)) {
Expand Down Expand Up @@ -415,7 +415,7 @@ rb_fstring(VALUE str)
bare = BARE_STRING_P(str);
if (!bare) {
if (STR_EMBED_P(str)) {
OBJ_FREEZE_RAW(str);
OBJ_FREEZE(str);
return str;
}

Expand All @@ -432,7 +432,7 @@ rb_fstring(VALUE str)

if (!bare) {
str_replace_shared_without_enc(str, fstr);
OBJ_FREEZE_RAW(str);
OBJ_FREEZE(str);
return str;
}
return fstr;
Expand Down
14 changes: 7 additions & 7 deletions struct.c
Expand Up @@ -136,7 +136,7 @@ struct_set_members(VALUE klass, VALUE /* frozen hidden array */ members)
j = struct_member_pos_probe(j, mask);
}
}
OBJ_FREEZE_RAW(back);
OBJ_FREEZE(back);
}
rb_ivar_set(klass, id_members, members);
rb_ivar_set(klass, id_back_members, back);
Expand Down Expand Up @@ -422,7 +422,7 @@ struct_make_members_list(va_list ar)
}
ary = rb_hash_keys(list);
RBASIC_CLEAR_CLASS(ary);
OBJ_FREEZE_RAW(ary);
OBJ_FREEZE(ary);
return ary;
}

Expand Down Expand Up @@ -682,7 +682,7 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
}
rest = rb_hash_keys(rest);
RBASIC_CLEAR_CLASS(rest);
OBJ_FREEZE_RAW(rest);
OBJ_FREEZE(rest);
if (NIL_P(name)) {
st = anonymous_struct(klass);
}
Expand Down Expand Up @@ -794,7 +794,7 @@ VALUE
rb_struct_initialize(VALUE self, VALUE values)
{
rb_struct_initialize_m(RARRAY_LENINT(values), RARRAY_CONST_PTR(values), self);
if (rb_obj_is_kind_of(self, rb_cData)) OBJ_FREEZE_RAW(self);
if (rb_obj_is_kind_of(self, rb_cData)) OBJ_FREEZE(self);
RB_GC_GUARD(values);
return Qnil;
}
Expand Down Expand Up @@ -1685,7 +1685,7 @@ rb_data_s_def(int argc, VALUE *argv, VALUE klass)
}
rest = rb_hash_keys(rest);
RBASIC_CLEAR_CLASS(rest);
OBJ_FREEZE_RAW(rest);
OBJ_FREEZE(rest);
data_class = anonymous_struct(klass);
setup_data(data_class, rest);
if (rb_block_given_p()) {
Expand Down Expand Up @@ -1802,7 +1802,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self)
rb_hash_foreach(argv[0], struct_hash_set_i, (VALUE)&arg);
// Freeze early before potentially raising, so that we don't leave an
// unfrozen copy on the heap, which could get exposed via ObjectSpace.
OBJ_FREEZE_RAW(self);
OBJ_FREEZE(self);
if (arg.unknown_keywords != Qnil) {
rb_exc_raise(rb_keyword_error_new("unknown", arg.unknown_keywords));
}
Expand All @@ -1814,7 +1814,7 @@ static VALUE
rb_data_init_copy(VALUE copy, VALUE s)
{
copy = rb_struct_init_copy(copy, s);
RB_OBJ_FREEZE_RAW(copy);
RB_OBJ_FREEZE(copy);
return copy;
}

Expand Down
4 changes: 2 additions & 2 deletions thread.c
Expand Up @@ -2281,7 +2281,7 @@ rb_thread_s_handle_interrupt(VALUE self, VALUE mask_arg)
mask = mask_arg;
}
else if (RB_TYPE_P(mask, T_HASH)) {
OBJ_FREEZE_RAW(mask);
OBJ_FREEZE(mask);
}

rb_ary_push(th->pending_interrupt_mask_stack, mask);
Expand Down Expand Up @@ -5846,7 +5846,7 @@ rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data)
rb_thread_t *cur_th = GET_THREAD();

rb_hash_aset(interrupt_mask, rb_cObject, sym_never);
OBJ_FREEZE_RAW(interrupt_mask);
OBJ_FREEZE(interrupt_mask);
rb_ary_push(cur_th->pending_interrupt_mask_stack, interrupt_mask);

VALUE ret = rb_ensure(b_proc, data, uninterruptible_exit, Qnil);
Expand Down
2 changes: 1 addition & 1 deletion vm_args.c
Expand Up @@ -1021,7 +1021,7 @@ vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *
VALUE callback_arg = rb_ary_hidden_new(2);
rb_ary_push(callback_arg, block_code);
rb_ary_push(callback_arg, ref);
OBJ_FREEZE_RAW(callback_arg);
OBJ_FREEZE(callback_arg);
func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 1, UNLIMITED_ARGUMENTS);
rb_hash_aset(ref, block_code, func);
}
Expand Down

0 comments on commit f06670c

Please sign in to comment.