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
Родитель 32ba86c9be
Коммит 8fd2df529b
3 изменённых файлов: 16 добавлений и 26 удалений

29
gc.c
Просмотреть файл

@ -748,26 +748,19 @@ typedef struct gc_function_map {
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
ruby_load_external_gc_from_argv(int argc, char **argv)
static void
ruby_external_gc_init(void)
{
char *gc_so_path = NULL;
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;
}
}
char *gc_so_path = getenv(RUBY_GC_LIBRARY_PATH);
void *handle = NULL;
if (gc_so_path && dln_supported_p()) {
char error[1024];
handle = dln_open(gc_so_path, error, sizeof(error));
if (!handle) {
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) { \
rb_gc_functions.name = dln_symbol(handle, "rb_gc_impl_" #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 { \
@ -938,6 +931,10 @@ ruby_load_external_gc_from_argv(int argc, char **argv)
void *
rb_objspace_alloc(void)
{
#if USE_SHARED_GC
ruby_external_gc_init();
#endif
void *objspace = rb_gc_impl_objspace_alloc();
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
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
malloc_offset = gc_compute_malloc_offset();

3
main.c
Просмотреть файл

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

10
ruby.c
Просмотреть файл

@ -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)) {
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
else if (strcmp("version", s) == 0) {
if (envopt) goto noenvopt_long;