diff options
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 41 |
1 files changed, 32 insertions, 9 deletions
@@ -497,10 +497,27 @@ dladdr_path(const void* addr) #define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index") +VALUE ruby_archlibdir_path, ruby_prefix_path; + void ruby_init_loadpath_safe(int safe_level) { - VALUE load_path; + static const char libdir[] = "/" +#ifdef LIBDIR_BASENAME + LIBDIR_BASENAME +#else + "lib" +#endif +#ifdef ENABLE_MULTIARCH + "/"RUBY_ARCH +#endif + ; + const ptrdiff_t libdir_len = (ptrdiff_t)sizeof(libdir) +#ifdef ENABLE_MULTIARCH + - rb_strlen_lit("/"RUBY_ARCH) +#endif + - 1; + VALUE load_path, archlibdir = 0; ID id_initial_load_path_mark; const char *paths = ruby_initial_load_paths; #if defined LOAD_RELATIVE @@ -561,23 +578,22 @@ ruby_init_loadpath_safe(int safe_level) p = strrchr(libpath, '/'); if (p) { static const char bindir[] = "/bin"; -#ifdef LIBDIR_BASENAME - static const char libdir[] = "/"LIBDIR_BASENAME; -#else - static const char libdir[] = "/lib"; -#endif const ptrdiff_t bindir_len = (ptrdiff_t)sizeof(bindir) - 1; - const ptrdiff_t libdir_len = (ptrdiff_t)sizeof(libdir) - 1; -#ifdef ENABLE_MULTIARCH const char *p2 = NULL; +#ifdef ENABLE_MULTIARCH multiarch: #endif if (p - libpath >= bindir_len && !STRNCASECMP(p - bindir_len, bindir, bindir_len)) { p -= bindir_len; + archlibdir = rb_str_subseq(sopath, 0, p - libpath); + rb_str_cat_cstr(archlibdir, libdir); + OBJ_FREEZE_RAW(archlibdir); } else if (p - libpath >= libdir_len && !strncmp(p - libdir_len, libdir, libdir_len)) { + archlibdir = rb_str_subseq(sopath, 0, (p2 ? p2 : p) - libpath); + OBJ_FREEZE_RAW(archlibdir); p -= libdir_len; } #ifdef ENABLE_MULTIARCH @@ -603,6 +619,13 @@ ruby_init_loadpath_safe(int safe_level) #define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len)) #define PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len) #endif + rb_gc_register_address(&ruby_prefix_path); + ruby_prefix_path = PREFIX_PATH(); + OBJ_FREEZE_RAW(ruby_prefix_path); + if (!archlibdir) archlibdir = ruby_prefix_path; + rb_gc_register_address(&ruby_archlibdir_path); + ruby_archlibdir_path = archlibdir; + load_path = GET_VM()->load_path; if (safe_level == 0) { @@ -618,7 +641,7 @@ ruby_init_loadpath_safe(int safe_level) paths += len + 1; } - rb_const_set(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"), rb_obj_freeze(PREFIX_PATH())); + rb_const_set(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"), ruby_prefix_path); } |