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.

Files changed (218) hide show
  1. data/Rakefile +16 -16
  2. data/ext/ffi_c/AbstractMemory.c +376 -14
  3. data/ext/ffi_c/AbstractMemory.h +8 -0
  4. data/ext/ffi_c/ArrayType.c +28 -0
  5. data/ext/ffi_c/Buffer.c +109 -25
  6. data/ext/ffi_c/Call.c +16 -5
  7. data/ext/ffi_c/ClosurePool.c +21 -8
  8. data/ext/ffi_c/DataConverter.c +29 -0
  9. data/ext/ffi_c/DynamicLibrary.c +71 -2
  10. data/ext/ffi_c/Function.c +122 -11
  11. data/ext/ffi_c/Function.h +6 -0
  12. data/ext/ffi_c/FunctionInfo.c +21 -1
  13. data/ext/ffi_c/LastError.c +24 -0
  14. data/ext/ffi_c/MappedType.c +22 -0
  15. data/ext/ffi_c/MemoryPointer.c +19 -1
  16. data/ext/ffi_c/MemoryPointer.h +6 -0
  17. data/ext/ffi_c/MethodHandle.c +26 -11
  18. data/ext/ffi_c/Platform.c +17 -3
  19. data/ext/ffi_c/Pointer.c +106 -0
  20. data/ext/ffi_c/Pointer.h +6 -0
  21. data/ext/ffi_c/Struct.c +10 -4
  22. data/ext/ffi_c/Struct.h +2 -1
  23. data/ext/ffi_c/StructByReference.c +8 -0
  24. data/ext/ffi_c/StructByValue.c +8 -0
  25. data/ext/ffi_c/StructLayout.c +8 -2
  26. data/ext/ffi_c/Thread.c +131 -1
  27. data/ext/ffi_c/Thread.h +6 -0
  28. data/ext/ffi_c/Type.c +111 -17
  29. data/ext/ffi_c/Types.c +9 -2
  30. data/ext/ffi_c/Types.h +4 -0
  31. data/ext/ffi_c/Variadic.c +13 -4
  32. data/ext/ffi_c/compat.h +8 -0
  33. data/ext/ffi_c/endian.h +10 -1
  34. data/ext/ffi_c/extconf.rb +51 -35
  35. data/ext/ffi_c/ffi.c +5 -0
  36. data/ext/ffi_c/libffi.darwin.mk +15 -15
  37. data/ext/ffi_c/libffi.gnu.mk +3 -3
  38. data/ext/ffi_c/libffi.mk +4 -4
  39. data/ext/ffi_c/libffi.vc.mk +26 -0
  40. data/ext/ffi_c/libffi.vc64.mk +26 -0
  41. data/ext/ffi_c/libffi/ChangeLog +541 -0
  42. data/ext/ffi_c/libffi/ChangeLog.libffi +13 -87
  43. data/ext/ffi_c/libffi/LICENSE +3 -3
  44. data/ext/ffi_c/libffi/Makefile.am +41 -32
  45. data/ext/ffi_c/libffi/Makefile.in +95 -66
  46. data/ext/ffi_c/libffi/Makefile.vc +141 -0
  47. data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
  48. data/ext/ffi_c/libffi/README +40 -4
  49. data/ext/ffi_c/libffi/aclocal.m4 +729 -7854
  50. data/ext/ffi_c/libffi/build-ios.sh +67 -0
  51. data/ext/ffi_c/libffi/compile +11 -10
  52. data/ext/ffi_c/libffi/config.guess +4 -1
  53. data/ext/ffi_c/libffi/config.sub +6 -3
  54. data/ext/ffi_c/libffi/configure +6264 -6354
  55. data/ext/ffi_c/libffi/configure.ac +155 -63
  56. data/ext/ffi_c/libffi/depcomp +81 -35
  57. data/ext/ffi_c/libffi/doc/libffi.info +78 -18
  58. data/ext/ffi_c/libffi/doc/libffi.texi +64 -5
  59. data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
  60. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  61. data/ext/ffi_c/libffi/fficonfig.h.in +18 -0
  62. data/ext/ffi_c/libffi/fficonfig.hw +57 -0
  63. data/ext/ffi_c/libffi/include/Makefile.in +21 -3
  64. data/ext/ffi_c/libffi/include/ffi.h.in +42 -14
  65. data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
  66. data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
  67. data/ext/ffi_c/libffi/include/ffi_common.h +9 -5
  68. data/ext/ffi_c/libffi/install-sh +364 -167
  69. data/ext/ffi_c/libffi/ltmain.sh +2599 -1369
  70. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
  71. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
  72. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
  73. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
  74. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  75. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
  76. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
  77. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
  78. data/ext/ffi_c/libffi/m4/libtool.m4 +1239 -768
  79. data/ext/ffi_c/libffi/m4/ltoptions.m4 +7 -6
  80. data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
  81. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +9 -3
  82. data/ext/ffi_c/libffi/man/Makefile.in +21 -3
  83. data/ext/ffi_c/libffi/mdate-sh +0 -0
  84. data/ext/ffi_c/libffi/missing +60 -44
  85. data/ext/ffi_c/libffi/msvcc.sh +197 -0
  86. data/ext/ffi_c/libffi/src/alpha/osf.S +39 -18
  87. data/ext/ffi_c/libffi/src/arm/ffi.c +443 -24
  88. data/ext/ffi_c/libffi/src/arm/ffitarget.h +17 -1
  89. data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
  90. data/ext/ffi_c/libffi/src/arm/sysv.S +206 -15
  91. data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
  92. data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
  93. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +2 -2
  94. data/ext/ffi_c/libffi/src/closures.c +17 -35
  95. data/ext/ffi_c/libffi/src/cris/ffi.c +1 -1
  96. data/ext/ffi_c/libffi/src/cris/ffitarget.h +2 -2
  97. data/ext/ffi_c/libffi/src/dlmalloc.c +66 -4
  98. data/ext/ffi_c/libffi/src/frv/ffitarget.h +2 -6
  99. data/ext/ffi_c/libffi/src/ia64/ffi.c +7 -5
  100. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +2 -2
  101. data/ext/ffi_c/libffi/src/java_raw_api.c +1 -1
  102. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +2 -2
  103. data/ext/ffi_c/libffi/src/m68k/ffi.c +10 -0
  104. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +2 -2
  105. data/ext/ffi_c/libffi/src/m68k/sysv.S +36 -0
  106. data/ext/ffi_c/libffi/src/mips/ffi.c +12 -5
  107. data/ext/ffi_c/libffi/src/mips/ffitarget.h +18 -11
  108. data/ext/ffi_c/libffi/src/mips/n32.S +4 -4
  109. data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
  110. data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
  111. data/ext/ffi_c/libffi/src/pa/ffi.c +7 -4
  112. data/ext/ffi_c/libffi/src/pa/ffitarget.h +6 -5
  113. data/ext/ffi_c/libffi/src/powerpc/aix.S +5 -1
  114. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +2 -0
  115. data/ext/ffi_c/libffi/src/powerpc/asm.h +1 -1
  116. data/ext/ffi_c/libffi/src/powerpc/darwin.S +215 -77
  117. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +358 -100
  118. data/ext/ffi_c/libffi/src/powerpc/ffi.c +11 -5
  119. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +603 -172
  120. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +17 -4
  121. data/ext/ffi_c/libffi/src/prep_cif.c +16 -13
  122. data/ext/ffi_c/libffi/src/s390/ffitarget.h +4 -2
  123. data/ext/ffi_c/libffi/src/sh/ffitarget.h +2 -2
  124. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +2 -2
  125. data/ext/ffi_c/libffi/src/sparc/ffi.c +55 -11
  126. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +5 -3
  127. data/ext/ffi_c/libffi/src/x86/ffi.c +54 -92
  128. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  129. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -14
  130. data/ext/ffi_c/libffi/src/x86/sysv.S +40 -26
  131. data/ext/ffi_c/libffi/src/x86/unix64.S +4 -0
  132. data/ext/ffi_c/libffi/src/x86/win32.S +379 -191
  133. data/ext/ffi_c/libffi/src/x86/win64.S +15 -7
  134. data/ext/ffi_c/libffi/testsuite/Makefile.am +1 -1
  135. data/ext/ffi_c/libffi/testsuite/Makefile.in +22 -4
  136. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
  137. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +1 -5
  138. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +1 -1
  139. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +1 -1
  140. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +1 -0
  141. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +1 -0
  142. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +3 -0
  143. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +2 -2
  144. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +3 -0
  145. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +1 -1
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +1 -0
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +2 -3
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -1
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +36 -0
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +17 -17
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -0
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +1 -0
  154. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +1 -1
  155. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +1 -3
  156. data/ext/ffi_c/win32/stdint.h +199 -0
  157. data/gen/Rakefile +18 -2
  158. data/lib/1.8/ffi_c.so +0 -0
  159. data/lib/ffi.rb +13 -9
  160. data/lib/ffi/autopointer.rb +88 -26
  161. data/lib/ffi/enum.rb +42 -0
  162. data/lib/ffi/errno.rb +6 -1
  163. data/lib/ffi/ffi.rb +1 -0
  164. data/lib/ffi/io.rb +13 -2
  165. data/lib/ffi/library.rb +219 -24
  166. data/lib/ffi/memorypointer.rb +1 -33
  167. data/lib/ffi/platform.rb +21 -7
  168. data/lib/ffi/platform/arm-linux/types.conf +102 -0
  169. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  170. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  171. data/lib/ffi/platform/i486-gnu/types.conf +107 -0
  172. data/lib/ffi/platform/ia64-linux/types.conf +102 -0
  173. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  174. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  175. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  176. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  177. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  178. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  179. data/lib/ffi/platform/x86_64-freebsd/types.conf +126 -0
  180. data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  181. data/lib/ffi/pointer.rb +44 -0
  182. data/lib/ffi/struct.rb +2 -6
  183. data/lib/ffi/struct_layout_builder.rb +2 -1
  184. data/lib/ffi/tools/const_generator.rb +78 -26
  185. data/lib/ffi/tools/types_generator.rb +8 -1
  186. data/lib/ffi/types.rb +21 -1
  187. data/spec/ffi/async_callback_spec.rb +2 -2
  188. data/spec/ffi/bool_spec.rb +6 -6
  189. data/spec/ffi/buffer_spec.rb +23 -23
  190. data/spec/ffi/callback_spec.rb +101 -102
  191. data/spec/ffi/custom_type_spec.rb +20 -24
  192. data/spec/ffi/dup_spec.rb +7 -7
  193. data/spec/ffi/enum_spec.rb +127 -127
  194. data/spec/ffi/errno_spec.rb +2 -2
  195. data/spec/ffi/ffi_spec.rb +3 -3
  196. data/spec/ffi/function_spec.rb +10 -10
  197. data/spec/ffi/library_spec.rb +30 -12
  198. data/spec/ffi/managed_struct_spec.rb +4 -4
  199. data/spec/ffi/number_spec.rb +40 -40
  200. data/spec/ffi/pointer_spec.rb +21 -24
  201. data/spec/ffi/rbx/memory_pointer_spec.rb +17 -15
  202. data/spec/ffi/rbx/struct_spec.rb +2 -2
  203. data/spec/ffi/spec_helper.rb +1 -1
  204. data/spec/ffi/string_spec.rb +9 -9
  205. data/spec/ffi/strptr_spec.rb +3 -3
  206. data/spec/ffi/struct_callback_spec.rb +7 -7
  207. data/spec/ffi/struct_initialize_spec.rb +2 -2
  208. data/spec/ffi/struct_packed_spec.rb +6 -6
  209. data/spec/ffi/struct_spec.rb +94 -84
  210. data/spec/ffi/typedef_spec.rb +15 -4
  211. data/spec/ffi/union_spec.rb +3 -3
  212. data/spec/ffi/variadic_spec.rb +17 -14
  213. data/tasks/extension.rake +0 -1
  214. data/tasks/gem.rake +0 -1
  215. data/tasks/rdoc.rake +1 -1
  216. data/tasks/yard.rake +11 -0
  217. metadata +50 -11
  218. data/lib/1.9/ffi_c.so +0 -0
@@ -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 Config::CONFIG['target_os'] =~ /mswin|mingw/
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 == Process.pid
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 == Process.pid
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 == Process.pid
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 == Process.pid
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 == Process.pid
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 == val
106
+ lib.gvar.should eq val
89
107
  lib.set(0)
90
108
  lib.gvar = val
91
- lib.get.should == val
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 == val
178
+ lib.gvar.should eq val
161
179
  lib.set(nil)
162
180
  lib.gvar = val
163
- lib.get.should == val
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 == i
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 == i
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 LibTest
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(LibTest.ptr_from_address(0x12345678)) }.should raise_error(NoMethodError)
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(LibTest.ptr_from_address(0x12345678)).class.should == WhatClassAmI
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
- s = PleaseReleaseMe.new(LibTest.ptr_from_address(0x12345678))
68
+ PleaseReleaseMe.new(ManagedStructTestLib.ptr_from_address(0x12345678))
69
69
  end
70
70
  PleaseReleaseMe.wait_gc loop_count
71
71
  end
@@ -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 == 1
40
+ FFI::TYPE_INT8.size.should eq 1
41
41
  end
42
42
  it "uint8.size" do
43
- FFI::TYPE_UINT8.size.should == 1
43
+ FFI::TYPE_UINT8.size.should eq 1
44
44
  end
