summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2023-04-20 09:44:02 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2023-04-26 15:02:23 -0400
commitadaff1fc496b6f01fb1c4c812b9b4082618e2f79 (patch)
tree453d043ffdae6210a561ca7966b5c4783127f6f7 /load.c
parent92466e440d459cd21e89f8bfbe6d8438bcaa9389 (diff)
downloadruby-adaff1fc496b6f01fb1c4c812b9b4082618e2f79.tar.gz
[Bug #19592] Fix ext/Setup support
After [1], using ext/Setup to link some, but not all extensions failed during linking. I did not know about this option, and had assumed that only `--with-static-linked-ext` builds can include statically linked extensions. Include the support code for statically linked extensions in all configurations like before [1]. Initialize the table lazily to minimize footprint on builds that have no statically linked extensions. [1]: 790cf4b6d0475614afb127b416e87cfa39044d67 "Fix autoload status of statically linked extensions"
Diffstat (limited to 'load.c')
-rw-r--r--load.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/load.c b/load.c
index d4d6afaddb..da81becfc1 100644
--- a/load.c
+++ b/load.c
@@ -1032,8 +1032,10 @@ 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);
-#if EXTSTATIC
- if (!ft && type != 1) { // not already a feature and not found as a dynamic library
+
+ // Check if it's a statically linked extension when
+ // not already a feature and not found as a dynamic library.
+ if (!ft && type != 1 && vm->static_ext_inits) {
VALUE lookup_name = tmp;
// Append ".so" if not already present so for example "etc" can find "etc.so".
// We always register statically linked extensions with a ".so" extension.
@@ -1048,7 +1050,7 @@ search_required(rb_vm_t *vm, VALUE fname, volatile VALUE *path, feature_func rb_
return 's';
}
}
-#endif
+
switch (type) {
case 0:
if (ft)
@@ -1087,19 +1089,18 @@ load_ext(VALUE path)
return (VALUE)dln_load(RSTRING_PTR(path));
}
-#if EXTSTATIC
static bool
run_static_ext_init(rb_vm_t *vm, const char *feature)
{
st_data_t key = (st_data_t)feature;
st_data_t init_func;
- if (st_delete(vm->static_ext_inits, &key, &init_func)) {
+
+ if (vm->static_ext_inits && st_delete(vm->static_ext_inits, &key, &init_func)) {
((void (*)(void))init_func)();
return true;
}
return false;
}
-#endif
static int
no_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn)
@@ -1203,11 +1204,9 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
else if (!*ftptr) {
result = TAG_RETURN;
}
-#if EXTSTATIC
else if (found == 's' && run_static_ext_init(th->vm, RSTRING_PTR(path))) {
result = TAG_RETURN;
}
-#endif
else if (RTEST(rb_hash_aref(realpaths,
realpath = rb_realpath_internal(Qnil, path, 1)))) {
result = 0;
@@ -1326,7 +1325,6 @@ rb_require(const char *fname)
return rb_require_string(rb_str_new_cstr(fname));
}
-#if EXTSTATIC
static int
register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing)
{
@@ -1341,17 +1339,25 @@ register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing
return ST_CONTINUE;
}
+// Private API for statically linked extensions.
+// Used with the ext/Setup file, the --with-setup and
+// --with-static-linked-ext configuration option, etc.
void
ruby_init_ext(const char *name, void (*init)(void))
{
+ st_table *inits_table;
rb_vm_t *vm = GET_VM();
- st_table *inits_table = vm->static_ext_inits;
if (feature_provided(vm, name, 0))
return;
+
+ inits_table = vm->static_ext_inits;
+ if (!inits_table) {
+ inits_table = st_init_strtable();
+ vm->static_ext_inits = inits_table;
+ }
st_update(inits_table, (st_data_t)name, register_init_ext, (st_data_t)init);
}
-#endif
/*
* call-seq: