Skip to content

Commit

Permalink
Apply JRuby patches to stdlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 14, 2016
1 parent 9ec0f8b commit b34aa3d
Show file tree
Hide file tree
Showing 26 changed files with 4,592 additions and 436 deletions.
8 changes: 4 additions & 4 deletions ext/bigdecimal/lib/bigdecimal/ludcmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def lusolve(a,b,ps,zero=0.0)
end
x <<= b[ps[i]] - dot
end
(n-1).downto(0) do |i|
(n-1).downto(0) do |i2|
dot = zero
psin = ps[i]*n
for j in (i+1)...n do
psin = ps[i2]*n
for j in (i2+1)...n do
dot = a[psin+j].mult(x[j],prec) + dot
end
x[i] = (x[i]-dot).div(a[psin+i],prec)
x[i2] = (x[i2]-dot).div(a[psin+i2],prec)
end
x
end
Expand Down
16 changes: 15 additions & 1 deletion ext/bigdecimal/lib/bigdecimal/math.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: false
require 'bigdecimal'
require 'bigdecimal/util'

#
#--
Expand Down Expand Up @@ -227,6 +228,19 @@ def PI(prec)
#
def E(prec)
raise ArgumentError, "Zero or negative precision for E" if prec <= 0
BigMath.exp(1, prec)
n = prec + BigDecimal.double_fig
one = BigDecimal("1")
y = one
d = y
z = one
i = 0
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
m = BigDecimal.double_fig if m < BigDecimal.double_fig
i += 1
z *= i
d = one.div(z,m)
y += d
end
y
end
end
37 changes: 19 additions & 18 deletions ext/digest/lib/digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ module Digest
REQUIRE_MUTEX = Thread::Mutex.new

def self.const_missing(name) # :nodoc:
case name
when :SHA256, :SHA384, :SHA512
lib = 'digest/sha2.so'
else
lib = File.join('digest', name.to_s.downcase)
end
Digest::REQUIRE_MUTEX.synchronize do
case name
when :SHA256, :SHA384, :SHA512
lib = 'digest/sha2.so'
else
lib = File.join('digest', name.to_s.downcase)
end

begin
require lib
rescue LoadError
raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
end
unless Digest.const_defined?(name)
raise NameError, "uninitialized constant Digest::#{name}", caller(1)
begin
require lib
rescue LoadError
raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
end
unless Digest.const_defined?(name)
raise NameError, "uninitialized constant Digest::#{name}", caller(1)
end
Digest.const_get(name)
end
Digest.const_get(name)
end

class ::Digest::Class
Expand Down Expand Up @@ -95,10 +97,9 @@ def base64digest!
# # => LoadError: library not found for class Digest::Foo -- digest/foo
def Digest(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)
}

# 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)
Expand Down
32 changes: 26 additions & 6 deletions ext/fiddle/lib/fiddle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: false
require 'fiddle.so'
require 'fiddle.so' unless RUBY_ENGINE == 'jruby'
require 'fiddle/jruby' if RUBY_ENGINE == 'jruby'
require 'fiddle/function'
require 'fiddle/closure'

Expand All @@ -8,24 +9,43 @@ module Fiddle
# Returns the last win32 +Error+ of the current executing +Thread+ or nil
# if none
def self.win32_last_error
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
if RUBY_ENGINE == 'jruby'
errno = FFI.errno
errno = nil if errno == 0

This comment has been minimized.

Copy link
@nobu

nobu Mar 15, 2017

This always results in nil, doesn't it?

This comment has been minimized.

Copy link
@nobu

nobu Mar 15, 2017

Probably you want just FFI.errno.nonzero?.

This comment has been minimized.

Copy link
@headius

headius Nov 22, 2017

Author Member

@nobu Thanks, did not see this comment.

else
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
end
end

# Sets the last win32 +Error+ of the current executing +Thread+ to +error+
def self.win32_last_error= error
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
if RUBY_ENGINE == 'jruby'
FFI.errno = error || 0
else
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
end
end
end

# Returns the last +Error+ of the current executing +Thread+ or nil if none
def self.last_error
Thread.current[:__FIDDLE_LAST_ERROR__]
if RUBY_ENGINE == 'jruby'
errno = FFI.errno
errno = nil if errno == 0
errno
else
Thread.current[:__FIDDLE_LAST_ERROR__]
end
end

# Sets the last +Error+ of the current executing +Thread+ to +error+
def self.last_error= error
Thread.current[:__DL2_LAST_ERROR__] = error
Thread.current[:__FIDDLE_LAST_ERROR__] = error
if RUBY_ENGINE == 'jruby'
FFI.errno = error || 0
else
Thread.current[:__DL2_LAST_ERROR__] = error
Thread.current[:__FIDDLE_LAST_ERROR__] = error
end
end

# call-seq: dlopen(library) => Fiddle::Handle
Expand Down
Loading

0 comments on commit b34aa3d

Please sign in to comment.