summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2024-07-15 17:56:01 +0900
committernagachika <nagachika@ruby-lang.org>2024-07-15 17:56:01 +0900
commitb72deb7ca1198f8c799cd5e7e44635cf50abd7ec (patch)
tree2febe52d603d457cc01666970e73431a8d11c508 /eval.c
parentbfdb6d5a9dca32b41a2b22c108b46f9fc01fee35 (diff)
merge revision(s) 58918788abd63901588e4aa1e39b5c057321c10a: [Backport #20342]
[Bug #20342] Consider wrapped load in `main` methods
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/eval.c b/eval.c
index 24e6dac079..a61dfb1289 100644
--- a/eval.c
+++ b/eval.c
@@ -1777,6 +1777,16 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
return obj;
}
+VALUE
+rb_top_main_class(const char *method)
+{
+ VALUE klass = GET_THREAD()->top_wrapper;
+
+ if (!klass) return rb_cObject;
+ rb_warning("main.%s in the wrapped load is effective only in wrapper module", method);
+ return klass;
+}
+
/*
* call-seq:
* include(module, ...) -> self
@@ -1789,13 +1799,7 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
static VALUE
top_include(int argc, VALUE *argv, VALUE self)
{
- rb_thread_t *th = GET_THREAD();
-
- if (th->top_wrapper) {
- rb_warning("main.include in the wrapped load is effective only in wrapper module");
- return rb_mod_include(argc, argv, th->top_wrapper);
- }
- return rb_mod_include(argc, argv, rb_cObject);
+ return rb_mod_include(argc, argv, rb_top_main_class("include"));
}
/*