Skip to content

Commit

Permalink
Update stdlib to Ruby 2.5.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Dec 12, 2018
1 parent 8249863 commit 7b964fd
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 116 deletions.
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/drb/extservm.rb
Expand Up @@ -37,7 +37,7 @@ def service(name)
synchronize do
while true
server = @servers[name]
return server if server&.alive?
return server if server && server.alive? # server may be `false'
invoke_service(name)
@cond.wait
end
Expand Down
17 changes: 4 additions & 13 deletions lib/ruby/stdlib/erb.rb
Expand Up @@ -291,7 +291,7 @@ class ERB
# <i>Generates</i>:
#
# #coding:UTF-8
# _erbout=+''; _erbout.<<(-"Got "); _erbout.<<(( obj ).to_s); _erbout.<<(-"!\n"); _erbout
# _erbout=+''; _erbout.<< "Got ".freeze; _erbout.<<(( obj ).to_s); _erbout.<< "!\n".freeze; _erbout
#
# By default the output is sent to the print method. For example:
#
Expand All @@ -302,7 +302,7 @@ class ERB
# <i>Generates</i>:
#
# #coding:UTF-8
# print(-"Got "); print(( obj ).to_s); print(-"!\n")
# print "Got ".freeze; print(( obj ).to_s); print "!\n".freeze
#
# == Evaluation
#
Expand Down Expand Up @@ -576,17 +576,8 @@ def close
end
end

def content_dump(s) # :nodoc:
n = s.count("\n")
if n > 0
s.dump << "\n" * n
else
s.dump
end
end

def add_put_cmd(out, content)
out.push("#{@put_cmd}(-#{content_dump(content)})")
out.push("#{@put_cmd} #{content.dump}.freeze#{"\n" * content.count("\n")}")
end

def add_insert_cmd(out, content)
Expand Down Expand Up @@ -668,7 +659,7 @@ def compile_content(stag, out)
when '<%='
add_insert_cmd(out, content)
when '<%#'
# out.push("# #{content_dump(content)}")
# commented out
end
end

Expand Down
8 changes: 0 additions & 8 deletions lib/ruby/stdlib/fiddle/jruby.rb
Expand Up @@ -164,14 +164,6 @@ def self.__freefunc__(free)
end
end

module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
MALLOC = attach_function :malloc, [ :size_t ], :pointer
REALLOC = attach_function :realloc, [ :pointer, :size_t ], :pointer
FREE = attach_function :free, [ :pointer ], :void
end

def self.malloc(size, free = nil)
self.new(LibC.malloc(size), size, free ? free : LibC::FREE)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby/stdlib/irb.rb
Expand Up @@ -527,7 +527,9 @@ def eval_input
printf "... %d levels...\n", levels if levels > 0
end
puts messages.reverse
print "#{attr[1]}#{exc.class} (#{attr[4]}#{exc}#{attr[0, 1]})#{attr[]}\n"
messages = exc.to_s.split(/\n/)
print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
print "Maybe IRB bug!\n" if irb_bug
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/net/ftp.rb
Expand Up @@ -1428,7 +1428,7 @@ def read(len = nil)
s = super(len, String.new, true)
return s.empty? ? nil : s
else
result = ""
result = String.new
while s = super(DEFAULT_BLOCKSIZE, String.new, true)
break if s.empty?
result << s
Expand Down
14 changes: 7 additions & 7 deletions lib/ruby/stdlib/net/imap.rb
Expand Up @@ -1323,11 +1323,11 @@ def send_data(data, tag = nil)
when nil
put_string("NIL")
when String
send_string_data(data)
send_string_data(data, tag)
when Integer
send_number_data(data)
when Array
send_list_data(data)
send_list_data(data, tag)
when Time
send_time_data(data)
when Symbol
Expand All @@ -1337,13 +1337,13 @@ def send_data(data, tag = nil)
end
end

