ffi 0.2.0 → 0.3.0

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 (305) hide show
  1. data/README.rdoc +19 -0
  2. data/Rakefile +65 -55
  3. data/ext/{AbstractMemory.c → ffi_c/AbstractMemory.c} +67 -40
  4. data/ext/{AbstractMemory.h → ffi_c/AbstractMemory.h} +10 -8
  5. data/ext/{AutoPointer.c → ffi_c/AutoPointer.c} +17 -8
  6. data/ext/{AutoPointer.h → ffi_c/AutoPointer.h} +0 -0
  7. data/ext/ffi_c/Buffer.c +136 -0
  8. data/ext/{Callback.c → ffi_c/Callback.c} +60 -35
  9. data/ext/{Callback.h → ffi_c/Callback.h} +1 -7
  10. data/ext/{Invoker.c → ffi_c/Invoker.c} +472 -102
  11. data/ext/ffi_c/MemoryPointer.c +146 -0
  12. data/ext/{MemoryPointer.h → ffi_c/MemoryPointer.h} +2 -7
  13. data/ext/ffi_c/NativeLibrary.c +149 -0
  14. data/ext/{NativeLibrary.h → ffi_c/NativeLibrary.h} +0 -0
  15. data/ext/ffi_c/NullPointer.c +104 -0
  16. data/ext/{Platform.c → ffi_c/Platform.c} +0 -0
  17. data/ext/{Platform.h → ffi_c/Platform.h} +0 -7
  18. data/ext/{Pointer.c → ffi_c/Pointer.c} +35 -15
  19. data/ext/{Pointer.h → ffi_c/Pointer.h} +4 -2
  20. data/ext/ffi_c/Struct.c +542 -0
  21. data/ext/ffi_c/Struct.h +26 -0
  22. data/ext/ffi_c/Types.c +76 -0
  23. data/ext/{Types.h → ffi_c/Types.h} +23 -28
  24. data/ext/{compat.h → ffi_c/compat.h} +2 -2
  25. data/ext/{extconf.rb → ffi_c/extconf.rb} +12 -7
  26. data/ext/ffi_c/ffi.c +99 -0
  27. data/ext/ffi_c/ffi.mk +23 -0
  28. data/ext/{libffi.darwin.mk → ffi_c/libffi.darwin.mk} +0 -0
  29. data/ext/ffi_c/libffi.mk +11 -0
  30. data/ext/{libffi → ffi_c/libffi}/ChangeLog +0 -0
  31. data/ext/{libffi → ffi_c/libffi}/ChangeLog.libffi +0 -0
  32. data/ext/{libffi → ffi_c/libffi}/ChangeLog.libgcj +0 -0
  33. data/ext/{libffi → ffi_c/libffi}/ChangeLog.v1 +0 -0
  34. data/ext/{libffi → ffi_c/libffi}/LICENSE +0 -0
  35. data/ext/{libffi → ffi_c/libffi}/Makefile.am +0 -0
  36. data/ext/{libffi → ffi_c/libffi}/Makefile.in +0 -0
  37. data/ext/{libffi → ffi_c/libffi}/README +0 -0
  38. data/ext/{libffi → ffi_c/libffi}/TODO +0 -0
  39. data/ext/{libffi → ffi_c/libffi}/acinclude.m4 +0 -0
  40. data/ext/{libffi → ffi_c/libffi}/aclocal.m4 +0 -0
  41. data/ext/{libffi → ffi_c/libffi}/compile +0 -0
  42. data/ext/{libffi → ffi_c/libffi}/config.guess +0 -0
  43. data/ext/{libffi → ffi_c/libffi}/config.sub +0 -0
  44. data/ext/{libffi → ffi_c/libffi}/configure +0 -0
  45. data/ext/{libffi → ffi_c/libffi}/configure.ac +0 -0
  46. data/ext/{libffi → ffi_c/libffi}/configure.host +0 -0
  47. data/ext/{libffi → ffi_c/libffi}/depcomp +0 -0
  48. data/ext/{libffi → ffi_c/libffi}/doc/libffi.info +0 -0
  49. data/ext/{libffi → ffi_c/libffi}/doc/libffi.texi +0 -0
  50. data/ext/{libffi → ffi_c/libffi}/doc/stamp-vti +0 -0
  51. data/ext/{libffi → ffi_c/libffi}/doc/version.texi +0 -0
  52. data/ext/{libffi → ffi_c/libffi}/fficonfig.h.in +0 -0
  53. data/ext/{libffi → ffi_c/libffi}/include/Makefile.am +0 -0
  54. data/ext/{libffi → ffi_c/libffi}/include/Makefile.in +0 -0
  55. data/ext/{libffi → ffi_c/libffi}/include/ffi.h.in +0 -0
  56. data/ext/{libffi → ffi_c/libffi}/include/ffi_common.h +0 -0
  57. data/ext/{libffi → ffi_c/libffi}/install-sh +0 -0
  58. data/ext/{libffi → ffi_c/libffi}/libffi.pc.in +0 -0
  59. data/ext/{libffi → ffi_c/libffi}/libtool-version +0 -0
  60. data/ext/{libffi → ffi_c/libffi}/ltcf-c.sh +0 -0
  61. data/ext/{libffi → ffi_c/libffi}/ltcf-cxx.sh +0 -0
  62. data/ext/{libffi → ffi_c/libffi}/ltcf-gcj.sh +0 -0
  63. data/ext/{libffi → ffi_c/libffi}/ltconfig +0 -0
  64. data/ext/{libffi → ffi_c/libffi}/ltmain.sh +0 -0
  65. data/ext/{libffi → ffi_c/libffi}/man/Makefile.am +0 -0
  66. data/ext/{libffi → ffi_c/libffi}/man/Makefile.in +0 -0
  67. data/ext/{libffi → ffi_c/libffi}/man/ffi.3 +0 -0
  68. data/ext/{libffi → ffi_c/libffi}/man/ffi_call.3 +0 -0
  69. data/ext/{libffi → ffi_c/libffi}/man/ffi_prep_cif.3 +0 -0
  70. data/ext/{libffi → ffi_c/libffi}/mdate-sh +0 -0
  71. data/ext/{libffi → ffi_c/libffi}/missing +0 -0
  72. data/ext/{libffi → ffi_c/libffi}/mkinstalldirs +0 -0
  73. data/ext/{libffi → ffi_c/libffi}/src/alpha/ffi.c +0 -0
  74. data/ext/{libffi → ffi_c/libffi}/src/alpha/ffitarget.h +0 -0
  75. data/ext/{libffi → ffi_c/libffi}/src/alpha/osf.S +0 -0
  76. data/ext/{libffi → ffi_c/libffi}/src/arm/ffi.c +0 -0
  77. data/ext/{libffi → ffi_c/libffi}/src/arm/ffitarget.h +0 -0
  78. data/ext/{libffi → ffi_c/libffi}/src/arm/sysv.S +0 -0
  79. data/ext/{libffi → ffi_c/libffi}/src/closures.c +0 -0
  80. data/ext/{libffi → ffi_c/libffi}/src/cris/ffi.c +0 -0
  81. data/ext/{libffi → ffi_c/libffi}/src/cris/ffitarget.h +0 -0
  82. data/ext/{libffi → ffi_c/libffi}/src/cris/sysv.S +0 -0
  83. data/ext/{libffi → ffi_c/libffi}/src/debug.c +0 -0
  84. data/ext/{libffi → ffi_c/libffi}/src/dlmalloc.c +0 -0
  85. data/ext/{libffi → ffi_c/libffi}/src/frv/eabi.S +0 -0
  86. data/ext/{libffi → ffi_c/libffi}/src/frv/ffi.c +0 -0
  87. data/ext/{libffi → ffi_c/libffi}/src/frv/ffitarget.h +0 -0
  88. data/ext/{libffi → ffi_c/libffi}/src/ia64/ffi.c +0 -0
  89. data/ext/{libffi → ffi_c/libffi}/src/ia64/ffitarget.h +0 -0
  90. data/ext/{libffi → ffi_c/libffi}/src/ia64/ia64_flags.h +0 -0
  91. data/ext/{libffi → ffi_c/libffi}/src/ia64/unix.S +0 -0
  92. data/ext/{libffi → ffi_c/libffi}/src/java_raw_api.c +0 -0
  93. data/ext/{libffi → ffi_c/libffi}/src/m32r/ffi.c +0 -0
  94. data/ext/{libffi → ffi_c/libffi}/src/m32r/ffitarget.h +0 -0
  95. data/ext/{libffi → ffi_c/libffi}/src/m32r/sysv.S +0 -0
  96. data/ext/{libffi → ffi_c/libffi}/src/m68k/ffi.c +0 -0
  97. data/ext/{libffi → ffi_c/libffi}/src/m68k/ffitarget.h +0 -0
  98. data/ext/{libffi → ffi_c/libffi}/src/m68k/sysv.S +0 -0
  99. data/ext/{libffi → ffi_c/libffi}/src/mips/ffi.c +0 -0
  100. data/ext/{libffi → ffi_c/libffi}/src/mips/ffitarget.h +0 -0
  101. data/ext/{libffi → ffi_c/libffi}/src/mips/n32.S +0 -0
  102. data/ext/{libffi → ffi_c/libffi}/src/mips/o32.S +0 -0
  103. data/ext/{libffi → ffi_c/libffi}/src/pa/ffi.c +0 -0
  104. data/ext/{libffi → ffi_c/libffi}/src/pa/ffitarget.h +0 -0
  105. data/ext/{libffi → ffi_c/libffi}/src/pa/hpux32.S +0 -0
  106. data/ext/{libffi → ffi_c/libffi}/src/pa/linux.S +0 -0
  107. data/ext/{libffi → ffi_c/libffi}/src/powerpc/aix.S +0 -0
  108. data/ext/{libffi → ffi_c/libffi}/src/powerpc/aix_closure.S +0 -0
  109. data/ext/{libffi → ffi_c/libffi}/src/powerpc/asm.h +0 -0
  110. data/ext/{libffi → ffi_c/libffi}/src/powerpc/darwin.S +0 -0
  111. data/ext/{libffi → ffi_c/libffi}/src/powerpc/darwin_closure.S +0 -0
  112. data/ext/{libffi → ffi_c/libffi}/src/powerpc/ffi.c +0 -0
  113. data/ext/{libffi → ffi_c/libffi}/src/powerpc/ffi_darwin.c +0 -0
  114. data/ext/{libffi → ffi_c/libffi}/src/powerpc/ffitarget.h +0 -0
  115. data/ext/{libffi → ffi_c/libffi}/src/powerpc/linux64.S +0 -0
  116. data/ext/{libffi → ffi_c/libffi}/src/powerpc/linux64_closure.S +0 -0
  117. data/ext/{libffi → ffi_c/libffi}/src/powerpc/ppc_closure.S +0 -0
  118. data/ext/{libffi → ffi_c/libffi}/src/powerpc/sysv.S +0 -0
  119. data/ext/{libffi → ffi_c/libffi}/src/prep_cif.c +0 -0
  120. data/ext/{libffi → ffi_c/libffi}/src/raw_api.c +0 -0
  121. data/ext/{libffi → ffi_c/libffi}/src/s390/ffi.c +0 -0
  122. data/ext/{libffi → ffi_c/libffi}/src/s390/ffitarget.h +0 -0
  123. data/ext/{libffi → ffi_c/libffi}/src/s390/sysv.S +0 -0
  124. data/ext/{libffi → ffi_c/libffi}/src/sh/ffi.c +0 -0
  125. data/ext/{libffi → ffi_c/libffi}/src/sh/ffitarget.h +0 -0
  126. data/ext/{libffi → ffi_c/libffi}/src/sh/sysv.S +0 -0
  127. data/ext/{libffi → ffi_c/libffi}/src/sh64/ffi.c +0 -0
  128. data/ext/{libffi → ffi_c/libffi}/src/sh64/ffitarget.h +0 -0
  129. data/ext/{libffi → ffi_c/libffi}/src/sh64/sysv.S +0 -0
  130. data/ext/{libffi → ffi_c/libffi}/src/sparc/ffi.c +0 -0
  131. data/ext/{libffi → ffi_c/libffi}/src/sparc/ffitarget.h +0 -0
  132. data/ext/{libffi → ffi_c/libffi}/src/sparc/v8.S +0 -0
  133. data/ext/{libffi → ffi_c/libffi}/src/sparc/v9.S +0 -0
  134. data/ext/{libffi → ffi_c/libffi}/src/types.c +0 -0
  135. data/ext/{libffi → ffi_c/libffi}/src/x86/darwin.S +0 -0
  136. data/ext/{libffi → ffi_c/libffi}/src/x86/darwin64.S +0 -0
  137. data/ext/{libffi → ffi_c/libffi}/src/x86/ffi.c +0 -0
  138. data/ext/{libffi → ffi_c/libffi}/src/x86/ffi64.c +0 -0
  139. data/ext/{libffi → ffi_c/libffi}/src/x86/ffitarget.h +0 -0
  140. data/ext/{libffi → ffi_c/libffi}/src/x86/freebsd.S +0 -0
  141. data/ext/{libffi → ffi_c/libffi}/src/x86/sysv.S +0 -0
  142. data/ext/{libffi → ffi_c/libffi}/src/x86/unix64.S +0 -0
  143. data/ext/{libffi → ffi_c/libffi}/src/x86/win32.S +0 -0
  144. data/ext/{libffi → ffi_c/libffi}/testsuite/Makefile.am +0 -0
  145. data/ext/{libffi → ffi_c/libffi}/testsuite/Makefile.in +0 -0
  146. data/ext/{libffi → ffi_c/libffi}/testsuite/config/default.exp +0 -0
  147. data/ext/{libffi → ffi_c/libffi}/testsuite/lib/libffi-dg.exp +0 -0
  148. data/ext/{libffi → ffi_c/libffi}/testsuite/lib/target-libpath.exp +0 -0
  149. data/ext/{libffi → ffi_c/libffi}/testsuite/lib/wrapper.exp +0 -0
  150. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/call.exp +0 -0
  151. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn0.c +0 -0
  152. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn1.c +0 -0
  153. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn2.c +0 -0
  154. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn3.c +0 -0
  155. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn4.c +0 -0
  156. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn5.c +0 -0
  157. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_fn6.c +0 -0
  158. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/closure_stdcall.c +0 -0
  159. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_12byte.c +0 -0
  160. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_16byte.c +0 -0
  161. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_18byte.c +0 -0
  162. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_19byte.c +0 -0
  163. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_1_1byte.c +0 -0
  164. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_20byte.c +0 -0
  165. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_20byte1.c +0 -0
  166. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_24byte.c +0 -0
  167. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_2byte.c +0 -0
  168. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_3_1byte.c +0 -0
  169. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_3byte1.c +0 -0
  170. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_3byte2.c +0 -0
  171. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_4_1byte.c +0 -0
  172. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_4byte.c +0 -0
  173. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_5_1_byte.c +0 -0
  174. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_5byte.c +0 -0
  175. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_64byte.c +0 -0
  176. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_6_1_byte.c +0 -0
  177. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_6byte.c +0 -0
  178. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_7_1_byte.c +0 -0
  179. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_7byte.c +0 -0
  180. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_8byte.c +0 -0
  181. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_9byte1.c +0 -0
  182. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_9byte2.c +0 -0
  183. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_double.c +0 -0
  184. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_float.c +0 -0
  185. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_longdouble.c +0 -0
  186. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_pointer.c +0 -0
  187. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_sint16.c +0 -0
  188. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_sint32.c +0 -0
  189. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_sint64.c +0 -0
  190. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_uint16.c +0 -0
  191. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_uint32.c +0 -0
  192. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_align_uint64.c +0 -0
  193. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_double.c +0 -0
  194. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_float.c +0 -0
  195. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_schar.c +0 -0
  196. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_sshort.c +0 -0
  197. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_sshortchar.c +0 -0
  198. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_uchar.c +0 -0
  199. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_ushort.c +0 -0
  200. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_multi_ushortchar.c +0 -0
  201. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_schar.c +0 -0
  202. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_sint.c +0 -0
  203. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_sshort.c +0 -0
  204. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_uchar.c +0 -0
  205. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_uint.c +0 -0
  206. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_ulonglong.c +0 -0
  207. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/cls_ushort.c +0 -0
  208. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/ffitest.h +0 -0
  209. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float.c +0 -0
  210. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float1.c +0 -0
  211. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float2.c +0 -0
  212. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float3.c +0 -0
  213. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/float4.c +0 -0
  214. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/many.c +0 -0
  215. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/many_win32.c +0 -0
  216. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/negint.c +0 -0
  217. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct.c +0 -0
  218. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct1.c +0 -0
  219. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct10.c +0 -0
  220. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct2.c +0 -0
  221. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct3.c +0 -0
  222. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct4.c +0 -0
  223. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct5.c +0 -0
  224. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct6.c +0 -0
  225. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct7.c +0 -0
  226. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct8.c +0 -0
  227. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/nested_struct9.c +0 -0
  228. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/problem1.c +0 -0
  229. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/promotion.c +0 -0
  230. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/pyobjc-tc.c +0 -0
  231. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_dbl.c +0 -0
  232. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_dbl1.c +0 -0
  233. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_dbl2.c +0 -0
  234. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl.c +0 -0
  235. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl1.c +0 -0
  236. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl2.c +0 -0
  237. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_fl3.c +0 -0
  238. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ldl.c +0 -0
  239. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ll.c +0 -0
  240. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ll1.c +0 -0
  241. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_sc.c +0 -0
  242. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_sl.c +0 -0
  243. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_uc.c +0 -0
  244. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/return_ul.c +0 -0
  245. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/strlen.c +0 -0
  246. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/strlen_win32.c +0 -0
  247. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct1.c +0 -0
  248. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct2.c +0 -0
  249. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct3.c +0 -0
  250. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct4.c +0 -0
  251. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct5.c +0 -0
  252. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct6.c +0 -0
  253. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct7.c +0 -0
  254. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct8.c +0 -0
  255. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.call/struct9.c +0 -0
  256. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/ffitestcxx.h +0 -0
  257. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/special.exp +0 -0
  258. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/unwindtest.cc +0 -0
  259. data/ext/{libffi → ffi_c/libffi}/testsuite/libffi.special/unwindtest_ffi_call.cc +0 -0
  260. data/ext/{libffi → ffi_c/libffi}/texinfo.tex +0 -0
  261. data/ext/{rbffi.h → ffi_c/rbffi.h} +1 -8
  262. data/lib/ffi/autopointer.rb +7 -7
  263. data/lib/ffi/buffer.rb +0 -25
  264. data/lib/ffi/ffi.rb +1 -0
  265. data/lib/ffi/library.rb +103 -37
  266. data/lib/ffi/memorypointer.rb +25 -28
  267. data/lib/ffi/platform.rb +2 -2
  268. data/lib/ffi/pointer.rb +21 -7
  269. data/lib/ffi/struct.rb +161 -179
  270. data/lib/ffi/types.rb +3 -3
  271. data/lib/ffi/union.rb +17 -0
  272. data/nbproject/configurations.xml +98 -88
  273. data/samples/hello.rb +1 -2
  274. data/samples/sample_helper.rb +6 -0
  275. data/{specs → spec/ffi}/buffer_spec.rb +0 -0
  276. data/{specs → spec/ffi}/callback_spec.rb +114 -89
  277. data/{specs → spec/ffi}/errno_spec.rb +0 -0
  278. data/spec/ffi/library_spec.rb +144 -0
  279. data/{specs → spec/ffi}/managed_struct_spec.rb +12 -1
  280. data/{specs → spec/ffi}/number_spec.rb +34 -16
  281. data/{specs → spec/ffi}/pointer_spec.rb +46 -2
  282. data/{specs → spec/ffi}/rbx/attach_function_spec.rb +2 -1
  283. data/{specs → spec/ffi}/rbx/memory_pointer_spec.rb +19 -19
  284. data/{specs → spec/ffi}/rbx/spec_helper.rb +0 -0
  285. data/{specs → spec/ffi}/rbx/struct_spec.rb +0 -0
  286. data/spec/ffi/spec_helper.rb +13 -0
  287. data/{specs → spec/ffi}/string_spec.rb +8 -0
  288. data/spec/ffi/struct_spec.rb +453 -0
  289. data/{specs → spec/ffi}/typedef_spec.rb +3 -3
  290. data/spec/ffi/union_spec.rb +60 -0
  291. data/{specs → spec/ffi}/variadic_spec.rb +0 -0
  292. data/spec/spec.opts +4 -0
  293. metadata +356 -334
  294. data/README +0 -0
  295. data/ext/Buffer.c +0 -98
  296. data/ext/MemoryPointer.c +0 -99
  297. data/ext/NativeLibrary.c +0 -90
  298. data/ext/Types.c +0 -76
  299. data/ext/ffi.c +0 -64
  300. data/ext/ffi.mk +0 -24
  301. data/ext/libffi.mk +0 -10
  302. data/gen/Rakefile +0 -12
  303. data/specs/library_spec.rb +0 -55
  304. data/specs/spec_helper.rb +0 -9
  305. data/specs/struct_spec.rb +0 -223
@@ -1,5 +1,5 @@
1
1
  module FFI
2
- TypeDefs = Hash.new
2
+ # TypeDefs = Hash.new
3
3
  def self.add_typedef(current, add)
4
4
  if current.kind_of? Integer
5
5
  code = current
@@ -103,7 +103,7 @@ module FFI
103
103
  4 => :int,
104
104
  8 => :long_long,
105
105
  }
106
- SizeTypes = {
106
+ SizeTypes.merge!({
107
107
  NativeType::INT8 => 1,
108
108
  NativeType::UINT8 => 1,
109
109
  NativeType::INT16 => 2,
@@ -117,7 +117,7 @@ module FFI
117
117
  NativeType::LONG => FFI::Platform::LONG_SIZE / 8,
118
118
  NativeType::ULONG => FFI::Platform::LONG_SIZE / 8,
119
119
  NativeType::POINTER => FFI::Platform::ADDRESS_SIZE / 8,
120
- }
120
+ })
121
121
 
122
122
  def self.size_to_type(size)
123
123
  if sz = TypeSizes[size]
@@ -0,0 +1,17 @@
1
+ require 'ffi/struct'
2
+
3
+ module FFI
4
+ class UnionLayoutBuilder < FFI::StructLayoutBuilder
5
+ private
6
+ def calc_alignment_of(field_class, offset); 0; end
7
+ def calc_current_size(offset, size)
8
+ @size = size if size > @size
9
+ end
10
+ end
11
+ class Union < FFI::Struct
12
+ private
13
+ def self.builder
14
+ UnionLayoutBuilder.new
15
+ end
16
+ end
17
+ end
@@ -3,26 +3,31 @@
3
3
  <logicalFolder name="root" displayName="root" projectFiles="true">
4
4
  <logicalFolder name="ruby-ffi" displayName="ruby-ffi" projectFiles="true">
5
5
  <logicalFolder name="ext" displayName="ext" projectFiles="true">
6
- <itemPath>ext/AbstractMemory.c</itemPath>
7
- <itemPath>ext/AbstractMemory.h</itemPath>
8
- <itemPath>ext/AutoPointer.c</itemPath>
9
- <itemPath>ext/AutoPointer.h</itemPath>
10
- <itemPath>ext/Buffer.c</itemPath>
11
- <itemPath>ext/Callback.c</itemPath>
12
- <itemPath>ext/Callback.h</itemPath>
13
- <itemPath>ext/ffi.c</itemPath>
14
- <itemPath>ext/Invoker.c</itemPath>
15
- <itemPath>ext/MemoryPointer.c</itemPath>
16
- <itemPath>ext/MemoryPointer.h</itemPath>
17
- <itemPath>ext/NativeLibrary.c</itemPath>
18
- <itemPath>ext/NativeLibrary.h</itemPath>
19
- <itemPath>ext/Platform.c</itemPath>
20
- <itemPath>ext/Platform.h</itemPath>
21
- <itemPath>ext/Pointer.c</itemPath>
22
- <itemPath>ext/Pointer.h</itemPath>
23
- <itemPath>ext/rbffi.h</itemPath>
24
- <itemPath>ext/Types.c</itemPath>
25
- <itemPath>ext/Types.h</itemPath>
6
+ <itemPath>ext/ffi_c/AbstractMemory.c</itemPath>
7
+ <itemPath>ext/ffi_c/AbstractMemory.h</itemPath>
8
+ <itemPath>ext/ffi_c/AutoPointer.c</itemPath>
9
+ <itemPath>ext/ffi_c/AutoPointer.h</itemPath>
10
+ <itemPath>ext/ffi_c/Buffer.c</itemPath>
11
+ <itemPath>ext/ffi_c/Callback.c</itemPath>
12
+ <itemPath>ext/ffi_c/Callback.h</itemPath>
13
+ <itemPath>ext/ffi_c/compat.h</itemPath>
14
+ <itemPath>ext/ffi_c/extconf.rb</itemPath>
15
+ <itemPath>ext/ffi_c/ffi.c</itemPath>
16
+ <itemPath>ext/ffi_c/Invoker.c</itemPath>
17
+ <itemPath>ext/ffi_c/MemoryPointer.c</itemPath>
18
+ <itemPath>ext/ffi_c/MemoryPointer.h</itemPath>
19
+ <itemPath>ext/ffi_c/NativeLibrary.c</itemPath>
20
+ <itemPath>ext/ffi_c/NativeLibrary.h</itemPath>
21
+ <itemPath>ext/ffi_c/NullPointer.c</itemPath>
22
+ <itemPath>ext/ffi_c/Platform.c</itemPath>
23
+ <itemPath>ext/ffi_c/Platform.h</itemPath>
24
+ <itemPath>ext/ffi_c/Pointer.c</itemPath>
25
+ <itemPath>ext/ffi_c/Pointer.h</itemPath>
26
+ <itemPath>ext/ffi_c/rbffi.h</itemPath>
27
+ <itemPath>ext/ffi_c/Struct.c</itemPath>
28
+ <itemPath>ext/ffi_c/Struct.h</itemPath>
29
+ <itemPath>ext/ffi_c/Types.c</itemPath>
30
+ <itemPath>ext/ffi_c/Types.h</itemPath>
26
31
  </logicalFolder>
27
32
  <logicalFolder name="f1" displayName="lib" projectFiles="true">
28
33
  <logicalFolder name="ffi" displayName="ffi" projectFiles="true">
@@ -35,6 +40,7 @@
35
40
  <itemPath>lib/ffi/platform.rb</itemPath>
36
41
  <itemPath>lib/ffi/pointer.rb</itemPath>
37
42
  <itemPath>lib/ffi/struct.rb</itemPath>
43
+ <itemPath>lib/ffi/types.rb</itemPath>
38
44
  <itemPath>lib/ffi/variadic.rb</itemPath>
39
45
  </logicalFolder>
40
46
  <itemPath>lib/ffi.rb</itemPath>
@@ -43,6 +49,7 @@
43
49
  <itemPath>libtest/Benchmark.c</itemPath>
44
50
  <itemPath>libtest/BufferTest.c</itemPath>
45
51
  <itemPath>libtest/ClosureTest.c</itemPath>
52
+ <itemPath>libtest/GlobalVariable.c</itemPath>
46
53
  <itemPath>libtest/LastErrorTest.c</itemPath>
47
54
  <itemPath>libtest/NumberTest.c</itemPath>
48
55
  <itemPath>libtest/PointerTest.c</itemPath>
@@ -51,28 +58,27 @@
51
58
  <itemPath>libtest/StructTest.c</itemPath>
52
59
  <itemPath>libtest/VariadicTest.c</itemPath>
53
60
  </logicalFolder>
54
- <logicalFolder name="specs" displayName="specs" projectFiles="true">
55
- <logicalFolder name="rbx" displayName="rbx" projectFiles="true">
56
- <itemPath>specs/rbx/attach_function_spec.rb</itemPath>
57
- <itemPath>specs/rbx/memory_pointer_spec.rb</itemPath>
58
- <itemPath>specs/rbx/spec_helper.rb</itemPath>
59
- <itemPath>specs/rbx/struct_spec.rb</itemPath>
60
- </logicalFolder>
61
- <itemPath>specs/buffer_spec.rb</itemPath>
62
- <itemPath>specs/callback_spec.rb</itemPath>
63
- <itemPath>specs/library_spec.rb</itemPath>
64
- <itemPath>specs/number_spec.rb</itemPath>
65
- <itemPath>specs/pointer_spec.rb</itemPath>
66
- <itemPath>specs/spec_helper.rb</itemPath>
67
- <itemPath>specs/string_spec.rb</itemPath>
68
- <itemPath>specs/struct_spec.rb</itemPath>
69
- <itemPath>specs/typedef_spec.rb</itemPath>
61
+ <logicalFolder name="f2" displayName="spec" projectFiles="true">
62
+ <itemPath>spec/ffi/buffer_spec.rb</itemPath>
63
+ <itemPath>spec/ffi/callback_spec.rb</itemPath>
64
+ <itemPath>spec/ffi/errno_spec.rb</itemPath>
65
+ <itemPath>spec/ffi/library_spec.rb</itemPath>
66
+ <itemPath>spec/ffi/managed_struct_spec.rb</itemPath>
67
+ <itemPath>spec/ffi/number_spec.rb</itemPath>
68
+ <itemPath>spec/ffi/pointer_spec.rb</itemPath>
69
+ <itemPath>spec/ffi/spec_helper.rb</itemPath>
70
+ <itemPath>spec/ffi/string_spec.rb</itemPath>
71
+ <itemPath>spec/ffi/struct_spec.rb</itemPath>
72
+ <itemPath>spec/ffi/typedef_spec.rb</itemPath>
73
+ <itemPath>spec/ffi/union_spec.rb</itemPath>
74
+ <itemPath>spec/ffi/variadic_spec.rb</itemPath>
70
75
  </logicalFolder>
