зеркало из https://github.com/github/ruby.git
[ruby/fiddle] closure: accept symbol as type
https://github.com/ruby/fiddle/commit/dc2da6633e
This commit is contained in:
Родитель
212d836cd7
Коммит
b2de5999d8
|
@ -221,6 +221,7 @@ initialize(int rbargc, VALUE argv[], VALUE self)
|
||||||
{
|
{
|
||||||
VALUE ret;
|
VALUE ret;
|
||||||
VALUE args;
|
VALUE args;
|
||||||
|
VALUE normalized_args;
|
||||||
VALUE abi;
|
VALUE abi;
|
||||||
fiddle_closure * cl;
|
fiddle_closure * cl;
|
||||||
ffi_cif * cif;
|
ffi_cif * cif;
|
||||||
|
@ -239,21 +240,26 @@ initialize(int rbargc, VALUE argv[], VALUE self)
|
||||||
|
|
||||||
cl->argv = (ffi_type **)xcalloc(argc + 1, sizeof(ffi_type *));
|
cl->argv = (ffi_type **)xcalloc(argc + 1, sizeof(ffi_type *));
|
||||||
|
|
||||||
|
normalized_args = rb_ary_new_capa(argc);
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
int type = NUM2INT(RARRAY_AREF(args, i));
|
VALUE arg = rb_fiddle_type_ensure(RARRAY_AREF(args, i));
|
||||||
cl->argv[i] = INT2FFI_TYPE(type);
|
rb_ary_push(normalized_args, arg);
|
||||||
|
cl->argv[i] = rb_fiddle_int_to_ffi_type(NUM2INT(arg));
|
||||||
}
|
}
|
||||||
cl->argv[argc] = NULL;
|
cl->argv[argc] = NULL;
|
||||||
|
|
||||||
|
ret = rb_fiddle_type_ensure(ret);
|
||||||
rb_iv_set(self, "@ctype", ret);
|
rb_iv_set(self, "@ctype", ret);
|
||||||
rb_iv_set(self, "@args", args);
|
rb_iv_set(self, "@args", normalized_args);
|
||||||
|
|
||||||
cif = &cl->cif;
|
cif = &cl->cif;
|
||||||
pcl = cl->pcl;
|
pcl = cl->pcl;
|
||||||
|
|
||||||
result = ffi_prep_cif(cif, NUM2INT(abi), argc,
|
result = ffi_prep_cif(cif,
|
||||||
INT2FFI_TYPE(NUM2INT(ret)),
|
NUM2INT(abi),
|
||||||
cl->argv);
|
argc,
|
||||||
|
rb_fiddle_int_to_ffi_type(NUM2INT(ret)),
|
||||||
|
cl->argv);
|
||||||
|
|
||||||
if (FFI_OK != result)
|
if (FFI_OK != result)
|
||||||
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
|
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
|
||||||
|
|
|
@ -20,6 +20,18 @@ module Fiddle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_type_symbol
|
||||||
|
closure = Closure.new(:int, [:void])
|
||||||
|
assert_equal([
|
||||||
|
TYPE_INT,
|
||||||
|
[TYPE_VOID],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
closure.instance_variable_get(:@ctype),
|
||||||
|
closure.instance_variable_get(:@args),
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
def test_call
|
def test_call
|
||||||
closure = Class.new(Closure) {
|
closure = Class.new(Closure) {
|
||||||
def call
|
def call
|
||||||
|
|
Загрузка…
Ссылка в новой задаче