Skip to content

Commit 4df8c0e

Browse files
committed
shape.c: make internal_object_id extern instead of static
Otherwise every inclusion of shape.h result in a different variable and only the one in `shape.c` is properly initialized.
1 parent eecf5f7 commit 4df8c0e

5 files changed

Lines changed: 11 additions & 10 deletions

File tree

gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ object_id(VALUE obj)
18351835
if (rb_shape_too_complex_p(shape)) {
18361836
st_table *table = ROBJECT_FIELDS_HASH(obj);
18371837
if (rb_shape_has_object_id(shape)) {
1838-
st_lookup(table, (st_data_t)internal_object_id, (st_data_t *)&id);
1838+
st_lookup(table, (st_data_t)ruby_internal_object_id, (st_data_t *)&id);
18391839
RUBY_ASSERT(id, "object_id missing");
18401840

18411841
rb_gc_vm_unlock(lock_lev);
@@ -1845,7 +1845,7 @@ object_id(VALUE obj)
18451845
id = ULL2NUM(next_object_id);
18461846
next_object_id += OBJ_ID_INCREMENT;
18471847
rb_shape_t *object_id_shape = rb_shape_object_id_shape(obj);
1848-
st_insert(table, (st_data_t)internal_object_id, (st_data_t)id);
1848+
st_insert(table, (st_data_t)ruby_internal_object_id, (st_data_t)id);
18491849
rb_shape_set_shape(obj, object_id_shape);
18501850
if (RB_UNLIKELY(id_to_obj_tbl)) {
18511851
st_insert(id_to_obj_tbl, (st_data_t)id, (st_data_t)obj);

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
341341
// obj is TOO_COMPLEX so we can copy its iv_hash
342342
st_table *table = st_copy(ROBJECT_FIELDS_HASH(obj));
343343
if (rb_shape_has_object_id(src_shape)) {
344-
st_data_t id = (st_data_t)internal_object_id;
344+
st_data_t id = (st_data_t)ruby_internal_object_id;
345345
st_delete(table, &id, NULL);
346346
}
347347
rb_obj_init_too_complex(dest, table);

shape.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
static ID id_frozen;
4949
static ID id_t_object;
50+
ID ruby_internal_object_id; // extern
5051

5152
#define LEAF 0
5253
#define BLACK 0x0
@@ -732,7 +733,7 @@ shape_transition_too_complex(rb_shape_t *original_shape)
732733

733734
if (original_shape->flags & SHAPE_FL_HAS_OBJECT_ID) {
734735
bool dont_care;
735-
next_shape = get_next_shape_internal(next_shape, internal_object_id, SHAPE_OBJ_ID, &dont_care, false);
736+
next_shape = get_next_shape_internal(next_shape, ruby_internal_object_id, SHAPE_OBJ_ID, &dont_care, false);
736737
}
737738

738739
return next_shape;
@@ -775,7 +776,7 @@ rb_shape_object_id_shape(VALUE obj)
775776
}
776777

777778
bool dont_care;
778-
rb_shape_t* next_shape = get_next_shape_internal(shape, internal_object_id, SHAPE_OBJ_ID, &dont_care, true);
779+
rb_shape_t* next_shape = get_next_shape_internal(shape, ruby_internal_object_id, SHAPE_OBJ_ID, &dont_care, true);
779780
RUBY_ASSERT(next_shape);
780781
return next_shape;
781782
}
@@ -1363,7 +1364,7 @@ Init_default_shapes(void)
13631364

13641365
id_frozen = rb_make_internal_id();
13651366
id_t_object = rb_make_internal_id();
1366-
internal_object_id = rb_make_internal_id();
1367+
ruby_internal_object_id = rb_make_internal_id();
13671368

13681369
#ifdef HAVE_MMAP
13691370
size_t shape_cache_mmap_size = rb_size_mul_or_raise(REDBLACK_CACHE_SIZE, sizeof(redblack_node_t), rb_eRuntimeError);
@@ -1424,9 +1425,9 @@ Init_default_shapes(void)
14241425
// ran out of shapes.
14251426
rb_shape_t *shape;
14261427
shape = get_next_shape_internal(too_complex_shape, id_frozen, SHAPE_FROZEN, &dont_care, true);
1427-
get_next_shape_internal(shape, internal_object_id, SHAPE_OBJ_ID, &dont_care, true);
1428+
get_next_shape_internal(shape, ruby_internal_object_id, SHAPE_OBJ_ID, &dont_care, true);
14281429

1429-
shape = get_next_shape_internal(too_complex_shape, internal_object_id, SHAPE_OBJ_ID, &dont_care, true);
1430+
shape = get_next_shape_internal(too_complex_shape, ruby_internal_object_id, SHAPE_OBJ_ID, &dont_care, true);
14301431
get_next_shape_internal(shape, id_frozen, SHAPE_FROZEN, &dont_care, true);
14311432
}
14321433

shape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef uint32_t redblack_id_t;
3939
// ROOT_TOO_COMPLEX_SHAPE_ID 0x2
4040
#define FIRST_T_OBJECT_SHAPE_ID 0x3
4141

42-
static ID internal_object_id;
42+
extern ID ruby_internal_object_id;
4343

4444
typedef struct redblack_node redblack_node_t;
4545

variable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
22872287
// obj is TOO_COMPLEX so we can copy its iv_hash
22882288
st_table *table = st_copy(obj_fields_tbl->as.complex.table);
22892289
if (rb_shape_has_object_id(src_shape)) {
2290-
st_data_t id = (st_data_t)internal_object_id;
2290+
st_data_t id = (st_data_t)ruby_internal_object_id;
22912291
st_delete(table, &id, NULL);
22922292
}
22932293
rb_obj_init_too_complex(dest, table);

0 commit comments

Comments
 (0)