summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2022-11-17 17:33:18 -0500
committerAlan Wu <[email protected]>2022-11-25 16:21:40 -0500
commit790cf4b6d0475614afb127b416e87cfa39044d67 ()
treed04089ae209b4c3b27b6ab68097a6065d3583520 /load.c
parente15cd01149afe4924460f81cb6e27dd96de06657 (diff)
Fix autoload status of statically linked extensions
Previously, for statically-linked extensions, we used `vm->loading_table` to delay calling the init function until the extensions are required. This caused the extensions to look like they are in the middle of being loaded even before they're required. (`rb_feature_p()` returned true with a loading path output.) Combined with autoload, queries like `defined?(CONST)` and `Module#autoload?` were confused by this and returned nil incorrectly. RubyGems uses `defined?` to detect if OpenSSL is available and failed when OpenSSL was available in builds using `--with-static-linked-ext`. Use a dedicated table for the init functions instead of adding them to the loading table. This lets us remove some logic from non-EXTSTATIC builds. [Bug #19115]
Notes: Merged: https://.com/ruby/ruby/pull/6756
-rw-r--r--load.c55
1 files changed, 42 insertions, 13 deletions
@@ -850,14 +850,6 @@ load_lock(rb_vm_t *vm, const char *ftptr, bool warn)
st_insert(loading_tbl, (st_data_t)ftptr, data);
return (char *)ftptr;
}
- else if (imemo_type_p(data, imemo_memo)) {
- struct MEMO *memo = MEMO_CAST(data);
- void (*init)(void) = memo->u3.func;
- data = (st_data_t)rb_thread_shield_new();
- st_insert(loading_tbl, (st_data_t)ftptr, data);
- (*init)();
- return (char *)"";
- }
if (warn) {
VALUE warning = rb_warning_string("loading in progress, circular require considered harmful - %s", ftptr);
rb_backtrace_each(rb_str_append, warning);
@@ -1025,6 +1017,23 @@ search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, feature_func rb_
}
tmp = fname;
type = rb_find_file_ext(&tmp, ft == 's' ? ruby_ext : loadable_ext);
switch (type) {
case 0:
if (ft)
@@ -1063,6 +1072,20 @@ load_ext(VALUE path)
return (VALUE)dln_load(RSTRING_PTR(path));
}
static int
no_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn)
{
@@ -1164,6 +1187,11 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
else if (!*ftptr) {
result = TAG_RETURN;
}
else if (RTEST(rb_hash_aref(realpaths,
realpath = rb_realpath_internal(Qnil, path, 1)))) {
result = 0;
@@ -1280,6 +1308,7 @@ rb_require(const char *fname)
return rb_require_string(rb_str_new_cstr(fname));
}
static int
register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing)
{
@@ -1289,22 +1318,22 @@ register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing
rb_warn("%s is already registered", name);
}
else {
- *value = (st_data_t)MEMO_NEW(0, 0, init);
- *key = (st_data_t)ruby_strdup(name);
}
return ST_CONTINUE;
}
-RUBY_FUNC_EXPORTED void
ruby_init_ext(const char *name, void (*init)(void))
{
rb_vm_t *vm = GET_VM();
- st_table *loading_tbl = get_loading_table(vm);
if (feature_provided(vm, name, 0))
return;
- st_update(loading_tbl, (st_data_t)name, register_init_ext, (st_data_t)init);
}
/*
* call-seq: