Skip to content

Commit 40381b9

Browse files
committed
More updates to address the Rubinius/C-extensions bug.
1 parent a663bbd commit 40381b9

File tree

8 files changed

+41
-30
lines changed

8 files changed

+41
-30
lines changed

lib/concurrent/atomic.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,16 @@
5757
class Concurrent::Atomic < Concurrent::JavaAtomic
5858
end
5959

60-
elsif defined? Concurrent::CAtomic
60+
elsif defined? Concurrent::RbxAtomic
6161

62-
# @!macro [attach] concurrent_update_error
63-
#
64-
# This exception may be thrown by methods that have detected concurrent
65-
# modification of an object when such modification is not permissible.
66-
class Concurrent::Atomic < Concurrent::CAtomic
62+
# @!macro atomic_reference
63+
class Concurrent::Atomic < Concurrent::RbxAtomic
6764
end
6865

69-
elsif defined? Concurrent::RbxAtomic
66+
elsif Concurrent.allow_c_native_class?('CAtomic')
7067

7168
# @!macro atomic_reference
72-
class Concurrent::Atomic < Concurrent::RbxAtomic
69+
class Concurrent::Atomic < Concurrent::CAtomic
7370
end
7471

7572
else

lib/concurrent/atomic/atomic_boolean.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def make_false
162162
class AtomicBoolean < JavaAtomicBoolean
163163
end
164164

165-
elsif defined? Concurrent::CAtomicBoolean
165+
elsif Concurrent.allow_c_native_class?('CAtomicBoolean')
166166

167167
# @!macro atomic_boolean
168168
class CAtomicBoolean

lib/concurrent/atomic/atomic_fixnum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def compare_and_set(expect, update)
166166
class AtomicFixnum < JavaAtomicFixnum
167167
end
168168

169-
elsif defined? Concurrent::CAtomicFixnum
169+
elsif Concurrent.allow_c_native_class?('CAtomicFixnum')
170170

171171
# @!macro atomic_fixnum
172172
class CAtomicFixnum

lib/extension_helper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ def self.allow_c_extensions?
77

88
# @!visibility private
99
def self.allow_c_native_class?(clazz)
10-
allow_c_extensions? && defined?(clazz)
10+
allow_c_extensions? && defined?(Kernel.const_get("Concurrent::#{clazz}"))
11+
rescue
12+
false
1113
end
1214

1315
# @!visibility private
1416
def self.safe_require_c_extensions
15-
require 'concurrent_ruby_ext'
17+
require 'concurrent_ruby_ext' if allow_c_extensions?
1618
rescue LoadError
1719
warn 'Attempted to load C extensions on unsupported platform. Continuing with pure-Ruby.'
1820
end

spec/concurrent/atomic/atomic_boolean_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,28 @@ module Concurrent
158158
end
159159
end
160160

161-
if RUBY_PLATFORM == 'java'
161+
if TestHelpers.jruby?
162162

163163
describe JavaAtomicBoolean do
164164
it_should_behave_like :atomic_boolean
165165
end
166166
end
167167

168168
describe AtomicBoolean do
169-
if defined? Concurrent::CAtomicBoolean
170-
it 'inherits from CAtomicBoolean' do
171-
expect(AtomicBoolean.ancestors).to include(CAtomicBoolean)
169+
if RUBY_ENGINE != 'ruby'
170+
it 'does not load the C extension' do
171+
expect(defined?(Concurrent::CAtomicBoolean)).to be_falsey
172172
end
173-
elsif RUBY_PLATFORM == 'java'
173+
end
174+
175+
if TestHelpers.jruby?
174176
it 'inherits from JavaAtomicBoolean' do
175177
expect(AtomicBoolean.ancestors).to include(JavaAtomicBoolean)
176178
end
179+
elsif defined? Concurrent::CAtomicBoolean
180+
it 'inherits from CAtomicBoolean' do
181+
expect(AtomicBoolean.ancestors).to include(CAtomicBoolean)
182+
end
177183
else
178184
it 'inherits from MutexAtomicBoolean' do
179185
expect(AtomicBoolean.ancestors).to include(MutexAtomicBoolean)

spec/concurrent/atomic/atomic_fixnum_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,28 @@ module Concurrent
172172
end
173173
end
174174

175-
if RUBY_PLATFORM == 'java'
175+
if TestHelpers.jruby?
176176

177177
describe JavaAtomicFixnum do
178178
it_should_behave_like :atomic_fixnum
179179
end
180180
end
181181

182182
describe AtomicFixnum do
183-
if defined? Concurrent::CAtomicFixnum
184-
it 'inherits from CAtomicFixnum' do
185-
expect(AtomicFixnum.ancestors).to include(CAtomicFixnum)
183+
if RUBY_ENGINE != 'ruby'
184+
it 'does not load the C extension' do
185+
expect(defined?(Concurrent::CAtomicFixnum)).to be_falsey
186186
end
187-
elsif RUBY_PLATFORM == 'java'
187+
end
188+
189+
if TestHelpers.jruby?
188190
it 'inherits from JavaAtomicFixnum' do
189191
expect(AtomicFixnum.ancestors).to include(JavaAtomicFixnum)
190192
end
193+
elsif defined? Concurrent::CAtomicFixnum
194+
it 'inherits from CAtomicFixnum' do
195+
expect(AtomicFixnum.ancestors).to include(CAtomicFixnum)
196+
end
191197
else
192198
it 'inherits from MutexAtomicFixnum' do
193199
expect(AtomicFixnum.ancestors).to include(MutexAtomicFixnum)

spec/concurrent/atomic_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ module Concurrent
152152
end
153153

154154
describe Atomic do
155-
if TestHelpers.use_c_extensions?
156-
it 'inherits from CAtomic' do
157-
expect(Atomic.ancestors).to include(CAtomic)
158-
end
159-
elsif TestHelpers.jruby?
155+
if TestHelpers.jruby?
160156
it 'inherits from JavaAtomic' do
161157
expect(Atomic.ancestors).to include(JavaAtomic)
162158
end
159+
elsif TestHelpers.use_c_extensions?
160+
it 'inherits from CAtomic' do
161+
expect(Atomic.ancestors).to include(CAtomic)
162+
end
163163
elsif TestHelpers.rbx?
164164
it 'inherits from RbxAtomic' do
165165
expect(Atomic.ancestors).to include(RbxAtomic)

spec/support/example_group_extensions.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def delta(v1, v2)
1212
end
1313

1414
def mri?
15-
RbConfig::CONFIG['ruby_install_name']=~ /^ruby$/i
15+
RUBY_ENGINE == 'ruby'
1616
end
1717

1818
def jruby?
19-
RbConfig::CONFIG['ruby_install_name']=~ /^jruby$/i
19+
RUBY_ENGINE == 'jruby'
2020
end
2121

2222
def rbx?
23-
RbConfig::CONFIG['ruby_install_name']=~ /^rbx$/i
23+
RUBY_ENGINE == 'rbx'
2424
end
2525

2626
def use_c_extensions?

0 commit comments

Comments
 (0)