Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f9fbfa789ad1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0a172df9f0c5
Choose a head ref
  • 2 commits
  • 29 files changed
  • 1 contributor

Commits on Dec 10, 2014

  1. Copy the full SHA
    f192460 View commit details
  2. Update 2.2 revision number.

    headius committed Dec 10, 2014
    Copy the full SHA
    0a172df View commit details
2 changes: 1 addition & 1 deletion default.build.properties
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ version.ruby=2.2.0
version.ruby.major=2.2
version.ruby.minor=0
version.ruby.patchlevel=0
version.ruby.revision=48175
version.ruby.revision=48765

version.ruby1_9.major=1.9
version.ruby1_9=1.9.3
10 changes: 9 additions & 1 deletion lib/ruby/stdlib/csv.rb
Original file line number Diff line number Diff line change
@@ -1470,7 +1470,15 @@ def self.table(path, options = Hash.new)
# if the data cannot be transcoded,
# leaving the header unchanged.
# <b><tt>:skip_blanks</tt></b>:: When set to a +true+ value, CSV will
# skip over any rows with no content.
# skip over any empty rows. Note that
# this setting will not skip rows that
# contain column separators, even if
# the rows contain no actual data. If
# you want to skip rows that contain
# separators but no content, consider
# using <tt>:skip_lines</tt>, or
# inspecting fields.compact.empty? on
# each row.
# <b><tt>:force_quotes</tt></b>:: When set to a +true+ value, CSV will
# quote all CSV fields it creates.
# <b><tt>:skip_lines</tt></b>:: When set to an object responding to
24 changes: 21 additions & 3 deletions lib/ruby/stdlib/digest.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'digest.so'

module Digest
# A mutex for Digest().
REQUIRE_MUTEX = Mutex.new

def self.const_missing(name) # :nodoc:
case name
when :SHA256, :SHA384, :SHA512
@@ -76,15 +79,30 @@ def base64digest!
# call-seq:
# Digest(name) -> digest_subclass
#
# Returns a Digest subclass by +name+.
# Returns a Digest subclass by +name+ in a thread-safe manner even
# when on-demand loading is involved.
#
# require 'digest'
#
# Digest("MD5")
# # => Digest::MD5
#
# Digest("Foo")
# Digest(:SHA256)
# # => Digest::SHA256
#
# Digest(:Foo)
# # => LoadError: library not found for class Digest::Foo -- digest/foo
def Digest(name)
Digest.const_get(name)
const = name.to_sym
Digest::REQUIRE_MUTEX.synchronize {
# Ignore autoload's because it is void when we have #const_missing
Digest.const_missing(const)
}
rescue LoadError
# Constants do not necessarily rely on digest/*.
if Digest.const_defined?(const)
Digest.const_get(const)
else
raise
end
end
115 changes: 104 additions & 11 deletions lib/ruby/stdlib/matrix.rb
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ module ExceptionForMatrix # :nodoc:
# * #minor(*param)
# * #first_minor(row, column)
# * #cofactor(row, column)
# * #adjugate
# * #laplace_expansion(row_or_column: num)
# * #cofactor_expansion(row_or_column: num)
#
@@ -444,7 +445,7 @@ def collect(&block) # :yield: e

#
# Yields all elements of the matrix, starting with those of the first row,
# or returns an Enumerator is no block given.
# or returns an Enumerator if no block given.
# Elements can be restricted by passing an argument:
# * :all (default): yields all elements
# * :diagonal: yields only elements on the diagonal
@@ -689,6 +690,20 @@ def cofactor(row, column)
det_of_minor * (-1) ** (row + column)
end

#
# Returns the adjugate of the matrix.
#
# Matrix[ [7,6],[3,9] ].adjugate
# => 9 -6
# -3 7
#
def adjugate
Matrix.Raise ErrDimensionMismatch unless square?
Matrix.build(row_count, column_count) do |row, column|
cofactor(column, row)
end
end

#
# Returns the Laplace expansion along given row or column.
#
@@ -1676,6 +1691,11 @@ def ** (other)
# * #each2(v)
# * #collect2(v)
#
# Properties of vectors:
# * #angle_with(v)
# * Vector.independent?(*vs)
# * #independent?(*vs)
#
# Vector arithmetic:
# * #*(x) "is matrix or number"
# * #+(v)
@@ -1684,8 +1704,8 @@ def ** (other)
# * #-@
#
# Vector functions:
# * #inner_product(v)
# * #cross_product(v)
# * #inner_product(v), dot(v)
# * #cross_product(v), cross(v)
# * #collect
# * #magnitude
# * #map
@@ -1816,6 +1836,41 @@ def collect2(v) # :yield: e1, e2
end
end

#--
# PROPERTIES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++

#
# Returns +true+ iff all of vectors are linearly independent.
#
# Vector.independent?(Vector[1,0], Vector[0,1])
# => true
#
# Vector.independent?(Vector[1,2], Vector[2,4])
# => false
#
def Vector.independent?(*vs)
vs.each do |v|
raise TypeError, "expected Vector, got #{v.class}" unless v.is_a?(Vector)
Vector.Raise ErrDimensionMismatch unless v.size == vs.first.size
end
return false if vs.count > vs.first.size
Matrix[*vs].rank.eql?(vs.count)
end

#
# Returns +true+ iff all of vectors are linearly independent.
#
# Vector[1,0].independent?(Vector[0,1])
# => true
#
# Vector[1,2].independent?(Vector[2,4])
# => false
#
def independent?(*vs)
self.class.independent?(self, *vs)
end

#--
# COMPARING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
@@ -1834,14 +1889,14 @@ def eql?(other)
end

#
# Return a copy of the vector.
# Returns a copy of the vector.
#
def clone
self.class.elements(@elements)
end

#
# Return a hash-code for the vector.
# Returns a hash-code for the vector.
#
def hash
@elements.hash
@@ -1944,17 +1999,41 @@ def inner_product(v)
}
p
end
alias_method :dot, :inner_product

#
# Returns the cross product of this vector with the other.
# Returns the cross product of this vector with the others.
# Vector[1, 0, 0].cross_product Vector[0, 1, 0] => Vector[0, 0, 1]
#
def cross_product(v)
Vector.Raise ErrDimensionMismatch unless size == v.size && v.size == 3
Vector[ v[2]*@elements[1] - v[1]*@elements[2],
v[0]*@elements[2] - v[2]*@elements[0],
v[1]*@elements[0] - v[0]*@elements[1] ]
# It is generalized to other dimensions to return a vector perpendicular
# to the arguments.
# Vector[1, 2].cross_product # => Vector[-2, 1]
# Vector[1, 0, 0, 0].cross_product(
# Vector[0, 1, 0, 0],
# Vector[0, 0, 1, 0]
# ) #=> Vector[0, 0, 0, 1]
#
def cross_product(*vs)
raise ErrOperationNotDefined, "cross product is not defined on vectors of dimension #{size}" unless size >= 2
raise ArgumentError, "wrong number of arguments (#{vs.size} for #{size - 2})" unless vs.size == size - 2
vs.each do |v|
raise TypeError, "expected Vector, got #{v.class}" unless v.is_a? Vector
Vector.Raise ErrDimensionMismatch unless v.size == size
end
case size
when 2
Vector[-@elements[1], @elements[0]]
when 3
v = vs[0]
Vector[ v[2]*@elements[1] - v[1]*@elements[2],
v[0]*@elements[2] - v[2]*@elements[0],
v[1]*@elements[0] - v[0]*@elements[1] ]
else
rows = self, *vs, Array.new(size) {|i| Vector.basis(size: size, index: i) }
Matrix.rows(rows).laplace_expansion(row: size - 1)
end
end
alias_method :cross, :cross_product

#
# Like Array#collect.
@@ -1999,6 +2078,20 @@ def normalize
self / n
end

#
# Returns an angle with another vector. Result is within the [0...Math::PI].
# Vector[1,0].angle_with(Vector[0,1])
# # => Math::PI / 2
#
def angle_with(v)
raise TypeError, "Expected a Vector, got a #{v.class}" unless v.is_a?(Vector)
Vector.Raise ErrDimensionMismatch if size != v.size
prod = magnitude * v.magnitude
raise ZeroVectorError, "Can't get angle of zero vector" if prod == 0

Math.acos( inner_product(v) / prod )
end

#--
# CONVERTING
#++
5 changes: 4 additions & 1 deletion lib/ruby/stdlib/net/http.rb
Original file line number Diff line number Diff line change
@@ -918,7 +918,10 @@ def connect
@socket.write(buf)
HTTPResponse.read_new(@socket).value
end
s.session = @ssl_session if @ssl_session
if @ssl_session and
Process.clock_gettime(Process::CLOCK_REALTIME) < @ssl_session.time.to_f + @ssl_session.timeout
s.session = @ssl_session if @ssl_session
end
# Server Name Indication (SNI) RFC 3546
s.hostname = @address if s.respond_to? :hostname=
Timeout.timeout(@open_timeout, Net::OpenTimeout) { s.connect }
66 changes: 52 additions & 14 deletions lib/ruby/stdlib/net/imap.rb
Original file line number Diff line number Diff line change
@@ -788,8 +788,10 @@ def uid_search(keys, charset = nil)
# +attr+ is a list of attributes to fetch; see the documentation
# for Net::IMAP::FetchData for a list of valid attributes.
#
# The return value is an array of Net::IMAP::FetchData. For
# example:
# The return value is an array of Net::IMAP::FetchData or nil
# (instead of an empty array) if there is no matching message.
#
# For example:
#
# p imap.fetch(6..8, "UID")
# #=> [#<Net::IMAP::FetchData seqno=6, attr={"UID"=>98}>, \\
@@ -1254,9 +1256,7 @@ def validate_data(data)
when nil
when String
when Integer
if data < 0 || data >= 4294967296
raise DataFormatError, num.to_s
end
NumValidator.ensure_number(data)
when Array
data.each do |i|
validate_data(i)
@@ -1570,7 +1570,7 @@ def validate_internal(data)
case data
when "*"
when Integer
ensure_nz_number(data)
NumValidator.ensure_nz_number(data)
when Range
when Array
data.each do |i|
@@ -1584,11 +1584,42 @@ def validate_internal(data)
raise DataFormatError, data.inspect
end
end
end

# Common validators of number and nz_number types
module NumValidator # :nodoc
class << self
# Check is passed argument valid 'number' in RFC 3501 terminology
def valid_number?(num)
# [RFC 3501]
# number = 1*DIGIT
# ; Unsigned 32-bit integer
# ; (0 <= n < 4,294,967,296)
num >= 0 && num < 4294967296
end

# Check is passed argument valid 'nz_number' in RFC 3501 terminology
def valid_nz_number?(num)
# [RFC 3501]
# nz-number = digit-nz *DIGIT
# ; Non-zero unsigned 32-bit integer
# ; (0 < n < 4,294,967,296)
num != 0 && valid_number?(num)
end

def ensure_nz_number(num)
if num < -1 || num == 0 || num >= 4294967296
msg = "nz_number must be non-zero unsigned 32-bit integer: " +
num.inspect
# Ensure argument is 'number' or raise DataFormatError
def ensure_number(num)
return if valid_number?(num)

msg = "number must be unsigned 32-bit integer: #{num}"
raise DataFormatError, msg
end

# Ensure argument is 'nz_number' or raise DataFormatError
def ensure_nz_number(num)
return if valid_nz_number?(num)

msg = "nz_number must be non-zero unsigned 32-bit integer: #{num}"
raise DataFormatError, msg
end
end
@@ -2098,9 +2129,9 @@ def parse(str)

BEG_REGEXP = /\G(?:\
(?# 1: SPACE )( +)|\
(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\
(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\
(?# 4: ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+]+)|\
(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+])|\
(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+])|\
(?# 4: ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+]+)|\
(?# 5: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
(?# 6: LPAR )(\()|\
(?# 7: RPAR )(\))|\
@@ -2863,8 +2894,15 @@ def search_response
break
when T_SPACE
shift_token
else
when T_NUMBER
data.push(number)
when T_LPAR
# TODO: include the MODSEQ value in a response
shift_token
match(T_ATOM)
match(T_SPACE)
match(T_NUMBER)
match(T_RPAR)
end
end
else
Loading