You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MRI correctly aborts the execution of of a C function when the FFI::Function passed to it breaks. On JRuby (and Rubinius, for that matter), this doesn't happen. If the C function has a loop that would return early in case the callback returned -1, it even keeps calling the callback.
Consider this C code, which simply calls a callback 10 times, unless the callback function returns -1:
#include<stdio.h>typedefint (callback_fn) (void);
voidten_times(callback_fn*callback)
{
for (inti=1; i <= 10; i++) {
printf("libcallback: call #%i ...\n", i);
intrc= (*callback)();
if (rc==-1) {
printf("libcallback: early return because rc == -1\n");
return;
}
}
}
And here the Ruby script which attaches the function via FFI and verifies the bug with minitest:
The files needed to reproduce this bug, including a Makefile to build on OSX, are in this gist.
The text was updated successfully, but these errors were encountered:
paddor
changed the title
FFI::Function callback doesn't return block value to C
FFI: break from within a callback block behaves differently than on MRI
Dec 21, 2015
MRI correctly aborts the execution of of a C function when the FFI::Function passed to it
break
s. On JRuby (and Rubinius, for that matter), this doesn't happen. If the C function has a loop that would return early in case the callback returned -1, it even keeps calling the callback.Consider this C code, which simply calls a callback 10 times, unless the callback function returns -1:
And here the Ruby script which attaches the function via FFI and verifies the bug with minitest:
Here what I expect, as when run on Ruby 2.2.4:
Here the actual output on JRuby 9.0.4.0 (and also Rubinius 2.5.8):
The files needed to reproduce this bug, including a Makefile to build on OSX, are in this gist.
The text was updated successfully, but these errors were encountered: