summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2024-05-29 15:40:49 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2024-05-29 15:40:49 -0700
commita24f19742bfa398a3b32c51df01133db7bcbc6e0 (patch)
treec23e09cc613dfb8b2c060f0e91c91ca4b17c7135 /eval.c
parent72a45ac7a3cc9bbecf641ac505f8ee791c9da48c (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 15b6567aff..a8fc48daf5 100644
--- a/eval.c
+++ b/eval.c
@@ -1797,6 +1797,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
@@ -1809,13 +1819,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"));
}
/*