Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
79fb1844
Commit
79fb1844
authored
Jul 12, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461
parent
6137bf9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
9 deletions
+29
-9
mrblib/array.rb
mrblib/array.rb
+10
-3
mrblib/hash.rb
mrblib/hash.rb
+14
-6
mrblib/kernel.rb
mrblib/kernel.rb
+5
-0
No files found.
mrblib/array.rb
View file @
79fb1844
...
@@ -84,13 +84,20 @@ class Array
...
@@ -84,13 +84,20 @@ class Array
self
self
end
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)
# ISO 15.2.12.5.31 (x)
def
inspect
def
inspect
return
"[]"
if
self
.
size
==
0
begin
"["
+
self
.
map
{
|
x
|
x
.
inspect
}.
join
(
", "
)
+
"]"
self
.
_inspect
rescue
SystemStackError
"[...]"
end
end
end
# ISO 15.2.12.5.32 (x)
# ISO 15.2.12.5.32 (x)
alias
to_s
inspect
alias
to_s
inspect
...
...
mrblib/hash.rb
View file @
79fb1844
...
@@ -192,16 +192,24 @@ class Hash
...
@@ -192,16 +192,24 @@ class Hash
h
h
end
end
##
# internal method for Hash inspection
# Return the contents of this hash as a string.
def
_inspect
#
# ISO 15.2.13.4.30 (x)
def
inspect
return
"{}"
if
self
.
size
==
0
return
"{}"
if
self
.
size
==
0
"{"
+
self
.
map
{
|
k
,
v
|
"{"
+
self
.
map
{
|
k
,
v
|
k
.
inspect
+
"=>"
+
v
.
inspect
k
.
_inspect
+
"=>"
+
v
.
_
inspect
}.
join
(
", "
)
+
"}"
}.
join
(
", "
)
+
"}"
end
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)
# ISO 15.2.13.4.31 (x)
alias
to_s
inspect
alias
to_s
inspect
...
...
mrblib/kernel.rb
View file @
79fb1844
...
@@ -39,6 +39,11 @@ module Kernel
...
@@ -39,6 +39,11 @@ module Kernel
!
(
self
=~
y
)
!
(
self
=~
y
)
end
end
# internal method for inspect
def
_inspect
self
.
inspect
end
def
to_enum
(
*
a
)
def
to_enum
(
*
a
)
raise
NotImplementedError
.
new
(
"fiber required for enumerator"
)
raise
NotImplementedError
.
new
(
"fiber required for enumerator"
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment