From e170e73a9fa0e3ffdc41c811cabbf967380a3b46 Mon Sep 17 00:00:00 2001 From: tompng Date: Sun, 13 Oct 2024 15:33:55 +0900 Subject: [PATCH] Remove bignum check from save_history IRB need to accept bignum history size, but we don't want explicit bignum checks because threshold of bignum and fixnum depends on platform. --- lib/irb/history.rb | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/irb/history.rb b/lib/irb/history.rb index a428003d2..25fa71b9c 100644 --- a/lib/irb/history.rb +++ b/lib/irb/history.rb @@ -5,10 +5,7 @@ module History class << self # Integer representation of IRB.conf[:HISTORY_FILE]. def save_history - num = IRB.conf[:SAVE_HISTORY].to_i - # Bignums cause RangeErrors when slicing arrays. - # Treat such values as 'infinite'. - (num > save_history_max) ? -1 : num + IRB.conf[:SAVE_HISTORY].to_i end def save_history? @@ -27,13 +24,6 @@ def history_file IRB.rc_file("_history") end end - - private - - def save_history_max - # Max fixnum (32-bit) that can be used without getting RangeError. - 2**30 - 1 - end end end @@ -90,7 +80,8 @@ def save_history hist = history.map { |l| l.scrub.split("\n").join("\\\n") } unless append_history || History.infinite? - hist = hist.last(History.save_history) + # Check size before slicing because array.last(huge_number) raises RangeError. + hist = hist.last(History.save_history) if hist.size > History.save_history end f.puts(hist)