summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2023-04-20 09:44:02 -0400
committerAlan Wu <[email protected]>2023-04-26 15:02:23 -0400
commitadaff1fc496b6f01fb1c4c812b9b4082618e2f79 ()
tree453d043ffdae6210a561ca7966b5c4783127f6f7
parent92466e440d459cd21e89f8bfbe6d8438bcaa9389 (diff)
[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"
Notes: Merged: https://.com/ruby/ruby/pull/7729
-rw-r--r--load.c28
-rw-r--r--vm.c3
-rw-r--r--vm_core.h6
3 files changed, 17 insertions, 20 deletions
@@ -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
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)) {
((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;
}
void
ruby_init_ext(const char *name, void (*init)(void))
{
rb_vm_t *vm = GET_VM();
- st_table *inits_table = vm->static_ext_inits;
if (feature_provided(vm, name, 0))
return;
st_update(inits_table, (st_data_t)name, register_init_ext, (st_data_t)init);
}
-#endif
/*
* call-seq:
@@ -4037,9 +4037,6 @@ Init_vm_objects(void)
vm->mark_object_ary = rb_ary_hidden_new(128);
vm->loading_table = st_init_strtable();
vm->frozen_strings = st_init_table_with_size(&rb_fstring_hash_type, 10000);
-#if EXTSTATIC
- vm->static_ext_inits = st_init_strtable();
-#endif
}
/* Stub for builtin function when not building YJIT units*/
@@ -557,10 +557,6 @@ struct rb_iseq_struct {
#define ISEQ_BODY(iseq) ((iseq)->body)
-#ifndef EXTSTATIC
-#define EXTSTATIC 0
-#endif
-
#ifndef USE_LAZY_LOAD
#define USE_LAZY_LOAD 0
#endif
@@ -686,11 +682,9 @@ typedef struct rb_vm_struct {
VALUE loaded_features_realpath_map;
struct st_table *loaded_features_index;
struct st_table *loading_table;
-#if EXTSTATIC
// For running the init function of statically linked
// extensions when they are loaded
struct st_table *static_ext_inits;
-#endif
/* signal */
struct {