summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2020-06-01 07:50:39 +0200
committerLars Kanis <lars@greiz-reinsdorf.de>2020-06-01 07:53:09 +0200
commitabecee3c61aeb7f5af60c66378dbeaf0521a4e23 (patch)
tree8342cbe8573e851cee9ef9338715809d9dea6229
parent6624359868fd52245f7884fb1ce3db8682c52a39 (diff)
downloadffi-abecee3c61aeb7f5af60c66378dbeaf0521a4e23.tar.gz
Remove code required for ruby prior 2.3
Now that the gemspec requires ruby-2.3 or newer, compatibility code can be removed.
-rw-r--r--ext/ffi_c/Call.c6
-rw-r--r--ext/ffi_c/Function.c22
-rw-r--r--ext/ffi_c/Thread.c3
-rw-r--r--ext/ffi_c/Thread.h3
-rw-r--r--ext/ffi_c/extconf.rb7
-rw-r--r--spec/ffi/callback_spec.rb12
-rw-r--r--spec/ffi/struct_spec.rb25
-rw-r--r--spec/ffi/variadic_spec.rb1
8 files changed, 18 insertions, 61 deletions
diff --git a/ext/ffi_c/Call.c b/ext/ffi_c/Call.c
index 3fe816c..8db60f2 100644
--- a/ext/ffi_c/Call.c
+++ b/ext/ffi_c/Call.c
@@ -339,13 +339,7 @@ static void *
call_blocking_function(void* data)
{
rbffi_blocking_call_t* b = (rbffi_blocking_call_t *) data;
-#ifndef HAVE_RUBY_THREAD_HAS_GVL_P
- b->frame->has_gvl = false;
-#endif
ffi_call(&b->cif, FFI_FN(b->function), b->retval, b->ffiValues);
-#ifndef HAVE_RUBY_THREAD_HAS_GVL_P
- b->frame->has_gvl = true;
-#endif
return NULL;
}
diff --git a/ext/ffi_c/Function.c b/ext/ffi_c/Function.c
index 1bf751c..506d79b 100644
--- a/ext/ffi_c/Function.c
+++ b/ext/ffi_c/Function.c
@@ -99,26 +99,8 @@ static VALUE async_cb_event(void *);
static VALUE async_cb_call(void *);
#endif
-#ifdef HAVE_RUBY_THREAD_HAS_GVL_P
extern int ruby_thread_has_gvl_p(void);
-#define rbffi_thread_has_gvl_p(frame) ruby_thread_has_gvl_p()
-#else
-static int rbffi_thread_has_gvl_p(rbffi_frame_t *frame)
-{
- return frame != NULL && frame->has_gvl;
-}
-#endif
-
-#ifdef HAVE_RUBY_NATIVE_THREAD_P
extern int ruby_native_thread_p(void);
-#define rbffi_native_thread_p(frame) ruby_native_thread_p()
-#else
-static int rbffi_native_thread_p(rbffi_frame_t *frame)
-{
- return frame != NULL;
-}
-#endif
-
VALUE rbffi_FunctionClass = Qnil;
@@ -476,8 +458,8 @@ callback_invoke(ffi_cif* cif, void* retval, void** parameters, void* user_data)
if (cb.frame != NULL) cb.frame->exc = Qnil;
- if (rbffi_native_thread_p(cb.frame)) {
- if(rbffi_thread_has_gvl_p(cb.frame)) {
+ if (ruby_native_thread_p()) {
+ if(ruby_thread_has_gvl_p()) {
callback_with_gvl(&cb);
} else {
rb_thread_call_with_gvl(callback_with_gvl, &cb);
diff --git a/ext/ffi_c/Thread.c b/ext/ffi_c/Thread.c
index 10cdc5b..aab3344 100644
--- a/ext/ffi_c/Thread.c
+++ b/ext/ffi_c/Thread.c
@@ -74,9 +74,6 @@ void
rbffi_frame_push(rbffi_frame_t* frame)
{
memset(frame, 0, sizeof(*frame));
-#ifndef HAVE_RUBY_THREAD_HAS_GVL_P
- frame->has_gvl = true;
-#endif
frame->exc = Qnil;
#ifdef _WIN32
diff --git a/ext/ffi_c/Thread.h b/ext/ffi_c/Thread.h
index 485f2bb..46a65c6 100644
--- a/ext/ffi_c/Thread.h
+++ b/ext/ffi_c/Thread.h
@@ -66,9 +66,6 @@ typedef struct rbffi_frame {
struct thread_data* td;
#endif
struct rbffi_frame* prev;
-#ifndef HAVE_RUBY_THREAD_HAS_GVL_P
- bool has_gvl;
-#endif
VALUE exc;
} rbffi_frame_t;
diff --git a/ext/ffi_c/extconf.rb b/ext/ffi_c/extconf.rb
index 2e964c2..a9c7a07 100644
--- a/ext/ffi_c/extconf.rb
+++ b/ext/ffi_c/extconf.rb
@@ -45,13 +45,6 @@ if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
abort "system libffi is not usable" unless system_libffi_usable?
end
- have_func('rb_thread_call_without_gvl') || abort("Ruby C-API function `rb_thread_call_without_gvl` is missing")
- have_func('ruby_native_thread_p')
- if RUBY_VERSION >= "2.3.0"
- # On OSX and Linux ruby_thread_has_gvl_p() is detected but fails at runtime for ruby < 2.3.0
- have_func('ruby_thread_has_gvl_p')
- end
-
if system_libffi
have_func('ffi_prep_cif_var')
$defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
diff --git a/spec/ffi/callback_spec.rb b/spec/ffi/callback_spec.rb
index 019fd29..c8b9166 100644
--- a/spec/ffi/callback_spec.rb
+++ b/spec/ffi/callback_spec.rb
@@ -843,12 +843,10 @@ module CallbackInteropSpecs
end
# https://github.com/ffi/ffi/issues/527
- if RUBY_VERSION.split('.').map(&:to_i).pack("C*") >= [2,3,0].pack("C*") || RUBY_PLATFORM =~ /java/
- it "from fiddle to ffi" do
- assert_callback_in_same_thread_called_once do |block|
- func = FFI::Function.new(:void, [:pointer], &block)
- LibTestFiddle.testClosureVrV(Fiddle::Pointer[func.to_i])
- end
+ it "from fiddle to ffi" do
+ assert_callback_in_same_thread_called_once do |block|
+ func = FFI::Function.new(:void, [:pointer], &block)
+ LibTestFiddle.testClosureVrV(Fiddle::Pointer[func.to_i])
end
end
@@ -877,7 +875,7 @@ module CallbackInteropSpecs
end
# https://github.com/ffi/ffi/issues/527
- if RUBY_ENGINE == 'ruby' && RUBY_VERSION.split('.').map(&:to_i).pack("C*") >= [2,3,0].pack("C*")
+ if RUBY_ENGINE == 'ruby'
it "C outside ffi call stack does not deadlock [#527]" do
skip "not yet supported on TruffleRuby" if RUBY_ENGINE == "truffleruby"
path = File.join(File.dirname(__FILE__), "embed-test/embed-test.rb")
diff --git a/spec/ffi/struct_spec.rb b/spec/ffi/struct_spec.rb
index ea6c435..2989122 100644
--- a/spec/ffi/struct_spec.rb
+++ b/spec/ffi/struct_spec.rb
@@ -185,21 +185,18 @@ module StructSpecsStructTests
expect(mp.get_int64(4)).to eq(0xfee1deadbeef)
end
- rb_maj, rb_min = RUBY_VERSION.split('.')
- if rb_maj.to_i >= 1 && rb_min.to_i >= 9 || RUBY_PLATFORM =~ /java/
- it "Struct#layout withs with a hash of :name => type" do
- class HashLayout < FFI::Struct
- layout :a => :int, :b => :long_long
- end
- ll_off = (FFI::TYPE_UINT64.alignment == 4 ? 4 : 8)
- expect(HashLayout.size).to eq(ll_off + 8)
- mp = FFI::MemoryPointer.new(HashLayout.size)
- s = HashLayout.new mp
- s[:a] = 0x12345678
- expect(mp.get_int(0)).to eq(0x12345678)
- s[:b] = 0xfee1deadbeef
- expect(mp.get_int64(ll_off)).to eq(0xfee1deadbeef)
+ it "Struct#layout withs with a hash of :name => type" do
+ class HashLayout < FFI::Struct
+ layout :a => :int, :b => :long_long
end
+ ll_off = (FFI::TYPE_UINT64.alignment == 4 ? 4 : 8)
+ expect(HashLayout.size).to eq(ll_off + 8)
+ mp = FFI::MemoryPointer.new(HashLayout.size)
+ s = HashLayout.new mp
+ s[:a] = 0x12345678
+ expect(mp.get_int(0)).to eq(0x12345678)
+ s[:b] = 0xfee1deadbeef
+ expect(mp.get_int64(ll_off)).to eq(0xfee1deadbeef)
end
it "subclass overrides initialize without calling super" do
diff --git a/spec/ffi/variadic_spec.rb b/spec/ffi/variadic_spec.rb
index 0c7292e..0f1e077 100644
--- a/spec/ffi/variadic_spec.rb
+++ b/spec/ffi/variadic_spec.rb
@@ -33,7 +33,6 @@ describe "Function with variadic arguments" do
end
it 'can wrap a blocking function with varargs' do
- pending("not supported in 1.8") if RUBY_VERSION =~ /^1\.8\..*/
handle = LibTest.testBlockingOpen
expect(handle).not_to be_null
begin