71
76
  </logicalFolder>
72
77
  <logicalFolder name="ExternalFiles"
73
78
  displayName="Important Files"
74
79
  projectFiles="false">
75
80
  <itemPath>Makefile</itemPath>
81
+ <itemPath>Rakefile</itemPath>
76
82
  <itemPath>ruby-ffi-Makefile.mk</itemPath>
77
83
  </logicalFolder>
78
84
  </logicalFolder>
@@ -99,81 +105,79 @@
99
105
  <requiredProjects>
100
106
  </requiredProjects>
101
107
  </makefileType>
102
- <item path="ext/AbstractMemory.c">
103
- <itemExcluded>true</itemExcluded>
108
+ <item path="ext/ffi_c/AbstractMemory.c">
104
109
  <itemTool>0</itemTool>
105
110
  </item>
106
- <item path="ext/AbstractMemory.h">
107
- <itemExcluded>true</itemExcluded>
111
+ <item path="ext/ffi_c/AbstractMemory.h">
108
112
  <itemTool>3</itemTool>
109
113
  </item>
110
- <item path="ext/AutoPointer.c">
114
+ <item path="ext/ffi_c/AutoPointer.c">
111
115
  <itemTool>0</itemTool>
112
116
  </item>
113
- <item path="ext/AutoPointer.h">
117
+ <item path="ext/ffi_c/AutoPointer.h">
114
118
  <itemTool>3</itemTool>
115
119
  </item>
116
- <item path="ext/Buffer.c">
117
- <itemExcluded>true</itemExcluded>
120
+ <item path="ext/ffi_c/Buffer.c">
118
121
  <itemTool>0</itemTool>
119
122
  </item>
120
- <item path="ext/Callback.c">
121
- <itemExcluded>true</itemExcluded>
122
- <itemTool>3</itemTool>
123
+ <item path="ext/ffi_c/Callback.c">
124
+ <itemTool>0</itemTool>
123
125
  </item>
124
- <item path="ext/Callback.h">
125
- <itemExcluded>true</itemExcluded>
126
+ <item path="ext/ffi_c/Callback.h">
126
127
  <itemTool>3</itemTool>
127
128
  </item>
128
- <item path="ext/Invoker.c">
129
- <itemExcluded>true</itemExcluded>
129
+ <item path="ext/ffi_c/Invoker.c">
130
130
  <itemTool>0</itemTool>
131
131
  </item>
132
- <item path="ext/MemoryPointer.c">
133
- <itemExcluded>true</itemExcluded>
134
- <itemTool>3</itemTool>
132
+ <item path="ext/ffi_c/MemoryPointer.c">
133
+ <itemTool>0</itemTool>
135
134
  </item>
136
- <item path="ext/MemoryPointer.h">
137
- <itemExcluded>true</itemExcluded>
135
+ <item path="ext/ffi_c/MemoryPointer.h">
138
136
  <itemTool>3</itemTool>
139
137
  </item>
140
- <item path="ext/NativeLibrary.c">
141
- <itemExcluded>true</itemExcluded>
138
+ <item path="ext/ffi_c/NativeLibrary.c">
142
139
  <itemTool>0</itemTool>
143
140
  </item>
144
- <item path="ext/NativeLibrary.h">
141
+ <item path="ext/ffi_c/NativeLibrary.h">
145
142
  <itemTool>3</itemTool>
146
143
  </item>
147
- <item path="ext/Platform.c">
148
- <itemExcluded>true</itemExcluded>
144
+ <item path="ext/ffi_c/NullPointer.c">
149
145
  <itemTool>0</itemTool>
150
146
  </item>
151
- <item path="ext/Platform.h">
152
- <itemExcluded>true</itemExcluded>
147
+ <item path="ext/ffi_c/Platform.c">
148
+ <itemTool>0</itemTool>
149
+ </item>
150
+ <item path="ext/ffi_c/Platform.h">
153
151
  <itemTool>3</itemTool>
154
152
  </item>
155
- <item path="ext/Pointer.c">
156
- <itemExcluded>true</itemExcluded>
153
+ <item path="ext/ffi_c/Pointer.c">
154
+ <itemTool>0</itemTool>
155
+ </item>
156
+ <item path="ext/ffi_c/Pointer.h">
157
157
  <itemTool>3</itemTool>
158
158
  </item>
159
- <item path="ext/Pointer.h">
160
- <itemExcluded>true</itemExcluded>
159
+ <item path="ext/ffi_c/Struct.c">
160
+ <itemTool>0</itemTool>
161
+ </item>
162
+ <item path="ext/ffi_c/Struct.h">
161
163
  <itemTool>3</itemTool>
162
164
  </item>
163
- <item path="ext/Types.c">
164
- <itemExcluded>true</itemExcluded>
165
+ <item path="ext/ffi_c/Types.c">
165
166
  <itemTool>0</itemTool>
166
167
  </item>
167
- <item path="ext/Types.h">
168
- <itemExcluded>true</itemExcluded>
168
+ <item path="ext/ffi_c/Types.h">
169
+ <itemTool>3</itemTool>
170
+ </item>
171
+ <item path="ext/ffi_c/compat.h">
172
+ <itemTool>3</itemTool>
173
+ </item>
174
+ <item path="ext/ffi_c/extconf.rb">
169
175
  <itemTool>3</itemTool>
170
176
  </item>
171
- <item path="ext/ffi.c">
172
- <itemExcluded>true</itemExcluded>
177
+ <item path="ext/ffi_c/ffi.c">
173
178
  <itemTool>0</itemTool>
174
179
  </item>
175
- <item path="ext/rbffi.h">
176
- <itemExcluded>true</itemExcluded>
180
+ <item path="ext/ffi_c/rbffi.h">
177
181
  <itemTool>3</itemTool>
178
182
  </item>
179
183
  <item path="lib/ffi.rb">
@@ -206,6 +210,9 @@
206
210
  <item path="lib/ffi/struct.rb">
207
211
  <itemTool>3</itemTool>
208
212
  </item>
213
+ <item path="lib/ffi/types.rb">
214
+ <itemTool>3</itemTool>
215
+ </item>
209
216
  <item path="lib/ffi/variadic.rb">
210
217
  <itemTool>3</itemTool>
211
218
  </item>
@@ -218,6 +225,9 @@
218
225
  <item path="libtest/ClosureTest.c">
219
226
  <itemTool>0</itemTool>
220
227
  </item>
228
+ <item path="libtest/GlobalVariable.c">
229
+ <itemTool>0</itemTool>
230
+ </item>
221
231
  <item path="libtest/LastErrorTest.c">
222
232
  <itemTool>0</itemTool>
223
233
  </item>
@@ -239,43 +249,43 @@
239
249
  <item path="libtest/VariadicTest.c">
240
250
  <itemTool>0</itemTool>
241
251
  </item>
242
- <item path="specs/buffer_spec.rb">
252
+ <item path="spec/ffi/buffer_spec.rb">
243
253
  <itemTool>3</itemTool>
244
254
  </item>
245
- <item path="specs/callback_spec.rb">
255
+ <item path="spec/ffi/callback_spec.rb">
246
256
  <itemTool>3</itemTool>
247
257
  </item>
248
- <item path="specs/library_spec.rb">
258
+ <item path="spec/ffi/errno_spec.rb">
249
259
  <itemTool>3</itemTool>
250
260
  </item>
251
- <item path="specs/number_spec.rb">
261
+ <item path="spec/ffi/library_spec.rb">
252
262
  <itemTool>3</itemTool>
253
263
  </item>
254
- <item path="specs/pointer_spec.rb">
264
+ <item path="spec/ffi/managed_struct_spec.rb">
255
265
  <itemTool>3</itemTool>
256
266
  </item>
257
- <item path="specs/rbx/attach_function_spec.rb">
267
+ <item path="spec/ffi/number_spec.rb">
258
268
  <itemTool>3</itemTool>
259
269
  </item>
260
- <item path="specs/rbx/memory_pointer_spec.rb">
270
+ <item path="spec/ffi/pointer_spec.rb">
261
271
  <itemTool>3</itemTool>
262
272
  </item>
263
- <item path="specs/rbx/spec_helper.rb">
273
+ <item path="spec/ffi/spec_helper.rb">
264
274
  <itemTool>3</itemTool>
265
275
  </item>
266
- <item path="specs/rbx/struct_spec.rb">
276
+ <item path="spec/ffi/string_spec.rb">
267
277
  <itemTool>3</itemTool>
268
278
  </item>
269
- <item path="specs/spec_helper.rb">
279
+ <item path="spec/ffi/struct_spec.rb">
270
280
  <itemTool>3</itemTool>
271
281
  </item>
272
- <item path="specs/string_spec.rb">
282
+ <item path="spec/ffi/typedef_spec.rb">
273
283
  <itemTool>3</itemTool>
274
284
  </item>
275
- <item path="specs/struct_spec.rb">
285
+ <item path="spec/ffi/union_spec.rb">
276
286
  <itemTool>3</itemTool>
277
287
  </item>
278
- <item path="specs/typedef_spec.rb">
288
+ <item path="spec/ffi/variadic_spec.rb">
279
289
  <itemTool>3</itemTool>
280
290
  </item>
281
291
  </conf>
@@ -1,5 +1,4 @@
1
- require 'rubygems'
2
- require 'ffi'
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "sample_helper"))
3
2
  module Foo
4
3
  extend FFI::Library
5
4
  attach_function("cputs", "puts", [ :string ], :int)
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib"), File.join(File.dirname(__FILE__), "..", "build", RUBY_VERSION) unless RUBY_PLATFORM =~ /java/
5
+ require "ffi"
6
+
File without changes
@@ -1,33 +1,33 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
2
 
3
3
  describe "Callback" do
4
- module LibC
5
- extend FFI::Library
6
- callback :qsort_cmp, [ :pointer, :pointer ], :int
7
- attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int
8
- end
9
- it "arguments get passed correctly" do
10
- p = MemoryPointer.new(:int, 2)
11
- p.put_array_of_int32(0, [ 1 , 2 ])
12
- args = []
13
- cmp = proc do |p1, p2| args.push(p1.get_int(0)); args.push(p2.get_int(0)); 0; end
14
- # this is a bit dodgey, as it relies on qsort passing the args in order
15
- LibC.qsort(p, 2, 4, cmp)
16
- args.should == [ 1, 2 ]
17
- end
18
-
19
- it "Block can be substituted for Callback as last argument" do
20
- p = MemoryPointer.new(:int, 2)
21
- p.put_array_of_int32(0, [ 1 , 2 ])
22
- args = []
23
- # this is a bit dodgey, as it relies on qsort passing the args in order
24
- LibC.qsort(p, 2, 4) do |p1, p2|
25
- args.push(p1.get_int(0))
26
- args.push(p2.get_int(0))
27
- 0
28
- end
29
- args.should == [ 1, 2 ]
30
- end
4
+ # module LibC
5
+ # extend FFI::Library
6
+ # callback :qsort_cmp, [ :pointer, :pointer ], :int
7
+ # attach_function :qsort, [ :pointer, :int, :int, :qsort_cmp ], :int
8
+ # end
9
+ # it "arguments get passed correctly" do
10
+ # p = MemoryPointer.new(:int, 2)
11
+ # p.put_array_of_int32(0, [ 1 , 2 ])
12
+ # args = []
13
+ # cmp = proc do |p1, p2| args.push(p1.get_int(0)); args.push(p2.get_int(0)); 0; end
14
+ # # this is a bit dodgey, as it relies on qsort passing the args in order
15
+ # LibC.qsort(p, 2, 4, cmp)
16
+ # args.should == [ 1, 2 ]
17
+ # end
18
+ #
19
+ # it "Block can be substituted for Callback as last argument" do
20
+ # p = MemoryPointer.new(:int, 2)
21
+ # p.put_array_of_int32(0, [ 1 , 2 ])
22
+ # args = []
23
+ # # this is a bit dodgey, as it relies on qsort passing the args in order
24
+ # LibC.qsort(p, 2, 4) do |p1, p2|
25
+ # args.push(p1.get_int(0))
26
+ # args.push(p2.get_int(0))
27
+ # 0
28
+ # end
29
+ # args.should == [ 1, 2 ]
30
+ # end
31
31
  module LibTest
32
32
  extend FFI::Library
33
33
  ffi_lib TestLibrary::PATH
@@ -39,6 +39,7 @@ describe "Callback" do
39
39
  callback :cbVrU32, [ ], :uint
40
40
  callback :cbVrS64, [ ], :long_long
41
41
  callback :cbVrU64, [ ], :ulong_long
42
+ callback :cbVrP, [], :pointer
42
43
  callback :cbCrV, [ :char ], :void
43
44
  callback :cbSrV, [ :short ], :void
44
45
  callback :cbIrV, [ :int ], :void
@@ -51,119 +52,143 @@ describe "Callback" do
51
52
  attach_function :testCallbackVrU32, :testClosureVrI, [ :cbVrU32 ], :uint
52
53
  attach_function :testCallbackVrS64, :testClosureVrL, [ :cbVrS64 ], :long_long
53
54
  attach_function :testCallbackVrU64, :testClosureVrL, [ :cbVrU64 ], :ulong_long
55
+ attach_function :testCallbackVrP, :testClosureVrP, [ :cbVrP ], :pointer
54
56
  attach_function :testCallbackCrV, :testClosureBrV, [ :cbCrV, :char ], :void
57
+ attach_variable :cbVrS8, :gvar_pointer, :cbVrS8
58
+ attach_variable :pVrS8, :gvar_pointer, :pointer
59
+ attach_function :testGVarCallbackVrS8, :testClosureVrB, [ :pointer ], :char
60
+ attach_function :testOptionalCallbackCrV, :testOptionalClosureBrV, [ :cbCrV, :char ], :void
61
+
55
62
  end
56
63
  it "function with Callback plus another arg should raise error if no arg given" do
57
64
  lambda { LibTest.testCallbackCrV { |*a| }}.should raise_error
58
65
  end
59
- it "Callback returning :char (0)" do
66
+ it "returning :char (0)" do
60
67
  LibTest.testCallbackVrS8 { 0 }.should == 0
61
68
  end
62
- it "Callback returning :char (127)" do
69
+ it "returning :char (127)" do
63
70
  LibTest.testCallbackVrS8 { 127 }.should == 127
64
71
  end
65
- it "Callback returning :char (-128)" do
72
+ it "returning :char (-128)" do
66
73
  LibTest.testCallbackVrS8 { -128 }.should == -128
67
74
  end
68
75
  # test wrap around
69
- it "Callback returning :char (128)" do
76
+ it "returning :char (128)" do
70
77
  LibTest.testCallbackVrS8 { 128 }.should == -128
71
78
  end
72
- it "Callback returning :char (255)" do
79
+ it "returning :char (255)" do
73
80
  LibTest.testCallbackVrS8 { 0xff }.should == -1
74
81
  end
75
- it "Callback returning :uchar (0)" do
82
+ it "returning :uchar (0)" do
76
83
  LibTest.testCallbackVrU8 { 0 }.should == 0
77
84
  end
78
- it "Callback returning :uchar (0xff)" do
85
+ it "returning :uchar (0xff)" do
79
86
  LibTest.testCallbackVrU8 { 0xff }.should == 0xff
80
87
  end
81
- it "Callback returning :uchar (-1)" do
88
+ it "returning :uchar (-1)" do
82
89
  LibTest.testCallbackVrU8 { -1 }.should == 0xff
83
90
  end
84
- it "Callback returning :uchar (128)" do
91
+ it "returning :uchar (128)" do
85
92
  LibTest.testCallbackVrU8 { 128 }.should == 128
86
93
  end
87
- it "Callback returning :uchar (-128)" do
94
+ it "returning :uchar (-128)" do
88
95
  LibTest.testCallbackVrU8 { -128 }.should == 128
89
96
  end
90
- it "Callback returning :short (0)" do
97
+ it "returning :short (0)" do
91
98
  LibTest.testCallbackVrS16 { 0 }.should == 0
92
99
  end
93
- it "Callback returning :short (0x7fff)" do
100
+ it "returning :short (0x7fff)" do
94
101
  LibTest.testCallbackVrS16 { 0x7fff }.should == 0x7fff
95
102
  end
96
103
  # test wrap around
97
- it "Callback returning :short (0x8000)" do
104
+ it "returning :short (0x8000)" do
98
105
  LibTest.testCallbackVrS16 { 0x8000 }.should == -0x8000
99
106
  end
100
- it "Callback returning :short (0xffff)" do
107
+ it "returning :short (0xffff)" do
101
108
  LibTest.testCallbackVrS16 { 0xffff }.should == -1
102
109
  end
103
- it "Callback returning :ushort (0)" do
110
+ it "returning :ushort (0)" do
104
111
  LibTest.testCallbackVrU16 { 0 }.should == 0
105
112
  end
106
- it "Callback returning :ushort (0x7fff)" do
113
+ it "returning :ushort (0x7fff)" do
107
114
  LibTest.testCallbackVrU16 { 0x7fff }.should == 0x7fff
108
115
  end
109
- it "Callback returning :ushort (0x8000)" do
116
+ it "returning :ushort (0x8000)" do
110
117
  LibTest.testCallbackVrU16 { 0x8000 }.should == 0x8000
111
118
  end
112
- it "Callback returning :ushort (0xffff)" do
119
+ it "returning :ushort (0xffff)" do
113
120
  LibTest.testCallbackVrU16 { 0xffff }.should == 0xffff
114
121
  end
115
- it "Callback returning :ushort (-1)" do
122
+ it "returning :ushort (-1)" do
116
123
  LibTest.testCallbackVrU16 { -1 }.should == 0xffff
117
124
  end
118
125
 
119
- it "Callback returning :int (0)" do
126
+ it "returning :int (0)" do
120
127
  LibTest.testCallbackVrS32 { 0 }.should == 0
121
128
  end
122
- it "Callback returning :int (0x7fffffff)" do
129
+ it "returning :int (0x7fffffff)" do
123
130
  LibTest.testCallbackVrS32 { 0x7fffffff }.should == 0x7fffffff
124
131
  end
125
132
  # test wrap around
126
- it "Callback returning :int (-0x80000000)" do
133
+ it "returning :int (-0x80000000)" do
127
134
  LibTest.testCallbackVrS32 { -0x80000000 }.should == -0x80000000
128
135
  end
129
- it "Callback returning :int (-1)" do
136
+ it "returning :int (-1)" do
130
137
  LibTest.testCallbackVrS32 { -1 }.should == -1
131
138
  end
132
139
 
133
- it "Callback returning :uint (0)" do
140
+ it "returning :uint (0)" do
134
141
  LibTest.testCallbackVrU32 { 0 }.should == 0
135
142
  end
136
- it "Callback returning :uint (0x7fffffff)" do
143
+ it "returning :uint (0x7fffffff)" do
137
144
  LibTest.testCallbackVrU32 { 0x7fffffff }.should == 0x7fffffff
138
145
  end
139
146
  # test wrap around
140
- it "Callback returning :uint (0x80000000)" do
147
+ it "returning :uint (0x80000000)" do
141
148
  LibTest.testCallbackVrU32 { 0x80000000 }.should == 0x80000000
142
149
  end
143
- it "Callback returning :uint (0xffffffff)" do
150
+ it "returning :uint (0xffffffff)" do
144
151
  LibTest.testCallbackVrU32 { 0xffffffff }.should == 0xffffffff
145
152
  end
146
153
  it "Callback returning :uint (-1)" do
147
154
  LibTest.testCallbackVrU32 { -1 }.should == 0xffffffff
148
155
  end
149
156
 
150
- it "Callback returning :long_long (0)" do
157
+ it "returning :long_long (0)" do
151
158
  LibTest.testCallbackVrS64 { 0 }.should == 0
152
159
  end
153
- it "Callback returning :long_long (0x7fffffffffffffff)" do
160
+ it "returning :long_long (0x7fffffffffffffff)" do
154
161
  LibTest.testCallbackVrS64 { 0x7fffffffffffffff }.should == 0x7fffffffffffffff
155
162
  end
156
163
  # test wrap around
157
- it "Callback returning :long_long (-0x8000000000000000)" do
164
+ it "returning :long_long (-0x8000000000000000)" do
158
165
  LibTest.testCallbackVrS64 { -0x8000000000000000 }.should == -0x8000000000000000
159
166
  end
160
- it "Callback returning :long_long (-1)" do
167
+ it "returning :long_long (-1)" do
161
168
  LibTest.testCallbackVrS64 { -1 }.should == -1
162
169
  end
170
+ it "returning :pointer (nil)" do
171
+ LibTest.testCallbackVrP { nil }.null?.should be_true
172
+ end
173
+ it "returning :pointer (MemoryPointer)" do
174
+ p = MemoryPointer.new :long
175
+ LibTest.testCallbackVrP { p }.should == p
176
+ end
177
+
178
+ it "global variable" do
179
+ proc = Proc.new { 0x1e }
180
+ LibTest.cbVrS8 = proc
181
+ LibTest.testGVarCallbackVrS8(LibTest.pVrS8).should == 0x1e
182
+ end
183
+
184
+ describe "When the callback is considered optional by the underlying library" do
185
+ it "should handle receiving 'nil' in place of the closure" do
186
+ LibTest.testOptionalCallbackCrV(nil, 13)
187
+ end
188
+ end
163
189
 
164
-
165
190
  end
166
- describe "Callback with primitive argument" do
191
+ describe "primitive argument" do
167
192
  #
168
193
  # Test callbacks that take an argument, returning void
169
194
  #
@@ -185,151 +210,151 @@ describe "Callback with primitive argument" do
185
210
  attach_function :testCallbackU32rV, :testClosureIrV, [ :cbU32rV, :uint ], :void
186
211
  attach_function :testCallbackLrV, :testClosureLrV, [ :cbS64rV, :long_long ], :void
187
212
  end
188
- it "Callback with :char (0) argument" do
213
+ it ":char (0) argument" do
189
214
  v = 0xdeadbeef
190
215
  LibTest.testCallbackCrV(0) { |i| v = i }
191
216
  v.should == 0
192
217
  end
193
- it "Callback with :char (127) argument" do
218
+ it ":char (127) argument" do
194
219
  v = 0xdeadbeef
195
220
  LibTest.testCallbackCrV(127) { |i| v = i }
196
221
  v.should == 127
197
222
  end
198
- it "Callback with :char (-128) argument" do
223
+ it ":char (-128) argument" do
199
224
  v = 0xdeadbeef
200
225
  LibTest.testCallbackCrV(-128) { |i| v = i }
201
226
  v.should == -128
202
227
  end
203
- it "Callback with :char (-1) argument" do
228
+ it ":char (-1) argument" do
204
229
  v = 0xdeadbeef
205
230
  LibTest.testCallbackCrV(-1) { |i| v = i }
206
231
  v.should == -1
207
232
  end
208
233
 
209
- it "Callback with :uchar (0) argument" do
234
+ it ":uchar (0) argument" do
210
235
  v = 0xdeadbeef
211
236
  LibTest.testCallbackU8rV(0) { |i| v = i }
212
237
  v.should == 0
213
238
  end
214
- it "Callback with :uchar (127) argument" do
239
+ it ":uchar (127) argument" do
215
240
  v = 0xdeadbeef
216
241
  LibTest.testCallbackU8rV(127) { |i| v = i }
217
242
  v.should == 127
218
243
  end
219
- it "Callback with :uchar (128) argument" do
244
+ it ":uchar (128) argument" do
220
245
  v = 0xdeadbeef
221
246
  LibTest.testCallbackU8rV(128) { |i| v = i }
222
247
  v.should == 128
223
248
  end
224
- it "Callback with :uchar (255) argument" do
249
+ it ":uchar (255) argument" do
225
250
  v = 0xdeadbeef
226
251
  LibTest.testCallbackU8rV(255) { |i| v = i }
227
252
  v.should == 255
228
253
  end
229
254
 
230
- it "Callback with :short (0) argument" do
255
+ it ":short (0) argument" do
231
256
  v = 0xdeadbeef
232
257
  LibTest.testCallbackSrV(0) { |i| v = i }
233
258
  v.should == 0
234
259
  end
235
- it "Callback with :short (0x7fff) argument" do
260
+ it ":short (0x7fff) argument" do
236
261
  v = 0xdeadbeef
237
262
  LibTest.testCallbackSrV(0x7fff) { |i| v = i }
238
263
  v.should == 0x7fff
239
264
  end
240
- it "Callback with :short (-0x8000) argument" do
265
+ it ":short (-0x8000) argument" do
241
266
  v = 0xdeadbeef
242
267
  LibTest.testCallbackSrV(-0x8000) { |i| v = i }
243
268
  v.should == -0x8000
244
269
  end
245
- it "Callback with :short (-1) argument" do
270
+ it ":short (-1) argument" do
246
271
  v = 0xdeadbeef
247
272
  LibTest.testCallbackSrV(-1) { |i| v = i }
248
273
  v.should == -1
249
274
  end
250
275
 
251
- it "Callback with :ushort (0) argument" do
276
+ it ":ushort (0) argument" do
252
277
  v = 0xdeadbeef
253
278
  LibTest.testCallbackU16rV(0) { |i| v = i }
254
279
  v.should == 0
255
280
  end
256
- it "Callback with :ushort (0x7fff) argument" do
281
+ it ":ushort (0x7fff) argument" do
257
282
  v = 0xdeadbeef
258
283
  LibTest.testCallbackU16rV(0x7fff) { |i| v = i }
259
284
  v.should == 0x7fff
260
285
  end
261
- it "Callback with :ushort (0x8000) argument" do
286
+ it ":ushort (0x8000) argument" do
262
287
  v = 0xdeadbeef
263
288
  LibTest.testCallbackU16rV(0x8000) { |i| v = i }
264
289
  v.should == 0x8000
265
290
  end
266
- it "Callback with :ushort (0xffff) argument" do
291
+ it ":ushort (0xffff) argument" do
267
292
  v = 0xdeadbeef
268
293
  LibTest.testCallbackU16rV(0xffff) { |i| v = i }
269
294
  v.should == 0xffff
270
295
  end
271
296
 
272
- it "Callback with :int (0) argument" do
297
+ it ":int (0) argument" do
273
298
  v = 0xdeadbeef
274
299
  LibTest.testCallbackIrV(0) { |i| v = i }
275
300
  v.should == 0
276
301
  end
277
- it "Callback with :int (0x7fffffff) argument" do
302
+ it ":int (0x7fffffff) argument" do
278
303
  v = 0xdeadbeef
279
304
  LibTest.testCallbackIrV(0x7fffffff) { |i| v = i }
280
305
  v.should == 0x7fffffff
281
306
  end
282
- it "Callback with :int (-0x80000000) argument" do
307
+ it ":int (-0x80000000) argument" do
283
308
  v = 0xdeadbeef
284
309
  LibTest.testCallbackIrV(-0x80000000) { |i| v = i }
285
310
  v.should == -0x80000000
286
311
  end
287
- it "Callback with :int (-1) argument" do
312
+ it ":int (-1) argument" do
288
313
  v = 0xdeadbeef
289
314
  LibTest.testCallbackIrV(-1) { |i| v = i }
290
315
  v.should == -1
291
316
  end
292
317
 
293
- it "Callback with :uint (0) argument" do
318
+ it ":uint (0) argument" do
294
319
  v = 0xdeadbeef
295
320
  LibTest.testCallbackU32rV(0) { |i| v = i }
296
321
  v.should == 0
297
322
  end
298
- it "Callback with :uint (0x7fffffff) argument" do
323
+ it ":uint (0x7fffffff) argument" do
299
324
  v = 0xdeadbeef
300
325
  LibTest.testCallbackU32rV(0x7fffffff) { |i| v = i }
301
326
  v.should == 0x7fffffff
302
327
  end
303
- it "Callback with :uint (0x80000000) argument" do
328
+ it ":uint (0x80000000) argument" do
304
329
  v = 0xdeadbeef
305
330
  LibTest.testCallbackU32rV(0x80000000) { |i| v = i }
306
331
  v.should == 0x80000000
307
332
  end
308
- it "Callback with :uint (0xffffffff) argument" do
333
+ it ":uint (0xffffffff) argument" do
309
334
  v = 0xdeadbeef
310
335
  LibTest.testCallbackU32rV(0xffffffff) { |i| v = i }
311
336
  v.should == 0xffffffff
312
337
  end
313
338
 
314
- it "Callback with :long_long (0) argument" do
339
+ it ":long_long (0) argument" do
315
340
  v = 0xdeadbeef
316
341
  LibTest.testCallbackLrV(0) { |i| v = i }
317
342
  v.should == 0
318
343
  end
319
- it "Callback with :long_long (0x7fffffffffffffff) argument" do
344
+ it ":long_long (0x7fffffffffffffff) argument" do
320
345
  v = 0xdeadbeef
321
346
  LibTest.testCallbackLrV(0x7fffffffffffffff) { |i| v = i }
322
347
  v.should == 0x7fffffffffffffff
323
348
  end
324
- it "Callback with :long_long (-0x8000000000000000) argument" do
349
+ it ":long_long (-0x8000000000000000) argument" do
325
350
  v = 0xdeadbeef
326
351
  LibTest.testCallbackLrV(-0x8000000000000000) { |i| v = i }
327
352
  v.should == -0x8000000000000000
328
353
  end
329
- it "Callback with :long_long (-1) argument" do
354
+ it ":long_long (-1) argument" do
330
355
  v = 0xdeadbeef
331
356
  LibTest.testCallbackLrV(-1) { |i| v = i }
332
357
  v.should == -1
333
358
  end
334
359
 
335
- end unless true
360
+ end unless true