ffi 1.0.9-x86-mingw32 → 1.0.12.pre-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/Rakefile +16 -16
- data/ext/ffi_c/AbstractMemory.c +376 -14
- data/ext/ffi_c/AbstractMemory.h +8 -0
- data/ext/ffi_c/ArrayType.c +28 -0
- data/ext/ffi_c/Buffer.c +109 -25
- data/ext/ffi_c/Call.c +16 -5
- data/ext/ffi_c/ClosurePool.c +21 -8
- data/ext/ffi_c/DataConverter.c +29 -0
- data/ext/ffi_c/DynamicLibrary.c +71 -2
- data/ext/ffi_c/Function.c +122 -11
- data/ext/ffi_c/Function.h +6 -0
- data/ext/ffi_c/FunctionInfo.c +21 -1
- data/ext/ffi_c/LastError.c +24 -0
- data/ext/ffi_c/MappedType.c +22 -0
- data/ext/ffi_c/MemoryPointer.c +19 -1
- data/ext/ffi_c/MemoryPointer.h +6 -0
- data/ext/ffi_c/MethodHandle.c +26 -11
- data/ext/ffi_c/Platform.c +17 -3
- data/ext/ffi_c/Pointer.c +106 -0
- data/ext/ffi_c/Pointer.h +6 -0
- data/ext/ffi_c/Struct.c +10 -4
- data/ext/ffi_c/Struct.h +2 -1
- data/ext/ffi_c/StructByReference.c +8 -0
- data/ext/ffi_c/StructByValue.c +8 -0
- data/ext/ffi_c/StructLayout.c +8 -2
- data/ext/ffi_c/Thread.c +131 -1
- data/ext/ffi_c/Thread.h +6 -0
- data/ext/ffi_c/Type.c +111 -17
- data/ext/ffi_c/Types.c +9 -2
- data/ext/ffi_c/Types.h +4 -0
- data/ext/ffi_c/Variadic.c +13 -4
- data/ext/ffi_c/compat.h +8 -0
- data/ext/ffi_c/endian.h +10 -1
- data/ext/ffi_c/extconf.rb +51 -35
- data/ext/ffi_c/ffi.c +5 -0
- data/ext/ffi_c/libffi.darwin.mk +15 -15
- data/ext/ffi_c/libffi.gnu.mk +3 -3
- data/ext/ffi_c/libffi.mk +4 -4
- data/ext/ffi_c/libffi.vc.mk +26 -0
- data/ext/ffi_c/libffi.vc64.mk +26 -0
- data/ext/ffi_c/libffi/ChangeLog +541 -0
- data/ext/ffi_c/libffi/ChangeLog.libffi +13 -87
- data/ext/ffi_c/libffi/LICENSE +3 -3
- data/ext/ffi_c/libffi/Makefile.am +41 -32
- data/ext/ffi_c/libffi/Makefile.in +95 -66
- data/ext/ffi_c/libffi/Makefile.vc +141 -0
- data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
- data/ext/ffi_c/libffi/README +40 -4
- data/ext/ffi_c/libffi/aclocal.m4 +729 -7854
- data/ext/ffi_c/libffi/build-ios.sh +67 -0
- data/ext/ffi_c/libffi/compile +11 -10
- data/ext/ffi_c/libffi/config.guess +4 -1
- data/ext/ffi_c/libffi/config.sub +6 -3
- data/ext/ffi_c/libffi/configure +6264 -6354
- data/ext/ffi_c/libffi/configure.ac +155 -63
- data/ext/ffi_c/libffi/depcomp +81 -35
- data/ext/ffi_c/libffi/doc/libffi.info +78 -18
- data/ext/ffi_c/libffi/doc/libffi.texi +64 -5
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +18 -0
- data/ext/ffi_c/libffi/fficonfig.hw +57 -0
- data/ext/ffi_c/libffi/include/Makefile.in +21 -3
- data/ext/ffi_c/libffi/include/ffi.h.in +42 -14
- data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
- data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
- data/ext/ffi_c/libffi/include/ffi_common.h +9 -5
- data/ext/ffi_c/libffi/install-sh +364 -167
- data/ext/ffi_c/libffi/ltmain.sh +2599 -1369
- data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
- data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
- data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
- data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
- data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
- data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
- data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
- data/ext/ffi_c/libffi/m4/libtool.m4 +1239 -768
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +7 -6
- data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +9 -3
- data/ext/ffi_c/libffi/man/Makefile.in +21 -3
- data/ext/ffi_c/libffi/mdate-sh +0 -0
- data/ext/ffi_c/libffi/missing +60 -44
- data/ext/ffi_c/libffi/msvcc.sh +197 -0
- data/ext/ffi_c/libffi/src/alpha/osf.S +39 -18
- data/ext/ffi_c/libffi/src/arm/ffi.c +443 -24
- data/ext/ffi_c/libffi/src/arm/ffitarget.h +17 -1
- data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
- data/ext/ffi_c/libffi/src/arm/sysv.S +206 -15
- data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
- data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/closures.c +17 -35
- data/ext/ffi_c/libffi/src/cris/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/cris/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/dlmalloc.c +66 -4
- data/ext/ffi_c/libffi/src/frv/ffitarget.h +2 -6
- data/ext/ffi_c/libffi/src/ia64/ffi.c +7 -5
- data/ext/ffi_c/libffi/src/ia64/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/java_raw_api.c +1 -1
- data/ext/ffi_c/libffi/src/m32r/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/m68k/ffi.c +10 -0
- data/ext/ffi_c/libffi/src/m68k/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/m68k/sysv.S +36 -0
- data/ext/ffi_c/libffi/src/mips/ffi.c +12 -5
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +18 -11
- data/ext/ffi_c/libffi/src/mips/n32.S +4 -4
- data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
- data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
- data/ext/ffi_c/libffi/src/pa/ffi.c +7 -4
- data/ext/ffi_c/libffi/src/pa/ffitarget.h +6 -5
- data/ext/ffi_c/libffi/src/powerpc/aix.S +5 -1
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +2 -0
- data/ext/ffi_c/libffi/src/powerpc/asm.h +1 -1
- data/ext/ffi_c/libffi/src/powerpc/darwin.S +215 -77
- data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +358 -100
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +11 -5
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +603 -172
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +17 -4
- data/ext/ffi_c/libffi/src/prep_cif.c +16 -13
- data/ext/ffi_c/libffi/src/s390/ffitarget.h +4 -2
- data/ext/ffi_c/libffi/src/sh/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/sh64/ffitarget.h +2 -2
- data/ext/ffi_c/libffi/src/sparc/ffi.c +55 -11
- data/ext/ffi_c/libffi/src/sparc/ffitarget.h +5 -3
- data/ext/ffi_c/libffi/src/x86/ffi.c +54 -92
- data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -14
- data/ext/ffi_c/libffi/src/x86/sysv.S +40 -26
- data/ext/ffi_c/libffi/src/x86/unix64.S +4 -0
- data/ext/ffi_c/libffi/src/x86/win32.S +379 -191
- data/ext/ffi_c/libffi/src/x86/win64.S +15 -7
- data/ext/ffi_c/libffi/testsuite/Makefile.am +1 -1
- data/ext/ffi_c/libffi/testsuite/Makefile.in +22 -4
- data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +1 -5
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +2 -2
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +3 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +2 -3
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +36 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +17 -17
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +1 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +1 -3
- data/ext/ffi_c/win32/stdint.h +199 -0
- data/gen/Rakefile +18 -2
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/ffi.rb +13 -9
- data/lib/ffi/autopointer.rb +88 -26
- data/lib/ffi/enum.rb +42 -0
- data/lib/ffi/errno.rb +6 -1
- data/lib/ffi/ffi.rb +1 -0
- data/lib/ffi/io.rb +13 -2
- data/lib/ffi/library.rb +219 -24
- data/lib/ffi/memorypointer.rb +1 -33
- data/lib/ffi/platform.rb +21 -7
- data/lib/ffi/platform/arm-linux/types.conf +102 -0
- data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
- data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
- data/lib/ffi/platform/i486-gnu/types.conf +107 -0
- data/lib/ffi/platform/ia64-linux/types.conf +102 -0
- data/lib/ffi/platform/mips-linux/types.conf +102 -0
- data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
- data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
- data/lib/ffi/platform/s390-linux/types.conf +102 -0
- data/lib/ffi/platform/s390x-linux/types.conf +102 -0
- data/lib/ffi/platform/sparc-linux/types.conf +102 -0
- data/lib/ffi/platform/x86_64-freebsd/types.conf +126 -0
- data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
- data/lib/ffi/pointer.rb +44 -0
- data/lib/ffi/struct.rb +2 -6
- data/lib/ffi/struct_layout_builder.rb +2 -1
- data/lib/ffi/tools/const_generator.rb +78 -26
- data/lib/ffi/tools/types_generator.rb +8 -1
- data/lib/ffi/types.rb +21 -1
- data/spec/ffi/async_callback_spec.rb +2 -2
- data/spec/ffi/bool_spec.rb +6 -6
- data/spec/ffi/buffer_spec.rb +23 -23
- data/spec/ffi/callback_spec.rb +101 -102
- data/spec/ffi/custom_type_spec.rb +20 -24
- data/spec/ffi/dup_spec.rb +7 -7
- data/spec/ffi/enum_spec.rb +127 -127
- data/spec/ffi/errno_spec.rb +2 -2
- data/spec/ffi/ffi_spec.rb +3 -3
- data/spec/ffi/function_spec.rb +10 -10
- data/spec/ffi/library_spec.rb +30 -12
- data/spec/ffi/managed_struct_spec.rb +4 -4
- data/spec/ffi/number_spec.rb +40 -40
- data/spec/ffi/pointer_spec.rb +21 -24
- data/spec/ffi/rbx/memory_pointer_spec.rb +17 -15
- data/spec/ffi/rbx/struct_spec.rb +2 -2
- data/spec/ffi/spec_helper.rb +1 -1
- data/spec/ffi/string_spec.rb +9 -9
- data/spec/ffi/strptr_spec.rb +3 -3
- data/spec/ffi/struct_callback_spec.rb +7 -7
- data/spec/ffi/struct_initialize_spec.rb +2 -2
- data/spec/ffi/struct_packed_spec.rb +6 -6
- data/spec/ffi/struct_spec.rb +94 -84
- data/spec/ffi/typedef_spec.rb +15 -4
- data/spec/ffi/union_spec.rb +3 -3
- data/spec/ffi/variadic_spec.rb +17 -14
- data/tasks/extension.rake +0 -1
- data/tasks/gem.rake +0 -1
- data/tasks/rdoc.rake +1 -1
- data/tasks/yard.rake +11 -0
- metadata +50 -11
- data/lib/1.9/ffi_c.so +0 -0
@@ -17,37 +17,33 @@
|
|
17
17
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
18
18
|
|
19
19
|
describe "functions with custom types" do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
ToNativeMap= { :a => 1, :b => 2, :c => 3 }
|
25
|
-
FromNativeMap = { 1 => :a, 2 => :b, 3 => :c }
|
20
|
+
class Custom_enum
|
21
|
+
extend FFI::DataConverter
|
22
|
+
ToNativeMap= { :a => 1, :b => 2, :c => 3 }
|
23
|
+
FromNativeMap = { 1 => :a, 2 => :b, 3 => :c }
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def self.to_native(val, ctx)
|
33
|
-
@to_native_called = true
|
34
|
-
ToNativeMap[val]
|
35
|
-
end
|
25
|
+
def self.native_type
|
26
|
+
@native_type_called = true
|
27
|
+
FFI::Type::INT32
|
28
|
+
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
def self.native_type_called?; @native_type_called; end
|
42
|
-
def self.from_native_called?; @from_native_called; end
|
43
|
-
def self.to_native_called?; @to_native_called; end
|
30
|
+
def self.to_native(val, ctx)
|
31
|
+
@to_native_called = true
|
32
|
+
ToNativeMap[val]
|
44
33
|
end
|
45
34
|
|
35
|
+
def self.from_native(val, ctx)
|
36
|
+
@from_native_called = true
|
37
|
+
FromNativeMap[val]
|
38
|
+
end
|
39
|
+
def self.native_type_called?; @native_type_called; end
|
40
|
+
def self.from_native_called?; @from_native_called; end
|
41
|
+
def self.to_native_called?; @to_native_called; end
|
46
42
|
end
|
47
43
|
|
48
44
|
it "can attach with custom return type" do
|
49
45
|
lambda do
|
50
|
-
|
46
|
+
Module.new do
|
51
47
|
extend FFI::Library
|
52
48
|
ffi_lib TestLibrary::PATH
|
53
49
|
attach_function :ret_s32, [ :int ], Custom_enum
|
@@ -86,4 +82,4 @@ describe "functions with custom types" do
|
|
86
82
|
m.ret_s32(:a)
|
87
83
|
Custom_enum.to_native_called?.should be_true
|
88
84
|
end
|
89
|
-
end
|
85
|
+
end
|
data/spec/ffi/dup_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe "Pointer#dup" do
|
|
24
24
|
p2 = p1.dup
|
25
25
|
p1.put_string(0, "deadbeef")
|
26
26
|
|
27
|
-
p2.get_string(0).should
|
27
|
+
p2.get_string(0).should eq "test123"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "sliced pointer can be cloned" do
|
@@ -33,8 +33,8 @@ describe "Pointer#dup" do
|
|
33
33
|
p2 = p1[1].dup
|
34
34
|
|
35
35
|
# first char will be excised
|
36
|
-
p2.get_string(0).should
|
37
|
-
p1.get_string(0).should
|
36
|
+
p2.get_string(0).should eq "est123"
|
37
|
+
p1.get_string(0).should eq "test123"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "sliced pointer when cloned is independent" do
|
@@ -44,7 +44,7 @@ describe "Pointer#dup" do
|
|
44
44
|
|
45
45
|
p1.put_string(0, "deadbeef")
|
46
46
|
# first char will be excised
|
47
|
-
p2.get_string(0).should
|
47
|
+
p2.get_string(0).should eq "est123"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -58,8 +58,8 @@ describe "Struct#dup" do
|
|
58
58
|
s1[:i] = 0x12345
|
59
59
|
s2 = s1.dup
|
60
60
|
s1[:i] = 0x98765
|
61
|
-
s2[:i].should
|
62
|
-
s1[:i].should
|
61
|
+
s2[:i].should eq 0x12345
|
62
|
+
s1[:i].should eq 0x98765
|
63
63
|
end
|
64
64
|
|
65
|
-
end
|
65
|
+
end
|
data/spec/ffi/enum_spec.rb
CHANGED
@@ -49,179 +49,179 @@ end
|
|
49
49
|
|
50
50
|
describe "A library with no enum defined" do
|
51
51
|
it "returns nil when asked for an enum" do
|
52
|
-
TestEnum0.enum_type(:foo).should
|
52
|
+
TestEnum0.enum_type(:foo).should eq nil
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "An untagged enum" do
|
57
57
|
it "constants can be used as function parameters and return value" do
|
58
|
-
TestEnum1.test_untagged_enum(:c1).should
|
59
|
-
TestEnum1.test_untagged_enum(:c2).should
|
60
|
-
TestEnum1.test_untagged_enum(:c3).should
|
61
|
-
TestEnum1.test_untagged_enum(:c4).should
|
62
|
-
TestEnum1.test_untagged_enum(:c5).should
|
63
|
-
TestEnum1.test_untagged_enum(:c6).should
|
64
|
-
TestEnum1.test_untagged_enum(:c7).should
|
65
|
-
TestEnum1.test_untagged_enum(:c8).should
|
66
|
-
TestEnum1.test_untagged_enum(:c9).should
|
67
|
-
TestEnum1.test_untagged_enum(:c10).should
|
68
|
-
TestEnum1.test_untagged_enum(:c11).should
|
69
|
-
TestEnum1.test_untagged_enum(:c12).should
|
70
|
-
TestEnum1.test_untagged_enum(:c13).should
|
71
|
-
TestEnum1.test_untagged_enum(:c14).should
|
72
|
-
TestEnum1.test_untagged_enum(:c15).should
|
73
|
-
TestEnum1.test_untagged_enum(:c16).should
|
58
|
+
TestEnum1.test_untagged_enum(:c1).should eq 0
|
59
|
+
TestEnum1.test_untagged_enum(:c2).should eq 1
|
60
|
+
TestEnum1.test_untagged_enum(:c3).should eq 2
|
61
|
+
TestEnum1.test_untagged_enum(:c4).should eq 3
|
62
|
+
TestEnum1.test_untagged_enum(:c5).should eq 42
|
63
|
+
TestEnum1.test_untagged_enum(:c6).should eq 43
|
64
|
+
TestEnum1.test_untagged_enum(:c7).should eq 44
|
65
|
+
TestEnum1.test_untagged_enum(:c8).should eq 45
|
66
|
+
TestEnum1.test_untagged_enum(:c9).should eq 42
|
67
|
+
TestEnum1.test_untagged_enum(:c10).should eq 43
|
68
|
+
TestEnum1.test_untagged_enum(:c11).should eq 4242
|
69
|
+
TestEnum1.test_untagged_enum(:c12).should eq 4243
|
70
|
+
TestEnum1.test_untagged_enum(:c13).should eq 42
|
71
|
+
TestEnum1.test_untagged_enum(:c14).should eq 4242
|
72
|
+
TestEnum1.test_untagged_enum(:c15).should eq 424242
|
73
|
+
TestEnum1.test_untagged_enum(:c16).should eq 42424242
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe "A tagged typedef enum" do
|
78
78
|
it "is accessible through its tag" do
|
79
|
-
TestEnum3.enum_type(:enum_type1).should_not
|
80
|
-
TestEnum3.enum_type(:enum_type2).should_not
|
81
|
-
TestEnum3.enum_type(:enum_type3).should_not
|
82
|
-
TestEnum3.enum_type(:enum_type4).should_not
|
79
|
+
TestEnum3.enum_type(:enum_type1).should_not eq nil
|
80
|
+
TestEnum3.enum_type(:enum_type2).should_not eq nil
|
81
|
+
TestEnum3.enum_type(:enum_type3).should_not eq nil
|
82
|
+
TestEnum3.enum_type(:enum_type4).should_not eq nil
|
83
83
|
end
|
84
84
|
it "contains enum constants" do
|
85
|
-
TestEnum3.enum_type(:enum_type1).symbols.length.should
|
86
|
-
TestEnum3.enum_type(:enum_type2).symbols.length.should
|
87
|
-
TestEnum3.enum_type(:enum_type3).symbols.length.should
|
88
|
-
TestEnum3.enum_type(:enum_type4).symbols.length.should
|
85
|
+
TestEnum3.enum_type(:enum_type1).symbols.length.should eq 4
|
86
|
+
TestEnum3.enum_type(:enum_type2).symbols.length.should eq 4
|
87
|
+
TestEnum3.enum_type(:enum_type3).symbols.length.should eq 4
|
88
|
+
TestEnum3.enum_type(:enum_type4).symbols.length.should eq 4
|
89
89
|
end
|
90
90
|
it "constants can be used as function parameters and return value" do
|
91
|
-
TestEnum3.test_tagged_typedef_enum1(:c1).should
|
92
|
-
TestEnum3.test_tagged_typedef_enum1(:c2).should
|
93
|
-
TestEnum3.test_tagged_typedef_enum1(:c3).should
|
94
|
-
TestEnum3.test_tagged_typedef_enum1(:c4).should
|
95
|
-
TestEnum3.test_tagged_typedef_enum2(:c5).should
|
96
|
-
TestEnum3.test_tagged_typedef_enum2(:c6).should
|
97
|
-
TestEnum3.test_tagged_typedef_enum2(:c7).should
|
98
|
-
TestEnum3.test_tagged_typedef_enum2(:c8).should
|
99
|
-
TestEnum3.test_tagged_typedef_enum3(:c9).should
|
100
|
-
TestEnum3.test_tagged_typedef_enum3(:c10).should
|
101
|
-
TestEnum3.test_tagged_typedef_enum3(:c11).should
|
102
|
-
TestEnum3.test_tagged_typedef_enum3(:c12).should
|
103
|
-
TestEnum3.test_tagged_typedef_enum4(:c13).should
|
104
|
-
TestEnum3.test_tagged_typedef_enum4(:c14).should
|
105
|
-
TestEnum3.test_tagged_typedef_enum4(:c15).should
|
106
|
-
TestEnum3.test_tagged_typedef_enum4(:c16).should
|
91
|
+
TestEnum3.test_tagged_typedef_enum1(:c1).should eq :c1
|
92
|
+
TestEnum3.test_tagged_typedef_enum1(:c2).should eq :c2
|
93
|
+
TestEnum3.test_tagged_typedef_enum1(:c3).should eq :c3
|
94
|
+
TestEnum3.test_tagged_typedef_enum1(:c4).should eq :c4
|
95
|
+
TestEnum3.test_tagged_typedef_enum2(:c5).should eq :c5
|
96
|
+
TestEnum3.test_tagged_typedef_enum2(:c6).should eq :c6
|
97
|
+
TestEnum3.test_tagged_typedef_enum2(:c7).should eq :c7
|
98
|
+
TestEnum3.test_tagged_typedef_enum2(:c8).should eq :c8
|
99
|
+
TestEnum3.test_tagged_typedef_enum3(:c9).should eq :c9
|
100
|
+
TestEnum3.test_tagged_typedef_enum3(:c10).should eq :c10
|
101
|
+
TestEnum3.test_tagged_typedef_enum3(:c11).should eq :c11
|
102
|
+
TestEnum3.test_tagged_typedef_enum3(:c12).should eq :c12
|
103
|
+
TestEnum3.test_tagged_typedef_enum4(:c13).should eq :c13
|
104
|
+
TestEnum3.test_tagged_typedef_enum4(:c14).should eq :c14
|
105
|
+
TestEnum3.test_tagged_typedef_enum4(:c15).should eq :c15
|
106
|
+
TestEnum3.test_tagged_typedef_enum4(:c16).should eq :c16
|
107
107
|
end
|
108
108
|
|
109
109
|
it "integers can be used instead of constants" do
|
110
|
-
TestEnum3.test_tagged_typedef_enum1(0).should
|
111
|
-
TestEnum3.test_tagged_typedef_enum1(1).should
|
112
|
-
TestEnum3.test_tagged_typedef_enum1(2).should
|
113
|
-
TestEnum3.test_tagged_typedef_enum1(3).should
|
114
|
-
TestEnum3.test_tagged_typedef_enum2(42).should
|
115
|
-
TestEnum3.test_tagged_typedef_enum2(43).should
|
116
|
-
TestEnum3.test_tagged_typedef_enum2(44).should
|
117
|
-
TestEnum3.test_tagged_typedef_enum2(45).should
|
118
|
-
TestEnum3.test_tagged_typedef_enum3(42).should
|
119
|
-
TestEnum3.test_tagged_typedef_enum3(43).should
|
120
|
-
TestEnum3.test_tagged_typedef_enum3(4242).should
|
121
|
-
TestEnum3.test_tagged_typedef_enum3(4243).should
|
122
|
-
TestEnum3.test_tagged_typedef_enum4(42).should
|
123
|
-
TestEnum3.test_tagged_typedef_enum4(4242).should
|
124
|
-
TestEnum3.test_tagged_typedef_enum4(424242).should
|
125
|
-
TestEnum3.test_tagged_typedef_enum4(42424242).should
|
110
|
+
TestEnum3.test_tagged_typedef_enum1(0).should eq :c1
|
111
|
+
TestEnum3.test_tagged_typedef_enum1(1).should eq :c2
|
112
|
+
TestEnum3.test_tagged_typedef_enum1(2).should eq :c3
|
113
|
+
TestEnum3.test_tagged_typedef_enum1(3).should eq :c4
|
114
|
+
TestEnum3.test_tagged_typedef_enum2(42).should eq :c5
|
115
|
+
TestEnum3.test_tagged_typedef_enum2(43).should eq :c6
|
116
|
+
TestEnum3.test_tagged_typedef_enum2(44).should eq :c7
|
117
|
+
TestEnum3.test_tagged_typedef_enum2(45).should eq :c8
|
118
|
+
TestEnum3.test_tagged_typedef_enum3(42).should eq :c9
|
119
|
+
TestEnum3.test_tagged_typedef_enum3(43).should eq :c10
|
120
|
+
TestEnum3.test_tagged_typedef_enum3(4242).should eq :c11
|
121
|
+
TestEnum3.test_tagged_typedef_enum3(4243).should eq :c12
|
122
|
+
TestEnum3.test_tagged_typedef_enum4(42).should eq :c13
|
123
|
+
TestEnum3.test_tagged_typedef_enum4(4242).should eq :c14
|
124
|
+
TestEnum3.test_tagged_typedef_enum4(424242).should eq :c15
|
125
|
+
TestEnum3.test_tagged_typedef_enum4(42424242).should eq :c16
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
describe "All enums" do
|
130
130
|
it "have autonumbered constants when defined with names only" do
|
131
|
-
TestEnum1.enum_value(:c1).should
|
132
|
-
TestEnum1.enum_value(:c2).should
|
133
|
-
TestEnum1.enum_value(:c3).should
|
134
|
-
TestEnum1.enum_value(:c4).should
|
135
|
-
|
136
|
-
TestEnum3.enum_value(:c1).should
|
137
|
-
TestEnum3.enum_value(:c2).should
|
138
|
-
TestEnum3.enum_value(:c3).should
|
139
|
-
TestEnum3.enum_value(:c4).should
|
131
|
+
TestEnum1.enum_value(:c1).should eq 0
|
132
|
+
TestEnum1.enum_value(:c2).should eq 1
|
133
|
+
TestEnum1.enum_value(:c3).should eq 2
|
134
|
+
TestEnum1.enum_value(:c4).should eq 3
|
135
|
+
|
136
|
+
TestEnum3.enum_value(:c1).should eq 0
|
137
|
+
TestEnum3.enum_value(:c2).should eq 1
|
138
|
+
TestEnum3.enum_value(:c3).should eq 2
|
139
|
+
TestEnum3.enum_value(:c4).should eq 3
|
140
140
|
end
|
141
141
|
it "can have an explicit first constant and autonumbered subsequent constants" do
|
142
|
-
TestEnum1.enum_value(:c5).should
|
143
|
-
TestEnum1.enum_value(:c6).should
|
144
|
-
TestEnum1.enum_value(:c7).should
|
145
|
-
TestEnum1.enum_value(:c8).should
|
146
|
-
|
147
|
-
TestEnum3.enum_value(:c5).should
|
148
|
-
TestEnum3.enum_value(:c6).should
|
149
|
-
TestEnum3.enum_value(:c7).should
|
150
|
-
TestEnum3.enum_value(:c8).should
|
142
|
+
TestEnum1.enum_value(:c5).should eq 42
|
143
|
+
TestEnum1.enum_value(:c6).should eq 43
|
144
|
+
TestEnum1.enum_value(:c7).should eq 44
|
145
|
+
TestEnum1.enum_value(:c8).should eq 45
|
146
|
+
|
147
|
+
TestEnum3.enum_value(:c5).should eq 42
|
148
|
+
TestEnum3.enum_value(:c6).should eq 43
|
149
|
+
TestEnum3.enum_value(:c7).should eq 44
|
150
|
+
TestEnum3.enum_value(:c8).should eq 45
|
151
151
|
end
|
152
152
|
it "can have a mix of explicit and autonumbered constants" do
|
153
|
-
TestEnum1.enum_value(:c9).should
|
154
|
-
TestEnum1.enum_value(:c10).should
|
155
|
-
TestEnum1.enum_value(:c11).should
|
156
|
-
TestEnum1.enum_value(:c12).should
|
157
|
-
|
158
|
-
TestEnum3.enum_value(:c9).should
|
159
|
-
TestEnum3.enum_value(:c10).should
|
160
|
-
TestEnum3.enum_value(:c11).should
|
161
|
-
TestEnum3.enum_value(:c12).should
|
153
|
+
TestEnum1.enum_value(:c9).should eq 42
|
154
|
+
TestEnum1.enum_value(:c10).should eq 43
|
155
|
+
TestEnum1.enum_value(:c11).should eq 4242
|
156
|
+
TestEnum1.enum_value(:c12).should eq 4243
|
157
|
+
|
158
|
+
TestEnum3.enum_value(:c9).should eq 42
|
159
|
+
TestEnum3.enum_value(:c10).should eq 43
|
160
|
+
TestEnum3.enum_value(:c11).should eq 4242
|
161
|
+
TestEnum3.enum_value(:c12).should eq 4243
|
162
162
|
end
|
163
163
|
it "can have all its constants explicitely valued" do
|
164
|
-
TestEnum1.enum_value(:c13).should
|
165
|
-
TestEnum1.enum_value(:c14).should
|
166
|
-
TestEnum1.enum_value(:c15).should
|
167
|
-
TestEnum1.enum_value(:c16).should
|
164
|
+
TestEnum1.enum_value(:c13).should eq 42
|
165
|
+
TestEnum1.enum_value(:c14).should eq 4242
|
166
|
+
TestEnum1.enum_value(:c15).should eq 424242
|
167
|
+
TestEnum1.enum_value(:c16).should eq 42424242
|
168
168
|
|
169
|
-
TestEnum3.enum_value(:c13).should
|
170
|
-
TestEnum3.enum_value(:c14).should
|
171
|
-
TestEnum3.enum_value(:c15).should
|
172
|
-
TestEnum3.enum_value(:c16).should
|
169
|
+
TestEnum3.enum_value(:c13).should eq 42
|
170
|
+
TestEnum3.enum_value(:c14).should eq 4242
|
171
|
+
TestEnum3.enum_value(:c15).should eq 424242
|
172
|
+
TestEnum3.enum_value(:c16).should eq 42424242
|
173
173
|
end
|
174
174
|
it "return the constant corresponding to a specific value" do
|
175
175
|
enum = TestEnum3.enum_type(:enum_type1)
|
176
|
-
enum[0].should
|
177
|
-
enum[1].should
|
178
|
-
enum[2].should
|
179
|
-
enum[3].should
|
176
|
+
enum[0].should eq :c1
|
177
|
+
enum[1].should eq :c2
|
178
|
+
enum[2].should eq :c3
|
179
|
+
enum[3].should eq :c4
|
180
180
|
|
181
181
|
enum = TestEnum3.enum_type(:enum_type2)
|
182
|
-
enum[42].should
|
183
|
-
enum[43].should
|
184
|
-
enum[44].should
|
185
|
-
enum[45].should
|
182
|
+
enum[42].should eq :c5
|
183
|
+
enum[43].should eq :c6
|
184
|
+
enum[44].should eq :c7
|
185
|
+
enum[45].should eq :c8
|
186
186
|
|
187
187
|
enum = TestEnum3.enum_type(:enum_type3)
|
188
|
-
enum[42].should
|
189
|
-
enum[43].should
|
190
|
-
enum[4242].should
|
191
|
-
enum[4243].should
|
188
|
+
enum[42].should eq :c9
|
189
|
+
enum[43].should eq :c10
|
190
|
+
enum[4242].should eq :c11
|
191
|
+
enum[4243].should eq :c12
|
192
192
|
|
193
193
|
enum = TestEnum3.enum_type(:enum_type4)
|
194
|
-
enum[42].should
|
195
|
-
enum[4242].should
|
196
|
-
enum[424242].should
|
197
|
-
enum[42424242].should
|
194
|
+
enum[42].should eq :c13
|
195
|
+
enum[4242].should eq :c14
|
196
|
+
enum[424242].should eq :c15
|
197
|
+
enum[42424242].should eq :c16
|
198
198
|
end
|
199
199
|
it "return nil for values that don't have a symbol" do
|
200
200
|
enum = TestEnum3.enum_type(:enum_type1)
|
201
|
-
enum[-1].should
|
202
|
-
enum[4].should
|
201
|
+
enum[-1].should eq nil
|
202
|
+
enum[4].should eq nil
|
203
203
|
|
204
204
|
enum = TestEnum3.enum_type(:enum_type2)
|
205
|
-
enum[0].should
|
206
|
-
enum[41].should
|
207
|
-
enum[46].should
|
205
|
+
enum[0].should eq nil
|
206
|
+
enum[41].should eq nil
|
207
|
+
enum[46].should eq nil
|
208
208
|
|
209
209
|
enum = TestEnum3.enum_type(:enum_type3)
|
210
|
-
enum[0].should
|
211
|
-
enum[41].should
|
212
|
-
enum[44].should
|
213
|
-
enum[4241].should
|
214
|
-
enum[4244].should
|
210
|
+
enum[0].should eq nil
|
211
|
+
enum[41].should eq nil
|
212
|
+
enum[44].should eq nil
|
213
|
+
enum[4241].should eq nil
|
214
|
+
enum[4244].should eq nil
|
215
215
|
|
216
216
|
enum = TestEnum3.enum_type(:enum_type4)
|
217
|
-
enum[0].should
|
218
|
-
enum[41].should
|
219
|
-
enum[43].should
|
220
|
-
enum[4241].should
|
221
|
-
enum[4243].should
|
222
|
-
enum[424241].should
|
223
|
-
enum[424243].should
|
224
|
-
enum[42424241].should
|
225
|
-
enum[42424243].should
|
217
|
+
enum[0].should eq nil
|
218
|
+
enum[41].should eq nil
|
219
|
+
enum[43].should eq nil
|
220
|
+
enum[4241].should eq nil
|
221
|
+
enum[4243].should eq nil
|
222
|
+
enum[424241].should eq nil
|
223
|
+
enum[424243].should eq nil
|
224
|
+
enum[42424241].should eq nil
|
225
|
+
enum[42424243].should eq nil
|
226
226
|
end
|
227
227
|
end
|
data/spec/ffi/errno_spec.rb
CHANGED
data/spec/ffi/ffi_spec.rb
CHANGED
@@ -24,15 +24,15 @@ describe "FFI" do
|
|
24
24
|
let(:suffix) { FFI::Platform::LIBSUFFIX }
|
25
25
|
|
26
26
|
it "should add platform library extension if not present" do
|
27
|
-
FFI.map_library_name("#{prefix}dummy").should
|
27
|
+
FFI.map_library_name("#{prefix}dummy").should eq "#{prefix}dummy.#{suffix}"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should add platform library extension even if lib suffix is present in name" do
|
31
|
-
FFI.map_library_name("#{prefix}dummy_with_#{suffix}").should
|
31
|
+
FFI.map_library_name("#{prefix}dummy_with_#{suffix}").should eq "#{prefix}dummy_with_#{suffix}.#{suffix}"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return Platform::LIBC when called with 'c'" do
|
35
|
-
FFI.map_library_name('c').should
|
35
|
+
FFI.map_library_name('c').should eq FFI::Library::LIBC
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
data/spec/ffi/function_spec.rb
CHANGED
@@ -17,12 +17,12 @@
|
|
17
17
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
18
18
|
|
19
19
|
describe FFI::Function do
|
20
|
+
module LibTest
|
21
|
+
extend FFI::Library
|
22
|
+
ffi_lib TestLibrary::PATH
|
23
|
+
attach_function :testFunctionAdd, [:int, :int, :pointer], :int
|
24
|
+
end
|
20
25
|
before do
|
21
|
-
module LibTest
|
22
|
-
extend FFI::Library
|
23
|
-
ffi_lib TestLibrary::PATH
|
24
|
-
attach_function :testFunctionAdd, [:int, :int, :pointer], :int
|
25
|
-
end
|
26
26
|
@libtest = FFI::DynamicLibrary.open(TestLibrary::PATH,
|
27
27
|
FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
|
28
28
|
end
|
@@ -37,20 +37,20 @@ describe FFI::Function do
|
|
37
37
|
end
|
38
38
|
it 'can be used as callback from C passing to it a block' do
|
39
39
|
function_add = FFI::Function.new(:int, [:int, :int]) { |a, b| a + b }
|
40
|
-
LibTest.testFunctionAdd(10, 10, function_add).should
|
40
|
+
LibTest.testFunctionAdd(10, 10, function_add).should eq 20
|
41
41
|
end
|
42
42
|
it 'can be used as callback from C passing to it a Proc object' do
|
43
43
|
function_add = FFI::Function.new(:int, [:int, :int], Proc.new { |a, b| a + b })
|
44
|
-
LibTest.testFunctionAdd(10, 10, function_add).should
|
44
|
+
LibTest.testFunctionAdd(10, 10, function_add).should eq 20
|
45
45
|
end
|
46
46
|
it 'can be used to wrap an existing function pointer' do
|
47
|
-
FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')).call(10, 10).should
|
47
|
+
FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd')).call(10, 10).should eq 20
|
48
48
|
end
|
49
49
|
it 'can be attached to a module' do
|
50
50
|
module Foo; end
|
51
51
|
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
52
52
|
fp.attach(Foo, 'add')
|
53
|
-
Foo.add(10, 10).should
|
53
|
+
Foo.add(10, 10).should eq 20
|
54
54
|
end
|
55
55
|
it 'can be used to extend an object' do
|
56
56
|
fp = FFI::Function.new(:int, [:int, :int], @libtest.find_function('testAdd'))
|
@@ -61,7 +61,7 @@ describe FFI::Function do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
fp.attach(foo.singleton_class, 'add')
|
64
|
-
foo.add(10, 10).should
|
64
|
+
foo.add(10, 10).should eq 20
|
65
65
|
end
|
66
66
|
it 'can wrap a blocking function' do
|
67
67
|
fp = FFI::Function.new(:void, [ :int ], @libtest.find_function('testBlocking'), :blocking => true)
|