diff options
author | Sutou Kouhei <[email protected]> | 2024-10-07 11:03:10 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-10-10 10:05:52 +0900 |
commit | a47f153d9d951166f8442e3b2c7036505385a953 (patch) | |
tree | dbf0da6b6ecc59c509cb1cba8a7eba879fb83335 /test/fiddle/test_function.rb | |
parent | a392ee1437efbaa84edf3412bb96a5d667a08387 (diff) |
Import JRuby implementation (#147)
Fix GH-104
lib/fiddle/jruby.rb is based on
https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/fiddle/jruby.rb
.
Here are changes for it:
* Move `Fiddle::TYPE_*` to `Fiddle::Types::*`
* Add `Fiddle::Types::VARIADIC`
* Add `Fiddle::Types::CONST_STRING`
* Add `Fiddle::Types::BOOL`
* Add `Fiddle::Types::INT8_T`
* Add `Fiddle::Types::UINT8_T`
* Add `Fiddle::Types::INT16_T`
* Add `Fiddle::Types::UINT16_T`
* Add `Fiddle::Types::INT32_T`
* Add `Fiddle::Types::UINT32_T`
* Add `Fiddle::Types::INT64_T`
* Add `Fiddle::Types::UINT64_T`
* Add more `Fiddle::ALIGN_*` for the above new `Fiddle::Types::*`
* Add more `Fiddle::SIZEOF_*` for the above new `Fiddle::Types::*`
* Add support for specifying type as not only `Fiddle::Types::*` but
also `Symbol` like `:int`
* Add support for variable size arguments in `Fiddle::Function`
* Add `Fiddle::Closure#free`
* Add `Fiddle::Closure#freed?`
* Add `Fiddle::Error` as base the error class
* Add `Fiddle::Pointer#call_free` and stop using `FFI::AutoPointer` in
`Fiddle::Pointer`
* Add support for `Fiddle::Pointer.malloc {}` `Fiddle::Pointer`
* Add support for `Fiddle::Pointer#free=`
* Add `Fiddle::Pointer#freed?`
* Use binary string not C string for `Fiddle::Pointer#[]`
* Add `Fiddle::Handle.sym_defined?`
* Add `Fiddle::Handle#sym_defined?`
* Add `Fiddle::Handle::DEFAULT`
* Add `Fiddle::ClearedReferenceError`
* Add no-op `Fiddle::Pinned`
Some features are still "not implemented". So there are some "omit"s for
JRuby in tests.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11860
Diffstat (limited to 'test/fiddle/test_function.rb')
-rw-r--r-- | test/fiddle/test_function.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb index 2bd67c9da1..658874bfb4 100644 --- a/test/fiddle/test_function.rb +++ b/test/fiddle/test_function.rb @@ -16,6 +16,8 @@ module Fiddle end def teardown + # We can't use ObjectSpace with JRuby. + return if RUBY_ENGINE == "jruby" # Ensure freeing all closures. # See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 . not_freed_closures = [] @@ -36,6 +38,10 @@ module Fiddle end def test_need_gvl? + if RUBY_ENGINE == "jruby" + omit("rb_str_dup() doesn't exit in JRuby") + end + libruby = Fiddle.dlopen(nil) rb_str_dup = Function.new(libruby['rb_str_dup'], [:voidp], @@ -103,6 +109,10 @@ module Fiddle end def test_last_error + if RUBY_ENGINE == "jruby" + omit("Fiddle.last_error doesn't work with JRuby") + end + func = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) assert_nil Fiddle.last_error @@ -135,6 +145,10 @@ module Fiddle end def test_strcpy + if RUBY_ENGINE == "jruby" + omit("Function that returns string doesn't work with JRuby") + end + f = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) buff = +"000" str = f.call(buff, "123") @@ -149,6 +163,10 @@ module Fiddle end def test_function_as_proc + if RUBY_ENGINE == "jruby" + omit("Function that returns string doesn't work with JRuby") + end + f = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) buff, str = call_proc("123", &f) assert_equal("123", buff) @@ -156,6 +174,10 @@ module Fiddle end def test_function_as_method + if RUBY_ENGINE == "jruby" + omit("Function that returns string doesn't work with JRuby") + end + f = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) klass = Class.new do define_singleton_method(:strcpy, &f) @@ -194,6 +216,10 @@ module Fiddle end def test_no_memory_leak + if RUBY_ENGINE == "jruby" + omit("rb_obj_frozen_p() doesn't exist in JRuby") + end + if respond_to?(:assert_nothing_leaked_memory) rb_obj_frozen_p_symbol = Fiddle.dlopen(nil)["rb_obj_frozen_p"] rb_obj_frozen_p = Fiddle::Function.new(rb_obj_frozen_p_symbol, |