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
data/spec/ffi/library_spec.rb
CHANGED
@@ -16,8 +16,26 @@
|
|
16
16
|
|
17
17
|
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
18
18
|
describe "Library" do
|
19
|
+
describe "#ffi_convention" do
|
20
|
+
it "defaults to :default" do
|
21
|
+
m = Module.new do
|
22
|
+
extend FFI::Library
|
23
|
+
end
|
24
|
+
m.ffi_convention.should eq :default
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be settable" do
|
28
|
+
m = Module.new do
|
29
|
+
extend FFI::Library
|
30
|
+
end
|
31
|
+
|
32
|
+
m.ffi_convention.should eq :default
|
33
|
+
m.ffi_convention :stdcall
|
34
|
+
m.ffi_convention.should eq :stdcall
|
35
|
+
end
|
36
|
+
end
|
19
37
|
|
20
|
-
unless
|
38
|
+
unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
21
39
|
it "attach_function with no library specified" do
|
22
40
|
lambda {
|
23
41
|
Module.new do |m|
|
@@ -32,7 +50,7 @@ describe "Library" do
|
|
32
50
|
m.extend FFI::Library
|
33
51
|
ffi_lib FFI::Library::CURRENT_PROCESS
|
34
52
|
attach_function :getpid, [ ], :uint
|
35
|
-
end.getpid.should
|
53
|
+
end.getpid.should eq Process.pid
|
36
54
|
}.should_not raise_error
|
37
55
|
end
|
38
56
|
it "attach_function :getpid from [ 'c', 'libc.so.6'] " do
|
@@ -41,7 +59,7 @@ describe "Library" do
|
|
41
59
|
m.extend FFI::Library
|
42
60
|
ffi_lib [ 'c', 'libc.so.6' ]
|
43
61
|
attach_function :getpid, [ ], :uint
|
44
|
-
end.getpid.should
|
62
|
+
end.getpid.should eq Process.pid
|
45
63
|
}.should_not raise_error
|
46
64
|
end
|
47
65
|
it "attach_function :getpid from [ 'libc.so.6', 'c' ] " do
|
@@ -50,7 +68,7 @@ describe "Library" do
|
|
50
68
|
m.extend FFI::Library
|
51
69
|
ffi_lib [ 'libc.so.6', 'c' ]
|
52
70
|
attach_function :getpid, [ ], :uint
|
53
|
-
end.getpid.should
|
71
|
+
end.getpid.should eq Process.pid
|
54
72
|
}.should_not raise_error
|
55
73
|
end
|
56
74
|
it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef', nil, 'c' ] " do
|
@@ -59,7 +77,7 @@ describe "Library" do
|
|
59
77
|
m.extend FFI::Library
|
60
78
|
ffi_lib [ 'libfubar.so.0xdeadbeef', nil, 'c' ]
|
61
79
|
attach_function :getpid, [ ], :uint
|
62
|
-
end.getpid.should
|
80
|
+
end.getpid.should eq Process.pid
|
63
81
|
}.should_not raise_error
|
64
82
|
end
|
65
83
|
it "attach_function :getpid from [ 'libfubar.so.0xdeadbeef' ] " do
|
@@ -68,7 +86,7 @@ describe "Library" do
|
|
68
86
|
m.extend FFI::Library
|
69
87
|
ffi_lib 'libfubar.so.0xdeadbeef'
|
70
88
|
attach_function :getpid, [ ], :uint
|
71
|
-
end.getpid.should
|
89
|
+
end.getpid.should eq Process.pid
|
72
90
|
}.should raise_error(LoadError)
|
73
91
|
end
|
74
92
|
end
|
@@ -85,10 +103,10 @@ describe "Library" do
|
|
85
103
|
def gvar_test(name, type, val)
|
86
104
|
lib = gvar_lib(name, type)
|
87
105
|
lib.set(val)
|
88
|
-
lib.gvar.should
|
106
|
+
lib.gvar.should eq val
|
89
107
|
lib.set(0)
|
90
108
|
lib.gvar = val
|
91
|
-
lib.get.should
|
109
|
+
lib.get.should eq val
|
92
110
|
end
|
93
111
|
[ 0, 127, -128, -1 ].each do |i|
|
94
112
|
it ":char variable" do
|
@@ -157,10 +175,10 @@ describe "Library" do
|
|
157
175
|
lib = gvar_lib("pointer", :pointer)
|
158
176
|
val = FFI::MemoryPointer.new :long
|
159
177
|
lib.set(val)
|
160
|
-
lib.gvar.should
|
178
|
+
lib.gvar.should eq val
|
161
179
|
lib.set(nil)
|
162
180
|
lib.gvar = val
|
163
|
-
lib.get.should
|
181
|
+
lib.get.should eq val
|
164
182
|
end
|
165
183
|
|
166
184
|
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
@@ -180,11 +198,11 @@ describe "Library" do
|
|
180
198
|
val = GlobalStruct.new
|
181
199
|
val[:data] = i
|
182
200
|
lib.set(val)
|
183
|
-
lib.gvar[:data].should
|
201
|
+
lib.gvar[:data].should eq i
|
184
202
|
val[:data] = 0
|
185
203
|
lib.gvar[:data] = i
|
186
204
|
val = GlobalStruct.new(lib.get)
|
187
|
-
val[:data].should
|
205
|
+
val[:data].should eq i
|
188
206
|
end
|
189
207
|
end
|
190
208
|
end
|
@@ -19,14 +19,14 @@ require 'java' if RUBY_PLATFORM =~ /java/
|
|
19
19
|
|
20
20
|
describe "Managed Struct" do
|
21
21
|
include FFI
|
22
|
-
module
|
22
|
+
module ManagedStructTestLib
|
23
23
|
extend FFI::Library
|
24
24
|
ffi_lib TestLibrary::PATH
|
25
25
|
attach_function :ptr_from_address, [ FFI::Platform::ADDRESS_SIZE == 32 ? :uint : :ulong_long ], :pointer
|
26
26
|
end
|
27
27
|
it "should raise an error if release() is not defined" do
|
28
28
|
class NoRelease < FFI::ManagedStruct ; layout :i, :int; end
|
29
|
-
lambda { NoRelease.new(
|
29
|
+
lambda { NoRelease.new(ManagedStructTestLib.ptr_from_address(0x12345678)) }.should raise_error(NoMethodError)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be the right class" do
|
@@ -36,7 +36,7 @@ describe "Managed Struct" do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
WhatClassAmI.new(
|
39
|
+
WhatClassAmI.new(ManagedStructTestLib.ptr_from_address(0x12345678)).class.should eq WhatClassAmI
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should release memory properly" do
|
@@ -65,7 +65,7 @@ describe "Managed Struct" do
|
|
65
65
|
|
66
66
|
PleaseReleaseMe.should_receive(:release).at_least(loop_count-wiggle_room).times
|
67
67
|
loop_count.times do
|
68
|
-
|
68
|
+
PleaseReleaseMe.new(ManagedStructTestLib.ptr_from_address(0x12345678))
|
69
69
|
end
|
70
70
|
PleaseReleaseMe.wait_gc loop_count
|
71
71
|
end
|
data/spec/ffi/number_spec.rb
CHANGED
@@ -37,95 +37,95 @@ describe "Function with primitive integer arguments" do
|
|
37
37
|
attach_function :get_double, [ ], :double
|
38
38
|
end
|
39
39
|
it "int8.size" do
|
40
|
-
FFI::TYPE_INT8.size.should
|
40
|
+
FFI::TYPE_INT8.size.should eq 1
|
41
41
|
end
|
42
42
|
it "uint8.size" do
|
43
|
-
FFI::TYPE_UINT8.size.should
|
43
|
+
FFI::TYPE_UINT8.size.should eq 1
|
44
44
|
end
|
45
45
|
it "int16.size" do
|
46
|
-
FFI::TYPE_INT16.size.should
|
46
|
+
FFI::TYPE_INT16.size.should eq 2
|
47
47
|
end
|
48
48
|
it "uint16.size" do
|
49
|
-
FFI::TYPE_UINT16.size.should
|
49
|
+
FFI::TYPE_UINT16.size.should eq 2
|
50
50
|
end
|
51
51
|
it "int32.size" do
|
52
|
-
FFI::TYPE_INT32.size.should
|
52
|
+
FFI::TYPE_INT32.size.should eq 4
|
53
53
|
end
|
54
54
|
it "uint32.size" do
|
55
|
-
FFI::TYPE_UINT32.size.should
|
55
|
+
FFI::TYPE_UINT32.size.should eq 4
|
56
56
|
end
|
57
57
|
it "int64.size" do
|
58
|
-
FFI::TYPE_INT64.size.should
|
58
|
+
FFI::TYPE_INT64.size.should eq 8
|
59
59
|
end
|
60
60
|
it "uint64.size" do
|
61
|
-
FFI::TYPE_UINT64.size.should
|
61
|
+
FFI::TYPE_UINT64.size.should eq 8
|
62
62
|
end
|
63
63
|
it "float.size" do
|
64
|
-
FFI::TYPE_FLOAT32.size.should
|
64
|
+
FFI::TYPE_FLOAT32.size.should eq 4
|
65
65
|
end
|
66
66
|
it "double.size" do
|
67
|
-
FFI::TYPE_FLOAT64.size.should
|
67
|
+
FFI::TYPE_FLOAT64.size.should eq 8
|
68
68
|
end
|
69
69
|
[ 0, 127, -128, -1 ].each do |i|
|
70
70
|
it ":char call(:char (#{i}))" do
|
71
|
-
LibTest.ret_s8(i).should
|
71
|
+
LibTest.ret_s8(i).should eq i
|
72
72
|
end
|
73
73
|
end
|
74
74
|
[ 0, 0x7f, 0x80, 0xff ].each do |i|
|
75
75
|
it ":uchar call(:uchar (#{i}))" do
|
76
|
-
LibTest.ret_u8(i).should
|
76
|
+
LibTest.ret_u8(i).should eq i
|
77
77
|
end
|
78
78
|
end
|
79
79
|
[ 0, 0x7fff, -0x8000, -1 ].each do |i|
|
80
80
|
it ":short call(:short (#{i}))" do
|
81
|
-
LibTest.ret_s16(i).should
|
81
|
+
LibTest.ret_s16(i).should eq i
|
82
82
|
end
|
83
83
|
end
|
84
84
|
[ 0, 0x7fff, 0x8000, 0xffff ].each do |i|
|
85
85
|
it ":ushort call(:ushort (#{i}))" do
|
86
|
-
LibTest.ret_u16(i).should
|
86
|
+
LibTest.ret_u16(i).should eq i
|
87
87
|
end
|
88
88
|
end
|
89
89
|
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
90
90
|
it ":int call(:int (#{i}))" do
|
91
|
-
LibTest.ret_s32(i).should
|
91
|
+
LibTest.ret_s32(i).should eq i
|
92
92
|
end
|
93
93
|
end
|
94
94
|
[ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
|
95
95
|
it ":uint call(:uint (#{i}))" do
|
96
|
-
LibTest.ret_u32(i).should
|
96
|
+
LibTest.ret_u32(i).should eq i
|
97
97
|
end
|
98
98
|
end
|
99
99
|
[ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
|
100
100
|
it ":long_long call(:long_long (#{i}))" do
|
101
|
-
LibTest.ret_s64(i).should
|
101
|
+
LibTest.ret_s64(i).should eq i
|
102
102
|
end
|
103
103
|
end
|
104
104
|
[ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
|
105
105
|
it ":ulong_long call(:ulong_long (#{i}))" do
|
106
|
-
LibTest.ret_u64(i).should
|
106
|
+
LibTest.ret_u64(i).should eq i
|
107
107
|
end
|
108
108
|
end
|
109
109
|
if FFI::Platform::LONG_SIZE == 32
|
110
110
|
[ 0, 0x7fffffff, -0x80000000, -1 ].each do |i|
|
111
111
|
it ":long call(:long (#{i}))" do
|
112
|
-
LibTest.ret_long(i).should
|
112
|
+
LibTest.ret_long(i).should eq i
|
113
113
|
end
|
114
114
|
end
|
115
115
|
[ 0, 0x7fffffff, 0x80000000, 0xffffffff ].each do |i|
|
116
116
|
it ":ulong call(:ulong (#{i}))" do
|
117
|
-
LibTest.ret_ulong(i).should
|
117
|
+
LibTest.ret_ulong(i).should eq i
|
118
118
|
end
|
119
119
|
end
|
120
120
|
else
|
121
121
|
[ 0, 0x7fffffffffffffff, -0x8000000000000000, -1 ].each do |i|
|
122
122
|
it ":long call(:long (#{i}))" do
|
123
|
-
LibTest.ret_long(i).should
|
123
|
+
LibTest.ret_long(i).should eq i
|
124
124
|
end
|
125
125
|
end
|
126
126
|
[ 0, 0x7fffffffffffffff, 0x8000000000000000, 0xffffffffffffffff ].each do |i|
|
127
127
|
it ":ulong call(:ulong (#{i}))" do
|
128
|
-
LibTest.ret_ulong(i).should
|
128
|
+
LibTest.ret_ulong(i).should eq i
|
129
129
|
end
|
130
130
|
end
|
131
131
|
[ 0.0, 0.1, 1.1, 1.23 ].each do |f|
|
@@ -145,32 +145,32 @@ end
|
|
145
145
|
describe "Integer parameter range checking" do
|
146
146
|
[ 128, -129 ].each do |i|
|
147
147
|
it ":char call(:char (#{i}))" do
|
148
|
-
lambda { LibTest.ret_int8_t(i).should
|
148
|
+
lambda { LibTest.ret_int8_t(i).should eq i }.should raise_error
|
149
149
|
end
|
150
150
|
end
|
151
151
|
[ -1, 256 ].each do |i|
|
152
152
|
it ":uchar call(:uchar (#{i}))" do
|
153
|
-
lambda { LibTest.ret_u_int8_t(i).should
|
153
|
+
lambda { LibTest.ret_u_int8_t(i).should eq i }.should raise_error
|
154
154
|
end
|
155
155
|
end
|
156
156
|
[ 0x8000, -0x8001 ].each do |i|
|
157
157
|
it ":short call(:short (#{i}))" do
|
158
|
-
lambda { LibTest.ret_int16_t(i).should
|
158
|
+
lambda { LibTest.ret_int16_t(i).should eq i }.should raise_error
|
159
159
|
end
|
160
160
|
end
|
161
161
|
[ -1, 0x10000 ].each do |i|
|
162
162
|
it ":ushort call(:ushort (#{i}))" do
|
163
|
-
lambda { LibTest.ret_u_int16_t(i).should
|
163
|
+
lambda { LibTest.ret_u_int16_t(i).should eq i }.should raise_error
|
164
164
|
end
|
165
165
|
end
|
166
166
|
[ 0x80000000, -0x80000001 ].each do |i|
|
167
167
|
it ":int call(:int (#{i}))" do
|
168
|
-
lambda { LibTest.ret_int32_t(i).should
|
168
|
+
lambda { LibTest.ret_int32_t(i).should eq i }.should raise_error
|
169
169
|
end
|
170
170
|
end
|
171
171
|
[ -1, 0x100000000 ].each do |i|
|
172
172
|
it ":ushort call(:ushort (#{i}))" do
|
173
|
-
lambda { LibTest.ret_u_int32_t(i).should
|
173
|
+
lambda { LibTest.ret_u_int32_t(i).should eq i }.should raise_error
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
@@ -214,17 +214,17 @@ describe "Three different size Integer arguments" do
|
|
214
214
|
# 'f32' => [ 1.234567 ],
|
215
215
|
'f64' => [ 9.87654321 ]
|
216
216
|
}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
end
|
217
|
+
|
218
|
+
def verify(p, off, t, v)
|
219
|
+
if t == 'f32'
|
220
|
+
p.get_float32(off).should eq v
|
221
|
+
elsif t == 'f64'
|
222
|
+
p.get_float64(off).should eq v
|
223
|
+
else
|
224
|
+
p.get_int64(off).should eq v
|
226
225
|
end
|
227
226
|
end
|
227
|
+
|
228
228
|
PACK_VALUES.keys.each do |t1|
|
229
229
|
PACK_VALUES.keys.each do |t2|
|
230
230
|
PACK_VALUES.keys.each do |t3|
|
@@ -234,9 +234,9 @@ describe "Three different size Integer arguments" do
|
|
234
234
|
it "call(#{TYPE_MAP[t1]} (#{v1}), #{TYPE_MAP[t2]} (#{v2}), #{TYPE_MAP[t3]} (#{v3}))" do
|
235
235
|
p = FFI::Buffer.new :long_long, 3
|
236
236
|
LibTest.send("pack_#{t1}#{t2}#{t3}_s64", v1, v2, v3, p)
|
237
|
-
|
238
|
-
|
239
|
-
|
237
|
+
verify(p, 0, t1, v1)
|
238
|
+
verify(p, 8, t2, v2)
|
239
|
+
verify(p, 16, t3, v3)
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
data/spec/ffi/pointer_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe "Pointer" do
|
|
40
40
|
magic = 0x12345678
|
41
41
|
memory.put_int32(0, magic)
|
42
42
|
tp = ToPtrTest.new(memory)
|
43
|
-
PointerTestLib.ptr_ret_int32_t(tp, 0).should
|
43
|
+
PointerTestLib.ptr_ret_int32_t(tp, 0).should eq magic
|
44
44
|
end
|
45
45
|
class PointerDelegate < DelegateClass(FFI::Pointer)
|
46
46
|
def initialize(ptr)
|
@@ -55,7 +55,7 @@ describe "Pointer" do
|
|
55
55
|
magic = 0x12345678
|
56
56
|
memory.put_int32(0, magic)
|
57
57
|
ptr = PointerDelegate.new(memory)
|
58
|
-
PointerTestLib.ptr_ret_int32_t(ptr, 0).should
|
58
|
+
PointerTestLib.ptr_ret_int32_t(ptr, 0).should eq magic
|
59
59
|
end
|
60
60
|
it "Fixnum cannot be used as a Pointer argument" do
|
61
61
|
lambda { PointerTestLib.ptr_ret_int32(0, 0) }.should raise_error
|
@@ -69,13 +69,13 @@ describe "Pointer" do
|
|
69
69
|
it "#read_pointer" do
|
70
70
|
memory = FFI::MemoryPointer.new :pointer
|
71
71
|
PointerTestLib.ptr_set_pointer(memory, 0, PointerTestLib.ptr_from_address(0xdeadbeef))
|
72
|
-
memory.read_pointer.address.should
|
72
|
+
memory.read_pointer.address.should eq 0xdeadbeef
|
73
73
|
end
|
74
74
|
|
75
75
|
it "#write_pointer" do
|
76
76
|
memory = FFI::MemoryPointer.new :pointer
|
77
77
|
memory.write_pointer(PointerTestLib.ptr_from_address(0xdeadbeef))
|
78
|
-
PointerTestLib.ptr_ret_pointer(memory, 0).address.should
|
78
|
+
PointerTestLib.ptr_ret_pointer(memory, 0).address.should eq 0xdeadbeef
|
79
79
|
end
|
80
80
|
|
81
81
|
it "#read_array_of_pointer" do
|
@@ -86,7 +86,7 @@ describe "Pointer" do
|
|
86
86
|
end
|
87
87
|
array = memory.read_array_of_pointer(values.size)
|
88
88
|
values.each_with_index do |address, j|
|
89
|
-
array[j].address.should
|
89
|
+
array[j].address.should eq address
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -149,7 +149,7 @@ describe "AutoPointer" do
|
|
149
149
|
# note that if we called
|
150
150
|
# AutoPointerTestHelper.method(:release).to_proc inline, we'd
|
151
151
|
# have a reference to the pointer and it would never get GC'd.
|
152
|
-
|
152
|
+
AutoPointerSubclass.new(PointerTestLib.ptr_from_address(magic))
|
153
153
|
end
|
154
154
|
AutoPointerTestHelper.gc_everything loop_count
|
155
155
|
end
|
@@ -166,8 +166,8 @@ describe "AutoPointer" do
|
|
166
166
|
AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
|
167
167
|
AutoPointerTestHelper.reset
|
168
168
|
loop_count.times do
|
169
|
-
|
170
|
-
|
169
|
+
FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
|
170
|
+
AutoPointerTestHelper.finalizer)
|
171
171
|
end
|
172
172
|
AutoPointerTestHelper.gc_everything loop_count
|
173
173
|
end
|
@@ -176,8 +176,8 @@ describe "AutoPointer" do
|
|
176
176
|
AutoPointerTestHelper.should_receive(:release).at_least(loop_count-wiggle_room).times
|
177
177
|
AutoPointerTestHelper.reset
|
178
178
|
loop_count.times do
|
179
|
-
|
180
|
-
|
179
|
+
FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
|
180
|
+
AutoPointerTestHelper.method(:release))
|
181
181
|
end
|
182
182
|
AutoPointerTestHelper.gc_everything loop_count
|
183
183
|
end
|
@@ -194,21 +194,18 @@ describe "AutoPointer" do
|
|
194
194
|
end
|
195
195
|
end.should_not raise_error
|
196
196
|
end
|
197
|
-
end
|
198
197
|
|
199
|
-
describe "
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
it "Buffer argument raises TypeError" do
|
210
|
-
lambda { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.should raise_error(::TypeError)
|
211
|
-
end
|
198
|
+
describe "#new" do
|
199
|
+
it "MemoryPointer argument raises TypeError" do
|
200
|
+
lambda { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.should raise_error(::TypeError)
|
201
|
+
end
|
202
|
+
it "AutoPointer argument raises TypeError" do
|
203
|
+
lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.should raise_error(::TypeError)
|
204
|
+
end
|
205
|
+
it "Buffer argument raises TypeError" do
|
206
|
+
lambda { FFI::AutoPointer.new(FFI::Buffer.new(:int))}.should raise_error(::TypeError)
|
207
|
+
end
|
212
208
|
|
209
|
+
end
|
213
210
|
end
|
214
211
|
|
@@ -12,42 +12,44 @@ end
|
|
12
12
|
describe "MemoryPointer" do
|
13
13
|
it "makes a pointer from a string" do
|
14
14
|
m = FFI::MemoryPointer.from_string("FFI is Awesome")
|
15
|
-
m.
|
15
|
+
m.total.should eq 15
|
16
|
+
m.type_size.should eq 1
|
16
17
|
end
|
17
18
|
|
18
19
|
it "makes a pointer from a string with multibyte characters" do
|
19
20
|
m = FFI::MemoryPointer.from_string("ぱんだ")
|
20
|
-
m.
|
21
|
+
m.total.should eq 10
|
22
|
+
m.type_size.should eq 1
|
21
23
|
end
|
22
24
|
|
23
25
|
it "reads back a string" do
|
24
26
|
m = FFI::MemoryPointer.from_string("FFI is Awesome")
|
25
|
-
m.read_string.should
|
27
|
+
m.read_string.should eq "FFI is Awesome"
|
26
28
|
end
|
27
29
|
|
28
30
|
it "makes a pointer for a certain number of bytes" do
|
29
31
|
m = FFI::MemoryPointer.new(8)
|
30
32
|
m.write_array_of_int([1,2])
|
31
|
-
m.read_array_of_int(2).should
|
33
|
+
m.read_array_of_int(2).should eq [1,2]
|
32
34
|
end
|
33
35
|
|
34
36
|
it "allows access to an element of the pointer (as an array)" do
|
35
37
|
m = FFI::MemoryPointer.new(:int, 2)
|
36
38
|
m.write_array_of_int([1,2])
|
37
|
-
m[0].read_int.should
|
38
|
-
m[1].read_int.should
|
39
|
+
m[0].read_int.should eq 1
|
40
|
+
m[1].read_int.should eq 2
|
39
41
|
end
|
40
42
|
|
41
43
|
it "allows writing as an int" do
|
42
44
|
m = FFI::MemoryPointer.new(:int)
|
43
45
|
m.write_int(1)
|
44
|
-
m.read_int.should
|
46
|
+
m.read_int.should eq 1
|
45
47
|
end
|
46
48
|
|
47
49
|
it "allows writing as a long" do
|
48
50
|
m = FFI::MemoryPointer.new(:long)
|
49
51
|
m.write_long(10)
|
50
|
-
m.read_long.should
|
52
|
+
m.read_long.should eq 10
|
51
53
|
end
|
52
54
|
|
53
55
|
it "raises an error if you try putting a long into a pointer of size 1" do
|
@@ -70,40 +72,40 @@ describe "MemoryPointer" do
|
|
70
72
|
it "makes a pointer for a certain type" do
|
71
73
|
m = FFI::MemoryPointer.new(:int)
|
72
74
|
m.write_int(10)
|
73
|
-
m.read_int.should
|
75
|
+
m.read_int.should eq 10
|
74
76
|
end
|
75
77
|
|
76
78
|
it "makes a memory pointer for a number of a certain type" do
|
77
79
|
m = FFI::MemoryPointer.new(:int, 2)
|
78
80
|
m.write_array_of_int([1,2])
|
79
|
-
m.read_array_of_int(2).should
|
81
|
+
m.read_array_of_int(2).should eq [1,2]
|
80
82
|
end
|
81
83
|
|
82
84
|
it "makes a pointer for an object responding to #size" do
|
83
85
|
m = FFI::MemoryPointer.new(Struct.new(:size).new(8))
|
84
86
|
m.write_array_of_int([1,2])
|
85
|
-
m.read_array_of_int(2).should
|
87
|
+
m.read_array_of_int(2).should eq [1,2]
|
86
88
|
end
|
87
89
|
|
88
90
|
it "makes a pointer for a number of an object responding to #size" do
|
89
91
|
m = FFI::MemoryPointer.new(Struct.new(:size).new(4), 2)
|
90
92
|
m.write_array_of_int([1,2])
|
91
|
-
m.read_array_of_int(2).should
|
93
|
+
m.read_array_of_int(2).should eq [1,2]
|
92
94
|
end
|
93
95
|
it "MemoryPointer#address returns correct value" do
|
94
96
|
m = FFI::MemoryPointer.new(:long_long)
|
95
97
|
magic = 0x12345678
|
96
98
|
m.write_long(magic)
|
97
|
-
m.read_pointer.address.should
|
99
|
+
m.read_pointer.address.should eq magic
|
98
100
|
end
|
99
101
|
it "MemoryPointer#null? returns true for zero value" do
|
100
102
|
m = FFI::MemoryPointer.new(:long_long)
|
101
103
|
m.write_long(0)
|
102
|
-
m.read_pointer.null?.should
|
104
|
+
m.read_pointer.null?.should eq true
|
103
105
|
end
|
104
106
|
it "MemoryPointer#null? returns false for non-zero value" do
|
105
107
|
m = FFI::MemoryPointer.new(:long_long)
|
106
108
|
m.write_long(0x12345678)
|
107
|
-
m.read_pointer.null?.should
|
109
|
+
m.read_pointer.null?.should eq false
|
108
110
|
end
|
109
111
|
end
|