Skip to content

Commit 45a2c95

Browse files
committed
Reduce exposure of FL_FREEZE
The `FL_FREEZE` flag is redundant with `SHAPE_ID_FL_FROZEN`, so ideally it should be eliminated in favor of the later. Doing so would eliminate the risk of desync between the two, but also solve the problem of the frozen status being global in namespace context (See Bug #21330).
1 parent da10b95 commit 45a2c95

File tree

8 files changed

+34
-21
lines changed

8 files changed

+34
-21
lines changed

array.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,10 +3439,9 @@ rb_ary_sort_bang(VALUE ary)
34393439
ARY_SET_CAPA(ary, ARY_HEAP_LEN(tmp));
34403440
}
34413441
/* tmp was lost ownership for the ptr */
3442-
FL_UNSET(tmp, FL_FREEZE);
34433442
FL_SET_EMBED(tmp);
34443443
ARY_SET_EMBED_LEN(tmp, 0);
3445-
FL_SET(tmp, FL_FREEZE);
3444+
OBJ_FREEZE(tmp);
34463445
}
34473446
/* tmp will be GC'ed. */
34483447
RBASIC_SET_CLASS_RAW(tmp, rb_cArray); /* rb_cArray must be marked */

class.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,8 @@ rb_freeze_singleton_class(VALUE x)
27712771
if (!RCLASS_SINGLETON_P(x)) {
27722772
VALUE klass = RBASIC_CLASS(x);
27732773
if (klass && // no class when hidden from ObjectSpace
2774-
FL_TEST(klass, (FL_SINGLETON|FL_FREEZE)) == FL_SINGLETON) {
2774+
FL_TEST_RAW(klass, FL_SINGLETON) &&
2775+
!OBJ_FROZEN_RAW(klass)) {
27752776
OBJ_FREEZE(klass);
27762777
}
27772778
}

compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14456,7 +14456,7 @@ ibf_dump_object_object(struct ibf_dump *dump, VALUE obj)
1445614456
else {
1445714457
obj_header.internal = SPECIAL_CONST_P(obj) ? FALSE : (RBASIC_CLASS(obj) == 0) ? TRUE : FALSE;
1445814458
obj_header.special_const = FALSE;
14459-
obj_header.frozen = FL_TEST(obj, FL_FREEZE) ? TRUE : FALSE;
14459+
obj_header.frozen = OBJ_FROZEN(obj) ? TRUE : FALSE;
1446014460
ibf_dump_object_object_header(dump, obj_header);
1446114461
(*dump_object_functions[obj_header.type])(dump, obj);
1446214462
}

object.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,7 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
513513
argv[0] = obj;
514514
argv[1] = freeze_true_hash;
515515
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
516-
RBASIC(clone)->flags |= FL_FREEZE;
517-
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
518-
rb_obj_set_shape_id(clone, next_shape_id);
516+
OBJ_FREEZE(clone);
519517
break;
520518
}
521519
case Qfalse: {

shape.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,14 @@ rb_shape_transition_heap(VALUE obj, size_t heap_index)
818818
return (RBASIC_SHAPE_ID(obj) & (~SHAPE_ID_HEAP_INDEX_MASK)) | rb_shape_root(heap_index);
819819
}
820820

821+
void
822+
rb_set_namespaced_class_shape_id(VALUE obj, shape_id_t shape_id)
823+
{
824+
RBASIC_SET_SHAPE_ID(RCLASS_WRITABLE_ENSURE_FIELDS_OBJ(obj), shape_id);
825+
// FIXME: How to do multi-shape?
826+
RBASIC_SET_SHAPE_ID(obj, shape_id);
827+
}
828+
821829
/*
822830
* This function is used for assertions where we don't want to increment
823831
* max_iv_count

shape.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
146146
RUBY_ASSERT(rb_shape_verify_consistency(obj, shape_id));
147147
}
148148

149+
void rb_set_namespaced_class_shape_id(VALUE obj, shape_id_t shape_id);
150+
151+
static inline void
152+
RB_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
153+
{
154+
switch (BUILTIN_TYPE(obj)) {
155+
case T_CLASS:
156+
case T_MODULE:
157+
rb_set_namespaced_class_shape_id(obj, shape_id);
158+
break;
159+
default:
160+
RBASIC_SET_SHAPE_ID(obj, shape_id);
161+
break;
162+
}
163+
}
164+
149165
static inline rb_shape_t *
150166
RSHAPE(shape_id_t shape_id)
151167
{

string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,8 @@ rb_str_tmp_frozen_release(VALUE orig, VALUE tmp)
19111911
if (STR_EMBED_P(tmp)) {
19121912
RUBY_ASSERT(OBJ_FROZEN_RAW(tmp));
19131913
}
1914-
else if (FL_TEST_RAW(orig, STR_SHARED) &&
1915-
!FL_TEST_RAW(orig, STR_TMPLOCK|RUBY_FL_FREEZE)) {
1914+
else if (FL_TEST_RAW(orig, STR_SHARED | STR_TMPLOCK) == STR_TMPLOCK &&
1915+
!OBJ_FROZEN_RAW(orig)) {
19161916
VALUE shared = RSTRING(orig)->as.heap.aux.shared;
19171917

19181918
if (shared == tmp && !FL_TEST_RAW(tmp, STR_BORROWED)) {
@@ -2259,7 +2259,7 @@ str_duplicate_setup_heap(VALUE klass, VALUE str, VALUE dup)
22592259
if (FL_TEST_RAW(str, STR_SHARED)) {
22602260
root = RSTRING(str)->as.heap.aux.shared;
22612261
}
2262-
else if (UNLIKELY(!(flags & FL_FREEZE))) {
2262+
else if (UNLIKELY(!OBJ_FROZEN_RAW(str))) {
22632263
root = str = str_new_frozen(klass, str);
22642264
flags = FL_TEST_RAW(str, flag_mask);
22652265
}

variable.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,15 +2065,7 @@ rb_obj_set_shape_id(VALUE obj, shape_id_t shape_id)
20652065
return false;
20662066
}
20672067

2068-
if (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE) {
2069-
// Avoid creating the fields_obj just to freeze the class
2070-
if (!(shape_id == SPECIAL_CONST_SHAPE_ID && old_shape_id == ROOT_SHAPE_ID)) {
2071-
RBASIC_SET_SHAPE_ID(RCLASS_WRITABLE_ENSURE_FIELDS_OBJ(obj), shape_id);
2072-
}
2073-
}
2074-
// FIXME: How to do multi-shape?
2075-
RBASIC_SET_SHAPE_ID(obj, shape_id);
2076-
2068+
RB_SET_SHAPE_ID(obj, shape_id);
20772069
return true;
20782070
}
20792071

@@ -2085,8 +2077,7 @@ void rb_obj_freeze_inline(VALUE x)
20852077
RB_FL_UNSET_RAW(x, FL_USER2 | FL_USER3); // STR_CHILLED
20862078
}
20872079

2088-
shape_id_t next_shape_id = rb_shape_transition_frozen(x);
2089-
rb_obj_set_shape_id(x, next_shape_id);
2080+
RB_SET_SHAPE_ID(x, rb_shape_transition_frozen(x));
20902081

20912082
if (RBASIC_CLASS(x)) {
20922083
rb_freeze_singleton_class(x);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy