Skip to content

Commit 97d8a68

Browse files
committed
Merge root_box_data into root_box
* Make invariant `root_box` an array consist of only `root_box_data` * Remove the initializer list that are just overwritten in `initialize_root_box()` and misses `classext_cow_classes`. * Shrink the scope using another local `root_box`. * Make data type constants static.
1 parent 674c3d7 commit 97d8a68

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

box.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ VALUE rb_cBox = 0;
3131
VALUE rb_cBoxEntry = 0;
3232
VALUE rb_mBoxLoader = 0;
3333

34-
static rb_box_t root_box_data = {
35-
/* Initialize values lazily in Init_Box() */
36-
(VALUE)NULL, 0,
37-
(VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL, (VALUE)NULL,
38-
(struct st_table *)NULL, (struct st_table *)NULL, (VALUE)NULL, (VALUE)NULL,
39-
false, false
40-
};
41-
42-
static rb_box_t * root_box = &root_box_data;
43-
static rb_box_t * main_box = 0;
34+
static rb_box_t root_box[1]; /* Initialize in initialize_root_box() */
35+
static rb_box_t *main_box;
4436
static char *tmp_dir;
4537
static bool tmp_dir_has_dirsep;
4638

@@ -290,7 +282,7 @@ box_entry_memsize(const void *ptr)
290282
rb_st_memsize(box->loading_table);
291283
}
292284

293-
const rb_data_type_t rb_box_data_type = {
285+
static const rb_data_type_t rb_box_data_type = {
294286
"Ruby::Box::Entry",
295287
{
296288
rb_box_entry_mark,
@@ -301,7 +293,7 @@ const rb_data_type_t rb_box_data_type = {
301293
0, 0, RUBY_TYPED_FREE_IMMEDIATELY // TODO: enable RUBY_TYPED_WB_PROTECTED when inserting write barriers
302294
};
303295

304-
const rb_data_type_t rb_root_box_data_type = {
296+
static const rb_data_type_t rb_root_box_data_type = {
305297
"Ruby::Box::Root",
306298
{
307299
rb_box_entry_mark,
@@ -838,8 +830,6 @@ rb_box_require_relative(VALUE box, VALUE fname)
838830
static void
839831
initialize_root_box(void)
840832
{
841-
VALUE root_box, entry;
842-
ID id_box_entry;
843833
rb_vm_t *vm = GET_VM();
844834
rb_box_t *root = (rb_box_t *)rb_root_box();
845835

@@ -864,6 +854,8 @@ initialize_root_box(void)
864854
vm->root_box = root;
865855

866856
if (rb_box_available()) {
857+
VALUE root_box, entry;
858+
ID id_box_entry;
867859
CONST_ID(id_box_entry, "__box_entry__");
868860

869861
root_box = rb_obj_alloc(rb_cBox);

0 commit comments

Comments
 (0)