зеркало из 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 args;
|
||||
VALUE normalized_args;
|
||||
VALUE abi;
|
||||
fiddle_closure * cl;
|
||||
ffi_cif * cif;
|
||||
|
@ -239,21 +240,26 @@ initialize(int rbargc, VALUE argv[], VALUE self)
|
|||
|
||||
cl->argv = (ffi_type **)xcalloc(argc + 1, sizeof(ffi_type *));
|
||||
|
||||
normalized_args = rb_ary_new_capa(argc);
|
||||
for (i = 0; i < argc; i++) {
|
||||
int type = NUM2INT(RARRAY_AREF(args, i));
|
||||
cl->argv[i] = INT2FFI_TYPE(type);
|
||||
VALUE arg = rb_fiddle_type_ensure(RARRAY_AREF(args, i));
|
||||
rb_ary_push(normalized_args, arg);
|
||||
cl->argv[i] = rb_fiddle_int_to_ffi_type(NUM2INT(arg));
|
||||
}
|
||||
cl->argv[argc] = NULL;
|
||||
|
||||
ret = rb_fiddle_type_ensure(ret);
|
||||
rb_iv_set(self, "@ctype", ret);
|
||||
rb_iv_set(self, "@args", args);
|
||||
rb_iv_set(self, "@args", normalized_args);
|
||||
|
||||
cif = &cl->cif;
|
||||
pcl = cl->pcl;
|
||||
|
||||
result = ffi_prep_cif(cif, NUM2INT(abi), argc,
|
||||
INT2FFI_TYPE(NUM2INT(ret)),
|
||||
cl->argv);
|
||||
result = ffi_prep_cif(cif,
|
||||
NUM2INT(abi),
|
||||
argc,
|
||||
rb_fiddle_int_to_ffi_type(NUM2INT(ret)),
|
||||
cl->argv);
|
||||
|
||||
if (FFI_OK != result)
|
||||
rb_raise(rb_eRuntimeError, "error prepping CIF %d", result);
|
||||
|
|
|
@ -20,6 +20,18 @@ module Fiddle
|
|||
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
|
||||
closure = Class.new(Closure) {
|
||||
def call
|
||||
|
|
Загрузка…
Ссылка в новой задаче