зеркало из https://github.com/github/ruby.git
[ruby/prism] Make location methods thread-safe
* Before it could result in NoMethodError if multiple threads were calling location methods: https://gist.github.com/eregon/b78b7f266d7ee0a278a389cfd1782232 https://github.com/ruby/prism/commit/ff762dcccd
This commit is contained in:
Родитель
bf5cc9ef8c
Коммит
1b9b960963
|
@ -477,8 +477,9 @@ module Prism
|
||||||
|
|
||||||
# A Location object representing the location of this token in the source.
|
# A Location object representing the location of this token in the source.
|
||||||
def location
|
def location
|
||||||
return @location if @location.is_a?(Location)
|
location = @location
|
||||||
@location = Location.new(source, @location >> 32, @location & 0xFFFFFFFF)
|
return location if location.is_a?(Location)
|
||||||
|
@location = Location.new(source, location >> 32, location & 0xFFFFFFFF)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Implement the pretty print interface for Token.
|
# Implement the pretty print interface for Token.
|
||||||
|
|
|
@ -9,8 +9,9 @@ module Prism
|
||||||
# A Location instance that represents the location of this node in the
|
# A Location instance that represents the location of this node in the
|
||||||
# source.
|
# source.
|
||||||
def location
|
def location
|
||||||
return @location if @location.is_a?(Location)
|
location = @location
|
||||||
@location = Location.new(source, @location >> 32, @location & 0xFFFFFFFF)
|
return location if location.is_a?(Location)
|
||||||
|
@location = Location.new(source, location >> 32, location & 0xFFFFFFFF)
|
||||||
end
|
end
|
||||||
|
|
||||||
def newline? # :nodoc:
|
def newline? # :nodoc:
|
||||||
|
@ -196,18 +197,20 @@ module Prism
|
||||||
<%- case field -%>
|
<%- case field -%>
|
||||||
<%- when Prism::LocationField -%>
|
<%- when Prism::LocationField -%>
|
||||||
def <%= field.name %>
|
def <%= field.name %>
|
||||||
return @<%= field.name %> if @<%= field.name %>.is_a?(Location)
|
location = @<%= field.name %>
|
||||||
@<%= field.name %> = Location.new(source, @<%= field.name %> >> 32, @<%= field.name %> & 0xFFFFFFFF)
|
return location if location.is_a?(Location)
|
||||||
|
@<%= field.name %> = Location.new(source, location >> 32, location & 0xFFFFFFFF)
|
||||||
end
|
end
|
||||||
<%- when Prism::OptionalLocationField -%>
|
<%- when Prism::OptionalLocationField -%>
|
||||||
def <%= field.name %>
|
def <%= field.name %>
|
||||||
case @<%= field.name %>
|
location = @<%= field.name %>
|
||||||
|
case location
|
||||||
when nil
|
when nil
|
||||||
nil
|
nil
|
||||||
when Location
|
when Location
|
||||||
@<%= field.name %>
|
location
|
||||||
else
|
else
|
||||||
@<%= field.name %> = Location.new(source, @<%= field.name %> >> 32, @<%= field.name %> & 0xFFFFFFFF)
|
@<%= field.name %> = Location.new(source, location >> 32, location & 0xFFFFFFFF)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче