diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-07-12 23:22:20 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-07-12 23:22:20 +0900 |
| commit | 79fb18445dec95c546b43a98b38b541674f89d93 (patch) | |
| tree | 7512ae2b05396efad6f79b72c238067c0f75dbd9 /mrblib | |
| parent | 6137bf9e7148235b9104f74cb189663c06204e90 (diff) | |
| download | mruby-79fb18445dec95c546b43a98b38b541674f89d93.tar.gz mruby-79fb18445dec95c546b43a98b38b541674f89d93.zip | |
rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/array.rb | 13 | ||||
| -rw-r--r-- | mrblib/hash.rb | 20 | ||||
| -rw-r--r-- | mrblib/kernel.rb | 5 |
3 files changed, 29 insertions, 9 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb index 3218aa858..bd8d5930f 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -84,13 +84,20 @@ class Array self end + def _inspect + return "[]" if self.size == 0 + "["+self.map{|x|x.inspect}.join(", ")+"]" + end ## - # Private method for Array creation. + # Return the contents of this array as a string. # # ISO 15.2.12.5.31 (x) def inspect - return "[]" if self.size == 0 - "["+self.map{|x|x.inspect}.join(", ")+"]" + begin + self._inspect + rescue SystemStackError + "[...]" + end end # ISO 15.2.12.5.32 (x) alias to_s inspect diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 9bb146b27..e7c51fb1f 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -192,16 +192,24 @@ class Hash h end - ## - # Return the contents of this hash as a string. - # - # ISO 15.2.13.4.30 (x) - def inspect + # internal method for Hash inspection + def _inspect return "{}" if self.size == 0 "{"+self.map {|k,v| - k.inspect + "=>" + v.inspect + k._inspect + "=>" + v._inspect }.join(", ")+"}" end + ## + # Return the contents of this hash as a string. + # + # ISO 15.2.13.4.30 (x) + def inspect + begin + self._inspect + rescue SystemStackError + "{...}" + end + end # ISO 15.2.13.4.31 (x) alias to_s inspect diff --git a/mrblib/kernel.rb b/mrblib/kernel.rb index d0fe47300..476ec8e18 100644 --- a/mrblib/kernel.rb +++ b/mrblib/kernel.rb @@ -39,6 +39,11 @@ module Kernel !(self =~ y) end + # internal method for inspect + def _inspect + self.inspect + end + def to_enum(*a) raise NotImplementedError.new("fiber required for enumerator") end |
