diff options
author | Sutou Kouhei <kou@clear-code.com> | 2020-07-09 21:39:51 +0900 |
---|---|---|
committer | Sutou Kouhei <kou@cozmixng.org> | 2020-11-18 09:05:13 +0900 |
commit | e2dfc0c26b1f3d3517002ca2645d1b67847fe518 (patch) | |
tree | 943da48b87240b9b32c7885d332ef1488f270b6f /ext/fiddle/function.c | |
parent | ae7b53546ca18b56c23f612b6935e98268a07602 (diff) |
[ruby/fiddle] Add support for specifying types by name as String or Symbol
For example, :voidp equals to Fiddle::TYPE_VOID_P.
https://github.com/ruby/fiddle/commit/3b4de54899
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3780
Diffstat (limited to 'ext/fiddle/function.c')
-rw-r--r-- | ext/fiddle/function.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c index 8771dd3e30..437dbb624a 100644 --- a/ext/fiddle/function.c +++ b/ext/fiddle/function.c @@ -106,7 +106,9 @@ normalize_argument_types(const char *name, normalized_arg_types = rb_ary_new_capa(n_arg_types); for (i = 0; i < n_arg_types; i++) { VALUE arg_type = RARRAY_AREF(arg_types, i); - int c_arg_type = NUM2INT(arg_type); + int c_arg_type; + arg_type = rb_fiddle_type_ensure(arg_type); + c_arg_type = NUM2INT(arg_type); if (c_arg_type == TYPE_VARIADIC) { if (i != n_arg_types - 1) { rb_raise(rb_eArgError, @@ -146,6 +148,7 @@ initialize(int argc, VALUE argv[], VALUE self) PTR2NUM(cfunc); c_ffi_abi = NIL_P(abi) ? FFI_DEFAULT_ABI : NUM2INT(abi); abi = INT2FIX(c_ffi_abi); + ret_type = rb_fiddle_type_ensure(ret_type); c_ret_type = NUM2INT(ret_type); (void)INT2FFI_TYPE(c_ret_type); /* raise */ ret_type = INT2FIX(c_ret_type); @@ -256,7 +259,9 @@ function_call(int argc, VALUE argv[], VALUE self) arg_types = rb_ary_dup(fixed_arg_types); for (i = n_fixed_args; i < argc; i += 2) { VALUE arg_type = argv[i]; - int c_arg_type = NUM2INT(arg_type); + int c_arg_type; + arg_type = rb_fiddle_type_ensure(arg_type); + c_arg_type = NUM2INT(arg_type); (void)INT2FFI_TYPE(c_arg_type); /* raise */ rb_ary_push(arg_types, INT2FIX(c_arg_type)); } |