• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

mrubyを超漢字で動作させる


Commit MetaInfo

Revisão79fb18445dec95c546b43a98b38b541674f89d93 (tree)
Hora2014-07-12 23:22:20
AutorYukihiro "Matz" Matsumoto <matz@ruby...>
CommiterYukihiro "Matz" Matsumoto

Mensagem de Log

rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461

Mudança Sumário

Diff

--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -84,13 +84,20 @@ class Array
8484 self
8585 end
8686
87+ def _inspect
88+ return "[]" if self.size == 0
89+ "["+self.map{|x|x.inspect}.join(", ")+"]"
90+ end
8791 ##
88- # Private method for Array creation.
92+ # Return the contents of this array as a string.
8993 #
9094 # ISO 15.2.12.5.31 (x)
9195 def inspect
92- return "[]" if self.size == 0
93- "["+self.map{|x|x.inspect}.join(", ")+"]"
96+ begin
97+ self._inspect
98+ rescue SystemStackError
99+ "[...]"
100+ end
94101 end
95102 # ISO 15.2.12.5.32 (x)
96103 alias to_s inspect
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -192,16 +192,24 @@ class Hash
192192 h
193193 end
194194
195- ##
196- # Return the contents of this hash as a string.
197- #
198- # ISO 15.2.13.4.30 (x)
199- def inspect
195+ # internal method for Hash inspection
196+ def _inspect
200197 return "{}" if self.size == 0
201198 "{"+self.map {|k,v|
202- k.inspect + "=>" + v.inspect
199+ k._inspect + "=>" + v._inspect
203200 }.join(", ")+"}"
204201 end
202+ ##
203+ # Return the contents of this hash as a string.
204+ #
205+ # ISO 15.2.13.4.30 (x)
206+ def inspect
207+ begin
208+ self._inspect
209+ rescue SystemStackError
210+ "{...}"
211+ end
212+ end
205213 # ISO 15.2.13.4.31 (x)
206214 alias to_s inspect
207215
--- a/mrblib/kernel.rb
+++ b/mrblib/kernel.rb
@@ -39,6 +39,11 @@ module Kernel
3939 !(self =~ y)
4040 end
4141
42+ # internal method for inspect
43+ def _inspect
44+ self.inspect
45+ end
46+
4247 def to_enum(*a)
4348 raise NotImplementedError.new("fiber required for enumerator")
4449 end