45
45
  it "int16.size" do
46
- FFI::TYPE_INT16.size.should == 2
46
+ FFI::TYPE_INT16.size.should eq 2
47
47
  end
48
48
  it "uint16.size" do
49
- FFI::TYPE_UINT16.size.should == 2
49
+ FFI::TYPE_UINT16.size.should eq 2
50
50
  end
51
51
  it "int32.size" do
52
- FFI::TYPE_INT32.size.should == 4
52
+ FFI::TYPE_INT32.size.should eq 4
53
53
  end
54
54
  it "uint32.size" do
55
- FFI::TYPE_UINT32.size.should == 4
55
+ FFI::TYPE_UINT32.size.should eq 4
56
56
  end
57
57
  it "int64.size" do
58
- FFI::TYPE_INT64.size.should == 8
58
+ FFI::TYPE_INT64.size.should eq 8
59
59
  end
60
60
  it "uint64.size" do
61
- FFI::TYPE_UINT64.size.should == 8
61
+ FFI::TYPE_UINT64.size.should eq 8
62
62
  end
63
63
  it "float.size" do
64
- FFI::TYPE_FLOAT32.size.should == 4
64
+ FFI::TYPE_FLOAT32.size.should eq 4
65
65
  end
66
66
  it "double.size" do
67
- FFI::TYPE_FLOAT64.size.should == 8
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i
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 == i }.should raise_error
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 == i }.should raise_error
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 == i }.should raise_error
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 == i }.should raise_error
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 == i }.should raise_error
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 == i }.should raise_error
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
- module Number
218
- def self.verify(p, off, t, v)
219
- if t == 'f32'
220
- p.get_float32(off).should == v
221
- elsif t == 'f64'
222
- p.get_float64(off).should == v
223
- else
224
- p.get_int64(off).should == v
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
- Number.verify(p, 0, t1, v1)
238
- Number.verify(p, 8, t2, v2)
239
- Number.verify(p, 16, t3, v3)
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
@@ -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 == magic
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 == magic
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 == 0xdeadbeef
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 == 0xdeadbeef
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 == address
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
- ap = AutoPointerSubclass.new(PointerTestLib.ptr_from_address(magic))
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
- ap = FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
170
- AutoPointerTestHelper.finalizer)
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
- ap = FFI::AutoPointer.new(PointerTestLib.ptr_from_address(magic),
180
- AutoPointerTestHelper.method(:release))
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 "AutoPointer#new" do
200
- class AutoPointerSubclass < FFI::AutoPointer
201
- def self.release(ptr); end
202
- end
203
- it "MemoryPointer argument raises TypeError" do
204
- lambda { FFI::AutoPointer.new(FFI::MemoryPointer.new(:int))}.should raise_error(::TypeError)
205
- end
206
- it "AutoPointer argument raises TypeError" do
207
- lambda { AutoPointerSubclass.new(AutoPointerSubclass.new(PointerTestLib.ptr_from_address(0))) }.should raise_error(::TypeError)
208
- end
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.type_size.should == 15
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.type_size.should == 10
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 == "FFI is Awesome"
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 == [1,2]
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 == 1
38
- m[1].read_int.should == 2
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 == 1
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 == 10
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 == 10
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 == [1,2]
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 == [1,2]
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 == [1,2]
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 == magic
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 == true
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 == false
109
+ m.read_pointer.null?.should eq false
108
110
  end
109
111
  end