Revert "Load external GC using command line argument"

This reverts commit 8ddb1110c283c5cb59b6582383f36fdbcc43ab19.
This commit is contained in:
Peter Zhu 2024-07-04 10:35:25 -04:00
parent 32ba86c9be
commit 8fd2df529b
3 changed files with 16 additions and 26 deletions

29
gc.c
View File

@ -748,26 +748,19 @@ typedef struct gc_function_map {
static rb_gc_function_map_t rb_gc_functions; static rb_gc_function_map_t rb_gc_functions;
# define RUBY_GC_LIBRARY_ARG "--gc-library=" # define RUBY_GC_LIBRARY_PATH "RUBY_GC_LIBRARY_PATH"
void static void
ruby_load_external_gc_from_argv(int argc, char **argv) ruby_external_gc_init(void)
{ {
char *gc_so_path = NULL; char *gc_so_path = getenv(RUBY_GC_LIBRARY_PATH);
for (int i = 0; i < argc; i++) {
if (strncmp(argv[i], RUBY_GC_LIBRARY_ARG, sizeof(RUBY_GC_LIBRARY_ARG) - 1) == 0) {
gc_so_path = argv[i] + sizeof(RUBY_GC_LIBRARY_ARG) - 1;
}
}
void *handle = NULL; void *handle = NULL;
if (gc_so_path && dln_supported_p()) { if (gc_so_path && dln_supported_p()) {
char error[1024]; char error[1024];
handle = dln_open(gc_so_path, error, sizeof(error)); handle = dln_open(gc_so_path, error, sizeof(error));
if (!handle) { if (!handle) {
fprintf(stderr, "%s", error); fprintf(stderr, "%s", error);
rb_bug("ruby_load_external_gc_from_argv: Shared library %s cannot be opened", gc_so_path); rb_bug("ruby_external_gc_init: Shared library %s cannot be opened", gc_so_path);
} }
} }
@ -775,7 +768,7 @@ ruby_load_external_gc_from_argv(int argc, char **argv)
if (handle) { \ if (handle) { \
rb_gc_functions.name = dln_symbol(handle, "rb_gc_impl_" #name); \ rb_gc_functions.name = dln_symbol(handle, "rb_gc_impl_" #name); \
if (!rb_gc_functions.name) { \ if (!rb_gc_functions.name) { \
rb_bug("ruby_load_external_gc_from_argv: " #name " func not exported by library %s", gc_so_path); \ rb_bug("ruby_external_gc_init: " #name " func not exported by library %s", gc_so_path); \
} \ } \
} \ } \
else { \ else { \
@ -938,6 +931,10 @@ ruby_load_external_gc_from_argv(int argc, char **argv)
void * void *
rb_objspace_alloc(void) rb_objspace_alloc(void)
{ {
#if USE_SHARED_GC
ruby_external_gc_init();
#endif
void *objspace = rb_gc_impl_objspace_alloc(); void *objspace = rb_gc_impl_objspace_alloc();
ruby_current_vm_ptr->objspace = objspace; ruby_current_vm_ptr->objspace = objspace;
@ -4627,6 +4624,12 @@ rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func)
void void
Init_GC(void) Init_GC(void)
{ {
#if USE_SHARED_GC
if (getenv(RUBY_GC_LIBRARY_PATH) != NULL && !dln_supported_p()) {
rb_warn(RUBY_GC_LIBRARY_PATH " is ignored because this executable file can't load extension libraries");
}
#endif
#undef rb_intern #undef rb_intern
malloc_offset = gc_compute_malloc_offset(); malloc_offset = gc_compute_malloc_offset();

3
main.c
View File

@ -39,9 +39,6 @@ static int
rb_main(int argc, char **argv) rb_main(int argc, char **argv)
{ {
RUBY_INIT_STACK; RUBY_INIT_STACK;
#if USE_SHARED_GC
ruby_load_external_gc_from_argv(argc, argv);
#endif
ruby_init(); ruby_init();
return ruby_run_node(ruby_options(argc, argv)); return ruby_run_node(ruby_options(argc, argv));
} }

10
ruby.c
View File

@ -1441,16 +1441,6 @@ proc_long_options(ruby_cmdline_options_t *opt, const char *s, long argc, char **
else if (is_option_with_arg("source-encoding", Qfalse, Qtrue)) { else if (is_option_with_arg("source-encoding", Qfalse, Qtrue)) {
set_source_encoding_once(opt, s, 0); set_source_encoding_once(opt, s, 0);
} }
#endif
#if defined(USE_SHARED_GC) && USE_SHARED_GC
else if (is_option_with_arg("gc-library", Qfalse, Qfalse)) {
// no-op
// Handled by ruby_load_external_gc_from_argv
if (!dln_supported_p()) {
rb_warn("--gc-library is ignored because this executable file can't load extension libraries");
}
}
#endif #endif
else if (strcmp("version", s) == 0) { else if (strcmp("version", s) == 0) {
if (envopt) goto noenvopt_long; if (envopt) goto noenvopt_long;