def send_string_data(str)
def send_string_data(str, tag = nil)
case str
when ""
put_string('""')
when /[\x80-\xff\r\n]/n
# literal
send_literal(str)
send_literal(str, tag)
when /[(){ \x00-\x1f\x7f%*"\\]/n
# quoted string
send_quoted_string(str)
Expand All @@ -1356,7 +1356,7 @@ def send_quoted_string(str)
put_string('"' + str.gsub(/["\\]/n, "\\\\\\&") + '"')
end

def send_literal(str, tag)
def send_literal(str, tag = nil)
synchronize do
put_string("{" + str.bytesize.to_s + "}" + CRLF)
@continued_command_tag = tag
Expand All @@ -1377,7 +1377,7 @@ def send_number_data(num)
put_string(num.to_s)
end

def send_list_data(list)
def send_list_data(list, tag = nil)
put_string("(")
first = true
list.each do |i|
Expand All @@ -1386,7 +1386,7 @@ def send_list_data(list)
else
put_string(" ")
end
send_data(i)
send_data(i, tag)
end
put_string(")")
end
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby/stdlib/net/pop.rb
Expand Up @@ -467,7 +467,7 @@ def disable_ssl

# Provide human-readable stringification of class state.
def inspect
"#<#{self.class} #{@address}:#{@port} open=#{@started}>"
+"#<#{self.class} #{@address}:#{@port} open=#{@started}>"
end

# *WARNING*: This method causes a serious security hole.
Expand Down Expand Up @@ -758,7 +758,7 @@ def initialize(num, len, pop, cmd) #:nodoc:

# Provide human-readable stringification of class state.
def inspect
"#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>"
+"#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>"
end

#
Expand Down Expand Up @@ -799,7 +799,7 @@ def inspect
#
# This method raises a POPError if an error occurs.
#
def pop( dest = '', &block ) # :yield: message_chunk
def pop( dest = +'', &block ) # :yield: message_chunk
if block_given?
@command.retr(@number, &block)
nil
Expand All @@ -819,7 +819,7 @@ def pop( dest = '', &block ) # :yield: message_chunk
# The optional +dest+ argument is obsolete.
#
# This method raises a POPError if an error occurs.
def top(lines, dest = '')
def top(lines, dest = +'')
@command.top(@number, lines) do |chunk|
dest << chunk
end
Expand All @@ -831,7 +831,7 @@ def top(lines, dest = '')
# The optional +dest+ argument is obsolete.
#
# This method raises a POPError if an error occurs.
def header(dest = '')
def header(dest = +'')
top(0, dest)
end

Expand Down Expand Up @@ -898,7 +898,7 @@ def initialize(sock)
attr_reader :socket

def inspect
"#<#{self.class} socket=#{@socket}>"
+"#<#{self.class} socket=#{@socket}>"
end

def auth(account, password)
Expand Down
105 changes: 33 additions & 72 deletions lib/ruby/stdlib/resolv.rb
Expand Up @@ -727,10 +727,6 @@ def close
socks&.each(&:close)
end

def lazy_initialize
self
end

class Sender # :nodoc:
def initialize(msg, data, sock)
@msg = msg
Expand All @@ -743,66 +739,49 @@ class UnconnectedUDP < Requester # :nodoc:
def initialize(*nameserver_port)
super()
@nameserver_port = nameserver_port
@mutex = Thread::Mutex.new
@initialized = false
end

def lazy_initialize
@mutex.synchronize {
next if @initialized
@initialized = true
@socks_hash = {}
@socks = []
@nameserver_port.each {|host, port|
if host.index(':')
bind_host = "::"
af = Socket::AF_INET6
else
bind_host = "0.0.0.0"
af = Socket::AF_INET
end
next if @socks_hash[bind_host]
begin
sock = UDPSocket.new(af)
rescue Errno::EAFNOSUPPORT
next # The kernel doesn't support the address family.
end
@socks << sock
@socks_hash[bind_host] = sock
sock.do_not_reverse_lookup = true
DNS.bind_random_port(sock, bind_host)
}
@socks_hash = {}
@socks = []
nameserver_port.each {|host, port|
if host.index(':')
bind_host = "::"
af = Socket::AF_INET6
else
bind_host = "0.0.0.0"
af = Socket::AF_INET
end
next if @socks_hash[bind_host]
begin
sock = UDPSocket.new(af)
rescue Errno::EAFNOSUPPORT
next # The kernel doesn't support the address family.
end
sock.do_not_reverse_lookup = true
DNS.bind_random_port(sock, bind_host)
@socks << sock
@socks_hash[bind_host] = sock
}
self
end

def recv_reply(readable_socks)
lazy_initialize
reply, from = readable_socks[0].recvfrom(UDPSize)
return reply, [IPAddr.new(from[3]),from[1]]
end

def sender(msg, data, host, port=Port)
lazy_initialize
sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
return nil if !sock
service = [IPAddr.new(host), port]
id = DNS.allocate_request_id(service[0], service[1])
id = DNS.allocate_request_id(host, port)
request = msg.encode
request[0,2] = [id].pack('n')
return @senders[[service, id]] =
Sender.new(request, data, sock, host, port)
end

def close
@mutex.synchronize {
if @initialized
super
@senders.each_key {|service, id|
DNS.free_request_id(service[0], service[1], id)
}
@initialized = false
end
super
@senders.each_key {|service, id|
DNS.free_request_id(service[0], service[1], id)
}
end

Expand All @@ -824,34 +803,22 @@ def send
class ConnectedUDP < Requester # :nodoc:
def initialize(host, port=Port)
super()
@mutex = Thread::Mutex.new
@host = host
@port = port
@initialized = false
end

def lazy_initialize
@mutex.synchronize {
next if @initialized
@initialized = true
is_ipv6 = @host.index(':')
sock = UDPSocket.new(is_ipv6 ? Socket::AF_INET6 : Socket::AF_INET)
@socks = [sock]
sock.do_not_reverse_lookup = true
DNS.bind_random_port(sock, is_ipv6 ? "::" : "0.0.0.0")
sock.connect(@host, @port)
}
self
is_ipv6 = host.index(':')
sock = UDPSocket.new(is_ipv6 ? Socket::AF_INET6 : Socket::AF_INET)
@socks = [sock]
sock.do_not_reverse_lookup = true
DNS.bind_random_port(sock, is_ipv6 ? "::" : "0.0.0.0")
sock.connect(host, port)
end

def recv_reply(readable_socks)
lazy_initialize
reply = readable_socks[0].recv(UDPSize)
return reply, nil
end

def sender(msg, data, host=@host, port=@port)
lazy_initialize
unless host == @host && port == @port
raise RequestError.new("host/port don't match: #{host}:#{port}")
end
Expand All @@ -862,14 +829,9 @@ def sender(msg, data, host=@host, port=@port)
end

def close
@mutex.synchronize {
if @initialized
super
@senders.each_key {|from, id|
DNS.free_request_id(@host, @port, id)
}
@initialized = false
end
super
@senders.each_key {|from, id|
DNS.free_request_id(@host, @port, id)
}
end

Expand All @@ -884,7 +846,6 @@ def send

class MDNSOneShot < UnconnectedUDP # :nodoc:
def sender(msg, data, host, port=Port)
lazy_initialize
id = DNS.allocate_request_id(host, port)
request = msg.encode
request[0,2] = [id].pack('n')
Expand Down
7 changes: 1 addition & 6 deletions lib/ruby/stdlib/ripper/lexer.rb
Expand Up @@ -124,12 +124,7 @@ def _push_token(tok)
end

(SCANNER_EVENTS.map {|event|:"on_#{event}"} - private_instance_methods(false)).each do |event|
# FIXME: Our callee impl is broken and returns same result as __method__
# which is old method name and not new one.
define_method(event) { |tok|
@buf.push Elem.new([lineno(), column()], event, tok, state())
}
# alias_method event, :_push_token
alias_method event, :_push_token
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/time.rb
Expand Up @@ -575,7 +575,7 @@ def xmlschema(date)
T
(\d\d):(\d\d):(\d\d)
(\.\d+)?
(Z|[+-]\d\d:\d\d)?
(Z|[+-]\d\d(?::?\d\d)?)?
\s*\z/ix =~ date
year = $1.to_i
mon = $2.to_i
Expand Down

0 comments on commit 7b964fd

Please sign in to comment.