Skip to content

Commit 53351a4

Browse files
committed
Embed vm->static_ext_inits
1 parent 086c53d commit 53351a4

6 files changed

Lines changed: 19 additions & 12 deletions

File tree

internal/st.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ st_table *rb_st_init_existing_table_with_size(st_table *tab, const struct st_has
1111
st_table *rb_st_init_existing_numtable_with_size(st_table *tab, st_index_t size);
1212
#define st_init_existing_numtable_with_size rb_st_init_existing_numtable_with_size
1313

14+
st_table *rb_st_init_existing_strtable_with_size(st_table *tab, st_index_t size);
15+
#define st_init_existing_strtable_with_size rb_st_init_existing_strtable_with_size
16+
1417
void rb_st_free_embedded_table(st_table *tab);
1518
#define st_free_embedded_table rb_st_free_embedded_table
1619

load.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ search_required(const rb_box_t *box, VALUE fname, volatile VALUE *path, feature_
11391139
// not already a feature and not found as a dynamic library.
11401140
if (!ft && type != loadable_ext_rb) {
11411141
rb_vm_t *vm = GET_VM();
1142-
if (vm->static_ext_inits) {
1142+
if (vm->static_ext_inits.num_entries) {
11431143
VALUE lookup_name = tmp;
11441144
// Append ".so" if not already present so for example "etc" can find "etc.so".
11451145
// We always register statically linked extensions with a ".so" extension.
@@ -1149,7 +1149,7 @@ search_required(const rb_box_t *box, VALUE fname, volatile VALUE *path, feature_
11491149
rb_str_cat_cstr(lookup_name, ".so");
11501150
}
11511151
ftptr = RSTRING_PTR(lookup_name);
1152-
if (st_lookup(vm->static_ext_inits, (st_data_t)ftptr, NULL)) {
1152+
if (st_lookup(&vm->static_ext_inits, (st_data_t)ftptr, NULL)) {
11531153
*path = rb_filesystem_str_new_cstr(ftptr);
11541154
RB_GC_GUARD(lookup_name);
11551155
return 's';
@@ -1215,7 +1215,7 @@ run_static_ext_init(VALUE vm_ptr, VALUE feature_value)
12151215
st_data_t key = (st_data_t)feature;
12161216
st_data_t init_func;
12171217

1218-
if (vm->static_ext_inits && st_delete(vm->static_ext_inits, &key, &init_func)) {
1218+
if (st_delete(&vm->static_ext_inits, &key, &init_func)) {
12191219
((void (*)(void))init_func)();
12201220
return Qtrue;
12211221
}
@@ -1490,19 +1490,13 @@ register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing
14901490
void
14911491
ruby_init_ext(const char *name, void (*init)(void))
14921492
{
1493-
st_table *inits_table;
14941493
rb_vm_t *vm = GET_VM();
14951494
const rb_box_t *box = rb_loading_box();
14961495

14971496
if (feature_provided((rb_box_t *)box, name, 0))
14981497
return;
14991498

1500-
inits_table = vm->static_ext_inits;
1501-
if (!inits_table) {
1502-
inits_table = st_init_strtable();
1503-
vm->static_ext_inits = inits_table;
1504-
}
1505-
st_update(inits_table, (st_data_t)name, register_init_ext, (st_data_t)init);
1499+
st_update(&vm->static_ext_inits, (st_data_t)name, register_init_ext, (st_data_t)init);
15061500
}
15071501

15081502
/*

parser_st.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ nonempty_memcpy(void *dest, const void *src, size_t n)
8080
#define st_init_table_with_size rb_parser_st_init_table_with_size
8181
#undef st_init_existing_table_with_size
8282
#define st_init_existing_table_with_size rb_parser_st_init_existing_table_with_size
83+
#undef st_init_existing_strtable_with_size
84+
#define st_init_existing_strtable_with_size rb_parser_st_init_existing_strtable_with_size
8385
#undef st_init_existing_numtable_with_size
8486
#define st_init_existing_numtable_with_size rb_parser_st_init_existing_numtable_with_size
8587
#undef st_free_embedded_table

st.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,13 @@ st_init_strtable_with_size(st_index_t size)
651651
return st_init_table_with_size(&type_strhash, size);
652652
}
653653

654+
st_table *
655+
st_init_existing_strtable_with_size(st_table *tab, st_index_t size)
656+
{
657+
return st_init_existing_table_with_size(tab, &type_strhash, size);
658+
}
659+
660+
654661
/* Create and return table which can hold a minimal number of strings
655662
whose character case is ignored. */
656663
st_table *

vm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3393,7 +3393,7 @@ ruby_vm_destruct(rb_vm_t *vm)
33933393
// TODO: Is this ignorable for classext->m_tbl ?
33943394
// rb_id_table_free(RCLASS(rb_mRubyVMFrozenCore)->m_tbl);
33953395

3396-
st_free_table(vm->static_ext_inits);
3396+
st_free_embedded_table(&vm->static_ext_inits);
33973397

33983398
rb_id_table_free_items(&vm->constant_cache);
33993399
set_free_embedded_table(&vm->unused_block_warning_table);
@@ -4586,6 +4586,7 @@ Init_BareVM(void)
45864586
rb_objspace_alloc();
45874587
rb_id_table_init(&vm->negative_cme_table, 16);
45884588
st_init_existing_numtable_with_size(&vm->overloaded_cme_table, 0);
4589+
st_init_existing_strtable_with_size(&vm->static_ext_inits, 0);
45894590
set_init_embedded_numtable_with_size(&vm->unused_block_warning_table, 0);
45904591
vm->global_hooks.type = hook_list_type_global;
45914592

vm_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ typedef struct rb_vm_struct {
780780
/* load */
781781
// For running the init function of statically linked
782782
// extensions when they are loaded
783-
struct st_table *static_ext_inits;
783+
struct st_table static_ext_inits;
784784

785785
/* signal */
786786
struct {

0 commit comments

Comments
 (0)