From ca4755b59a7bdaaffbaef05474c8d8ee187e8d7d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 28 Nov 2023 00:13:05 +0900 Subject: [PATCH] [Bug #20023] Resurrect fake string feature name before raising --- load.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/load.c b/load.c index 3dd5f04411..780edf27a7 100644 --- a/load.c +++ b/load.c @@ -935,7 +935,7 @@ load_unlock(rb_vm_t *vm, const char *ftptr, int done) } } -static VALUE rb_require_string_internal(VALUE fname); +static VALUE rb_require_string_internal(VALUE fname, bool resurrect); /* * call-seq: @@ -998,7 +998,7 @@ rb_f_require_relative(VALUE obj, VALUE fname) rb_loaderror("cannot infer basepath"); } base = rb_file_dirname(base); - return rb_require_string_internal(rb_file_absolute_path(fname, base)); + return rb_require_string_internal(rb_file_absolute_path(fname, base), false); } typedef int (*feature_func)(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn); @@ -1336,11 +1336,11 @@ ruby_require_internal(const char *fname, unsigned int len) VALUE rb_require_string(VALUE fname) { - return rb_require_string_internal(FilePathValue(fname)); + return rb_require_string_internal(FilePathValue(fname), false); } static VALUE -rb_require_string_internal(VALUE fname) +rb_require_string_internal(VALUE fname, bool resurrect) { rb_execution_context_t *ec = GET_EC(); int result = require_internal(ec, fname, 1, RTEST(ruby_verbose)); @@ -1349,6 +1349,7 @@ rb_require_string_internal(VALUE fname) EC_JUMP_TAG(ec, result); } if (result < 0) { + if (resurrect) fname = rb_str_resurrect(fname); load_failed(fname); } @@ -1360,7 +1361,7 @@ rb_require(const char *fname) { struct RString fake; VALUE str = rb_setup_fake_str(&fake, fname, strlen(fname), 0); - return rb_require_string_internal(str); + return rb_require_string_internal(str, true); } static int