summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-04-30 19:29:34 +0900
committergit <svn-admin@ruby-lang.org>2024-04-30 10:29:38 +0000
commit8fb430c1da0d27247c5b425487ab4766afe8165d (patch)
tree4fa7e3358d57c23136734281f1297ba779ba2ce8 /lib
parent431711a8bb88d534cd2cf4db8634322b156f4b56 (diff)
[ruby/irb] Restore MAIN_CONTEXT correctly
(https://github.com/ruby/irb/pull/937) https://github.com/ruby/irb/commit/c41f460a70
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 168595d341..5cb91a2938 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -992,6 +992,7 @@ module IRB
def run(conf = IRB.conf)
in_nested_session = !!conf[:MAIN_CONTEXT]
conf[:IRB_RC].call(context) if conf[:IRB_RC]
+ prev_context = conf[:MAIN_CONTEXT]
conf[:MAIN_CONTEXT] = context
save_history = !in_nested_session && conf[:SAVE_HISTORY] && context.io.support_history_saving?
@@ -1014,6 +1015,9 @@ module IRB
eval_input
end
ensure
+ # Do not restore to nil. It will cause IRB crash when used with threads.
+ IRB.conf[:MAIN_CONTEXT] = prev_context if prev_context
+
RubyVM.keep_script_lines = keep_script_lines_backup if defined?(RubyVM.keep_script_lines)
trap("SIGINT", prev_trap)
conf[:AT_EXIT].each{|hook| hook.call}