Last active
December 27, 2015 09:16
-
-
Save paddor/31a5d0191b6f2a1db157 to your computer and use it in GitHub Desktop.
Rubinius: FFI::Function doesn't return break value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (callback_fn) (void); | |
void | |
call_callback(callback_fn *callback) | |
{ | |
(* callback)(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libcallback.dylib: callback.c | |
clang -dynamiclib -std=gnu99 callback.c -o $@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require 'ffi' | |
module LibCallback | |
extend ::FFI::Library | |
lib_name = 'libcallback' | |
ffi_lib "#{lib_name}.#{::FFI::Platform::LIBSUFFIX}" | |
attach_function :call_callback, [:pointer], :void, blocking: true | |
end | |
describe FFI::Function do | |
def foo | |
ret = nil | |
callback = FFI::Function.new(:void, [], blocking: true) do | |
ret = yield | |
end | |
LibCallback.call_callback(callback) | |
ret | |
end | |
it "returns block value" do | |
assert_equal :value, foo { :value } | |
end | |
describe "with breaking block" do | |
# NOTE: This is the one that fails on Rubinius 2.5.8 | |
it "returns break value" do | |
assert_equal :value, foo { break :value } | |
end | |
end | |
end | |
describe "pure Ruby block" do | |
def foo | |
yield | |
end | |
it "returns block value" do | |
assert_equal :value, foo { :value } | |
end | |
describe "with breaking block" do | |
it "returns break value" do | |
assert_equal :value, foo { break :value } | |
end | |
end | |
end | |
__END__ | |
## | |
# EXPECTED, as when run on Ruby 2.2.4 or JRuby 9.0.0.0 | |
Run options: --seed 7697 | |
# Running: | |
.... | |
Finished in 0.001665s, 2402.1095 runs/s, 2402.1095 assertions/s. | |
4 runs, 4 assertions, 0 failures, 0 errors, 0 skips | |
## | |
# ACTUAL, when run on Rubinius 2.5.8 | |
Run options: --seed 6069 | |
# Running tests: | |
.F.. | |
Finished tests in 0.077881s, 51.3604 tests/s, 51.3604 assertions/s. | |
1) Failure: | |
FFI::Function::with breaking block#test_0001_returns break value [/Users/paddor/src/ruby/cztop/rbx_ffi-callback_break_value/rbx_ffi-callback_break_value.rb:30]: | |
Expected: :value | |
Actual: nil | |
4 tests, 4 assertions, 1 failures, 0 errors, 0 skips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment