[ruby/fiddle] Fixed typos
https://github.com/ruby/fiddle/commit/a09e66adf4 https://github.com/ruby/fiddle/commit/6cab9b45d6 https://github.com/ruby/fiddle/commit/ab72b19bed
This commit is contained in:
parent
40b40523dc
commit
4949df498a
@ -93,7 +93,7 @@ initialize(int argc, VALUE argv[], VALUE self)
|
||||
ffi_cif * cif;
|
||||
ffi_type **arg_types, *rtype;
|
||||
ffi_status result;
|
||||
VALUE ptr, args, ret_type, abi, kwds, ary;
|
||||
VALUE ptr, args, ret_type, abi, kwds;
|
||||
int i, len;
|
||||
int nabi;
|
||||
void *cfunc;
|
||||
@ -113,14 +113,15 @@ initialize(int argc, VALUE argv[], VALUE self)
|
||||
Check_Type(args, T_ARRAY);
|
||||
len = RARRAY_LENINT(args);
|
||||
Check_Max_Args("args", len);
|
||||
ary = rb_ary_subseq(args, 0, len);
|
||||
/* freeze to prevent inconsistency at calling #to_int later */
|
||||
args = rb_ary_subseq(args, 0, len);
|
||||
for (i = 0; i < RARRAY_LEN(args); i++) {
|
||||
VALUE a = RARRAY_AREF(args, i);
|
||||
int type = NUM2INT(a);
|
||||
(void)INT2FFI_TYPE(type); /* raise */
|
||||
if (INT2FIX(type) != a) rb_ary_store(ary, i, INT2FIX(type));
|
||||
if (INT2FIX(type) != a) rb_ary_store(args, i, INT2FIX(type));
|
||||
}
|
||||
OBJ_FREEZE(ary);
|
||||
OBJ_FREEZE(args);
|
||||
|
||||
rb_iv_set(self, "@ptr", ptr);
|
||||
rb_iv_set(self, "@args", args);
|
||||
|
@ -35,6 +35,25 @@ module Fiddle
|
||||
end
|
||||
end
|
||||
|
||||
def test_argument_type_conversion
|
||||
type = Struct.new(:int, :call_count) do
|
||||
def initialize(int)
|
||||
super(int, 0)
|
||||
end
|
||||
def to_int
|
||||
raise "exhausted" if (self.call_count += 1) > 1
|
||||
self.int
|
||||
end
|
||||
end
|
||||
type_arg = type.new(TYPE_DOUBLE)
|
||||
type_result = type.new(TYPE_DOUBLE)
|
||||
assert_nothing_raised(RuntimeError) do
|
||||
Function.new(@libm['sin'], [type_arg], type_result)
|
||||
end
|
||||
assert_equal(1, type_arg.call_count)
|
||||
assert_equal(1, type_result.call_count)
|
||||
end
|
||||
|
||||
def test_call
|
||||
func = Function.new(@libm['sin'], [TYPE_DOUBLE], TYPE_DOUBLE)
|
||||
assert_in_delta 1.0, func.call(90 * Math::PI / 180), 0.0001
|
||||
|
Loading…
x
Reference in New Issue
Block a user