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
@@ -0,0 +1,19 @@
1
+ ruby-ffi
2
+ by Wayne Meissner
3
+ http://kenai.com/projects/ruby-ffi
4
+
5
+ == DESCRIPTION:
6
+
7
+ A Ruby foreign function interface
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ == SYNOPSIS:
12
+
13
+ == REQUIREMENTS:
14
+
15
+ == DOWNLOAD/INSTALL:
16
+
17
+ == LICENSE:
18
+
19
+ See LICENSE file.
data/Rakefile CHANGED
@@ -1,104 +1,114 @@
1
1
  require 'rubygems'
2
- require 'rake/gempackagetask'
3
- require 'rubygems/specification'
2
+
3
+ USE_RAKE_COMPILER = (RUBY_VERSION =~ /1\.9.*/ || RUBY_PLATFORM =~ /java/) ? false : true
4
+ if USE_RAKE_COMPILER
5
+ gem 'rake-compiler', '>=0.3.0'
6
+ require 'rake/extensiontask'
7
+ end
8
+
4
9
  require 'date'
5
10
  require 'fileutils'
6
11
  require 'rbconfig'
7
12
 
8
- GEM = "ffi"
9
- GEM_VERSION = "0.2.0"
10
- AUTHOR = "Wayne Meissner"
11
- EMAIL = "wmeissner@gmail.com"
12
- HOMEPAGE = "http://kenai.com/projects/ruby-ffi"
13
- SUMMARY = "A Ruby foreign function interface (compatible with Rubinius and JRuby FFI)"
13
+ begin
14
+ require 'bones'
15
+ Bones.setup
16
+ rescue LoadError
17
+ begin
18
+ load 'tasks/setup.rb'
19
+ rescue LoadError
20
+ raise RuntimeError, '### please install the "bones" gem ###'
21
+ end
22
+ end
23
+
14
24
  LIBEXT = Config::CONFIG['host_os'].downcase =~ /darwin/ ? "dylib" : "so"
15
25
  GMAKE = Config::CONFIG['host_os'].downcase =~ /bsd/ ? "gmake" : "make"
16
26
  LIBTEST = "build/libtest.#{LIBEXT}"
27
+ BUILD_DIR = "build/#{RUBY_VERSION}"
28
+
29
+ # Project general information
30
+ PROJ.name = 'ffi'
31
+ PROJ.authors = 'Wayne Meissner'
32
+ PROJ.email = 'wmeissner@gmail.com'
33
+ PROJ.url = 'http://kenai.com/projects/ruby-ffi'
34
+ PROJ.version = '0.3.0'
35
+ PROJ.rubyforge.name = 'ffi'
36
+
37
+ PROJ.readme_file = 'README.rdoc'
38
+
39
+ # Annoucement
40
+ PROJ.ann.paragraphs
41
+ PROJ.ann.email[:from] = 'wmeissner@gmail.com'
42
+ PROJ.ann.email[:to] << 'dev@ruby-ffi.kenai.com' << 'users@ruby-ffi.kenai.com'
43
+ PROJ.ann.email[:server] = 'smtp.gmail.com'
44
+
45
+ # Gem specifications
46
+ PROJ.gem.need_tar = false
47
+ PROJ.gem.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{ext,lib,nbproject,samples,spec}/**/*")
48
+ PROJ.gem.platform = Gem::Platform::RUBY
49
+ PROJ.gem.extensions = %w(ext/ffi_c/extconf.rb gen/Rakefile)
50
+
51
+ # RDoc
52
+ PROJ.rdoc.exclude << '^ext\/'
53
+ PROJ.rdoc.opts << '-x' << 'ext'
17
54
 
18
- spec = Gem::Specification.new do |s|
19
- s.name = GEM
20
- s.version = GEM_VERSION
21
- s.platform = Gem::Platform::RUBY
22
- s.has_rdoc = true
23
- s.extra_rdoc_files = ["README", "LICENSE"]
24
- s.summary = SUMMARY
25
- s.description = s.summary
26
- s.author = AUTHOR
27
- s.email = EMAIL
28
- s.homepage = HOMEPAGE
29
- s.rubyforge_project = 'ffi'
30
- s.extensions = %w(ext/extconf.rb gen/Rakefile)
31
-
32
- s.require_path = 'lib'
33
- s.autorequire = GEM
34
- s.files = %w(LICENSE README Rakefile) + Dir.glob("{ext,lib,nbproject,samples,specs}/**/*")
35
- end
36
55
  TEST_DEPS = [ LIBTEST ]
37
56
  if RUBY_PLATFORM == "java"
38
57
  desc "Run all specs"
39
58
  task :specs => TEST_DEPS do
40
- sh %{#{Gem.ruby} -S spec #{Dir["specs/**/*_spec.rb"].join(" ")} -fs --color}
59
+ sh %{#{Gem.ruby} -S spec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
41
60
  end
42
61
  desc "Run rubinius specs"
43
62
  task :rbxspecs => TEST_DEPS do
44
- sh %{#{Gem.ruby} -S spec #{Dir["specs/rbx/**/*_spec.rb"].join(" ")} -fs --color}
63
+ sh %{#{Gem.ruby} -S spec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
45
64
  end
46
65
  else
47
66
  TEST_DEPS.unshift :compile
48
67
  desc "Run all specs"
49
68
  task :specs => TEST_DEPS do
50
69
  ENV["MRI_FFI"] = "1"
51
- sh %{#{Gem.ruby} -Ibuild -Ilib -S spec #{Dir["specs/**/*_spec.rb"].join(" ")} -fs --color}
70
+ sh %{#{Gem.ruby} -Ilib -I#{BUILD_DIR} -S spec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
52
71
  end
53
72
  desc "Run rubinius specs"
54
73
  task :rbxspecs => TEST_DEPS do
55
74
  ENV["MRI_FFI"] = "1"
56
- sh %{#{Gem.ruby} -Ibuild -Ilib -S spec #{Dir["specs/rbx/**/*_spec.rb"].join(" ")} -fs --color}
75
+ sh %{#{Gem.ruby} -Ilib -I#{BUILD_DIR} -S spec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
57
76
  end
58
77
  end
59
78
 
60
- Rake::GemPackageTask.new(spec) do |pkg|
61
- pkg.gem_spec = spec
62
- end
79
+ desc "Build all packages"
80
+ task :package => 'gem:package'
63
81
 
64
- desc "install the gem locally"
65
- task :install => [:package] do
66
- sh %{sudo #{Gem.ruby} -S gem install pkg/#{GEM}-#{GEM_VERSION}}
67
- end
82
+ desc "Install the gem locally"
83
+ task :install => 'gem:install'
68
84
 
69
- desc "create a gemspec file"
70
- task :make_spec do
71
- File.open("#{GEM}.gemspec", "w") do |file|
72
- file.puts spec.to_ruby
85
+ unless USE_RAKE_COMPILER
86
+ file "#{BUILD_DIR}/Makefile" do
87
+ FileUtils.mkdir_p(BUILD_DIR) unless File.directory?(BUILD_DIR)
88
+ sh %{cd "#{BUILD_DIR}" && #{Gem.ruby} #{Dir.pwd}/ext/ffi_c/extconf.rb}
89
+ end
90
+ desc "Compile the native module"
91
+ task :compile => "#{BUILD_DIR}/Makefile" do
92
+ sh %{cd "#{BUILD_DIR}"; make}
73
93
  end
74
- end
75
- file "build/Makefile" do
76
- FileUtils.mkdir_p("build") unless File.directory?("build")
77
- sh %{cd build && #{Gem.ruby} ../ext/extconf.rb}
78
- end
79
- desc "Compile the native module"
80
- task :compile => "build/Makefile" do
81
- sh %{cd build; make}
82
94
  end
83
95
  desc "Clean all built files"
84
96
  task :clean do
85
- sh %{cd build;make distclean} if File.exists?("build/Makefile")
86
97
  FileUtils.rm_rf("build")
87
98
  FileUtils.rm_rf("conftest.dSYM")
88
99
  FileUtils.rm_f(Dir["pkg/*.gem"])
89
- FileUtils.rm_f("Makefile")
90
100
  end
91
101
  task "build/libtest.#{LIBEXT}" do
92
102
  sh %{#{GMAKE} -f libtest/GNUmakefile}
93
103
  end
94
-
104
+ desc "Build test helper lib"
105
+ task :libtest => "build/libtest.#{LIBEXT}"
95
106
  desc "Test the extension"
96
107
  task :test => [ :specs, :rbxspecs ] do
97
-
98
108
  end
99
109
  namespace :bench do
100
110
  ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
101
- bench_libs = "-Ibuild -Ilib" unless RUBY_PLATFORM == "java"
111
+ bench_libs = "-Ilib -I#{BUILD_DIR}" unless RUBY_PLATFORM == "java"
102
112
  bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench_helper.rb" }
103
113
  bench_files.each do |bench|
104
114
  task File.basename(bench, ".rb")[6..-1] => TEST_DEPS do
@@ -110,4 +120,4 @@ namespace :bench do
110
120
  sh %{#{Gem.ruby} #{bench_libs} #{bench}}
111
121
  end
112
122
  end
113
- end
123
+ end
@@ -7,6 +7,7 @@
7
7
  #include "compat.h"
8
8
  #include "AbstractMemory.h"
9
9
  #include "Pointer.h"
10
+ #include "Callback.h"
10
11
 
11
12
  static VALUE memory_put_float32(VALUE self, VALUE offset, VALUE value);
12
13
  static VALUE memory_get_float32(VALUE self, VALUE offset);
@@ -15,23 +16,18 @@ static VALUE memory_get_float64(VALUE self, VALUE offset);
15
16
  static VALUE memory_put_pointer(VALUE self, VALUE offset, VALUE value);
16
17
  static VALUE memory_get_pointer(VALUE self, VALUE offset);
17
18
 
18
- static inline caddr_t memory_address(VALUE self);
19
+ static inline char* memory_address(VALUE self);
19
20
  VALUE rb_FFI_AbstractMemory_class = Qnil;
20
21
  static VALUE classMemory = Qnil;
21
22
  static ID to_ptr = 0;
22
23
 
23
- #define ADDRESS(self, offset) (memory_address((self)) + NUM2ULONG(offset))
24
- #ifndef RARRAY_LEN
25
- # define RARRAY_LEN(ary) RARRAY(ary)->len
26
- #endif
27
-
28
24
  #define NUM_OP(name, type, toNative, fromNative) \
29
25
  static VALUE memory_put_##name(VALUE self, VALUE offset, VALUE value); \
30
26
  static VALUE \
31
27
  memory_put_##name(VALUE self, VALUE offset, VALUE value) \
32
28
  { \
33
29
  long off = NUM2LONG(offset); \
34
- AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
30
+ AbstractMemory* memory = MEMORY(self); \
35
31
  type tmp = (type) toNative(value); \
36
32
  checkBounds(memory, off, sizeof(type)); \
37
33
  memcpy(memory->address + off, &tmp, sizeof(tmp)); \
@@ -42,7 +38,7 @@ static VALUE \
42
38
  memory_get_##name(VALUE self, VALUE offset) \
43
39
  { \
44
40
  long off = NUM2LONG(offset); \
45
- AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
41
+ AbstractMemory* memory = MEMORY(self); \
46
42
  type tmp; \
47
43
  checkBounds(memory, off, sizeof(type)); \
48
44
  memcpy(&tmp, memory->address + off, sizeof(tmp)); \
@@ -54,13 +50,12 @@ memory_put_array_of_##name(VALUE self, VALUE offset, VALUE ary) \
54
50
  { \
55
51
  long count = RARRAY_LEN(ary); \
56
52
  long off = NUM2LONG(offset); \
57
- AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
58
- caddr_t address = memory->address; \
53
+ AbstractMemory* memory = MEMORY(self); \
59
54
  long i; \
60
55
  checkBounds(memory, off, count * sizeof(type)); \
61
56
  for (i = 0; i < count; i++) { \
62
- type tmp = (type) toNative(rb_ary_entry(ary, i)); \
63
- memcpy(address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
57
+ type tmp = (type) toNative(RARRAY_PTR(ary)[i]); \
58
+ memcpy(memory->address + off + (i * sizeof(type)), &tmp, sizeof(tmp)); \
64
59
  } \
65
60
  return self; \
66
61
  } \
@@ -70,35 +65,33 @@ memory_get_array_of_##name(VALUE self, VALUE offset, VALUE length) \
70
65
  { \
71
66
  long count = NUM2LONG(length); \
72
67
  long off = NUM2LONG(offset); \
73
- AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self); \
74
- caddr_t address = memory->address; \
75
- long last = off + count; \
68
+ AbstractMemory* memory = MEMORY(self); \
76
69
  long i; \
77
70
  checkBounds(memory, off, count * sizeof(type)); \
78
71
  VALUE retVal = rb_ary_new2(count); \
79
- for (i = off; i < last; ++i) { \
72
+ for (i = 0; i < count; ++i) { \
80
73
  type tmp; \
81
- memcpy(&tmp, address + (i * sizeof(type)), sizeof(tmp)); \
74
+ memcpy(&tmp, memory->address + off + (i * sizeof(type)), sizeof(tmp)); \
82
75
  rb_ary_push(retVal, fromNative(tmp)); \
83
76
  } \
84
77
  return retVal; \
85
78
  }
86
79
 
87
80
  NUM_OP(int8, int8_t, NUM2INT, INT2NUM);
88
- NUM_OP(uint8, u_int8_t, NUM2UINT, UINT2NUM);
81
+ NUM_OP(uint8, uint8_t, NUM2UINT, UINT2NUM);
89
82
  NUM_OP(int16, int16_t, NUM2INT, INT2NUM);
90
- NUM_OP(uint16, u_int16_t, NUM2UINT, UINT2NUM);
83
+ NUM_OP(uint16, uint16_t, NUM2UINT, UINT2NUM);
91
84
  NUM_OP(int32, int32_t, NUM2INT, INT2NUM);
92
- NUM_OP(uint32, u_int32_t, NUM2UINT, UINT2NUM);
85
+ NUM_OP(uint32, uint32_t, NUM2UINT, UINT2NUM);
93
86
  NUM_OP(int64, int64_t, NUM2LL, LL2NUM);
94
- NUM_OP(uint64, u_int64_t, NUM2ULL, ULL2NUM);
87
+ NUM_OP(uint64, uint64_t, NUM2ULL, ULL2NUM);
95
88
  NUM_OP(float32, float, NUM2DBL, rb_float_new);
96
89
  NUM_OP(float64, double, NUM2DBL, rb_float_new);
97
90
 
98
91
  static VALUE
99
92
  memory_put_pointer(VALUE self, VALUE offset, VALUE value)
100
93
  {
101
- AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self);
94
+ AbstractMemory* memory = MEMORY(self);
102
95
  long off = NUM2LONG(offset);
103
96
  const int type = TYPE(value);
104
97
  checkBounds(memory, off, sizeof(void *));
@@ -117,12 +110,8 @@ memory_put_pointer(VALUE self, VALUE offset, VALUE value)
117
110
  memcpy(memory->address + off, &tmp, sizeof(tmp));
118
111
  } else if (rb_respond_to(value, to_ptr)) {
119
112
  VALUE ptr = rb_funcall2(value, to_ptr, 0, NULL);
120
- if (rb_obj_is_kind_of(ptr, rb_FFI_Pointer_class) && TYPE(ptr) == T_DATA) {
121
- void* tmp = memory_address(ptr);
122
- memcpy(memory->address + off, &tmp, sizeof(tmp));
123
- } else {
124
- rb_raise(rb_eArgError, "to_ptr returned an invalid pointer");
125
- }
113
+ void* tmp = MEMORY_PTR(ptr);
114
+ memcpy(memory->address + off, &tmp, sizeof(tmp));
126
115
  } else {
127
116
  rb_raise(rb_eArgError, "value is not a pointer");
128
117
  }
@@ -132,18 +121,36 @@ memory_put_pointer(VALUE self, VALUE offset, VALUE value)
132
121
  static VALUE
133
122
  memory_get_pointer(VALUE self, VALUE offset)
134
123
  {
135
- AbstractMemory* memory = (AbstractMemory *) DATA_PTR(self);
124
+ AbstractMemory* memory = MEMORY(self);
136
125
  long off = NUM2LONG(offset);
137
- caddr_t tmp;
126
+ void* tmp;
138
127
  checkBounds(memory, off, sizeof(tmp));
139
128
  memcpy(&tmp, memory->address + off, sizeof(tmp));
140
129
  return rb_FFI_Pointer_new(tmp);
141
130
  }
142
131
 
132
+ static VALUE
133
+ memory_put_callback(VALUE self, VALUE offset, VALUE proc, VALUE cbInfo)
134
+ {
135
+ AbstractMemory* memory = MEMORY(self);
136
+ long off = NUM2LONG(offset);
137
+ checkBounds(memory, off, sizeof(void *));
138
+
139
+ if (rb_obj_is_kind_of(proc, rb_cProc)) {
140
+ VALUE callback = rb_FFI_NativeCallback_for_proc(proc, cbInfo);
141
+ void* code = ((NativeCallback *) DATA_PTR(callback))->code;
142
+ memcpy(memory->address + off, &code, sizeof(code));
143
+ } else {
144
+ rb_raise(rb_eArgError, "parameter is not a proc");
145
+ }
146
+
147
+ return self;
148
+ }
149
+
143
150
  static VALUE
144
151
  memory_clear(VALUE self)
145
152
  {
146
- AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
153
+ AbstractMemory* ptr = MEMORY(self);
147
154
  memset(ptr->address, 0, ptr->size);
148
155
  return self;
149
156
  }
@@ -151,16 +158,16 @@ memory_clear(VALUE self)
151
158
  static VALUE
152
159
  memory_size(VALUE self)
153
160
  {
154
- return LONG2FIX(((AbstractMemory *) DATA_PTR(self))->size);
161
+ return LONG2FIX((MEMORY(self))->size);
155
162
  }
156
163
 
157
164
  static VALUE
158
165
  memory_get_string(int argc, VALUE* argv, VALUE self)
159
166
  {
160
167
  VALUE length = Qnil, offset = Qnil;
161
- AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
168
+ AbstractMemory* ptr = MEMORY(self);
162
169
  long off, len;
163
- caddr_t end;
170
+ char* end;
164
171
  int nargs = rb_scan_args(argc, argv, "11", &offset, &length);
165
172
 
166
173
  off = NUM2LONG(offset);
@@ -174,7 +181,7 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
174
181
  static VALUE
175
182
  memory_put_string(VALUE self, VALUE offset, VALUE str)
176
183
  {
177
- AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
184
+ AbstractMemory* ptr = MEMORY(self);
178
185
  long off, len;
179
186
 
180
187
  off = NUM2LONG(offset);
@@ -191,7 +198,7 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
191
198
  static VALUE
192
199
  memory_get_bytes(VALUE self, VALUE offset, VALUE length)
193
200
  {
194
- AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
201
+ AbstractMemory* ptr = MEMORY(self);
195
202
  long off, len;
196
203
 
197
204
  off = NUM2LONG(offset);
@@ -203,7 +210,7 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
203
210
  static VALUE
204
211
  memory_put_bytes(int argc, VALUE* argv, VALUE self)
205
212
  {
206
- AbstractMemory* ptr = (AbstractMemory *) DATA_PTR(self);
213
+ AbstractMemory* ptr = MEMORY(self);
207
214
  VALUE offset = Qnil, str = Qnil, rbIndex = Qnil, rbLength = Qnil;
208
215
  long off, len, idx;
209
216
  int nargs = rb_scan_args(argc, argv, "22", &offset, &str, &rbIndex, &rbLength);
@@ -225,10 +232,21 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
225
232
  return self;
226
233
  }
227
234
 
228
- static inline caddr_t
229
- memory_address(VALUE self)
235
+ static inline char*
236
+ memory_address(VALUE obj)
230
237
  {
231
- return ((AbstractMemory *)DATA_PTR((self)))->address;
238
+ return ((AbstractMemory *) DATA_PTR(obj))->address;
239
+ }
240
+
241
+ AbstractMemory*
242
+ rb_FFI_AbstractMemory_cast(VALUE obj, VALUE klass)
243
+ {
244
+ if (rb_obj_is_kind_of(obj, klass)) {
245
+ AbstractMemory* memory;
246
+ Data_Get_Struct(obj, AbstractMemory, memory);
247
+ return memory;
248
+ }
249
+ rb_raise(rb_eArgError, "Invalid Memory object");
232
250
  }
233
251
 
234
252
  void
@@ -280,14 +298,23 @@ rb_FFI_AbstractMemory_Init()
280
298
  }
281
299
  rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
282
300
  rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
301
+ rb_define_alias(classMemory, "put_float", "put_float32");
302
+ rb_define_alias(classMemory, "get_float", "get_float32");
283
303
  rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2);
284
304
  rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2);
305
+ rb_define_alias(classMemory, "put_array_of_float", "put_array_of_float32");
306
+ rb_define_alias(classMemory, "get_array_of_float", "get_array_of_float32");
285
307
  rb_define_method(classMemory, "put_float64", memory_put_float64, 2);
286
308
  rb_define_method(classMemory, "get_float64", memory_get_float64, 1);
309
+ rb_define_alias(classMemory, "put_double", "put_float64");
310
+ rb_define_alias(classMemory, "get_double", "get_float64");
287
311
  rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2);
288
312
  rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2);
313
+ rb_define_alias(classMemory, "put_array_of_double", "put_array_of_float64");
314
+ rb_define_alias(classMemory, "get_array_of_double", "get_array_of_float64");
289
315
  rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2);
290
316
  rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1);
317
+ rb_define_method(classMemory, "put_callback", memory_put_callback, 3);
291
318
  rb_define_method(classMemory, "get_string", memory_get_string, -1);
292
319
  rb_define_method(classMemory, "put_string", memory_put_string, 2);
293
320
  rb_define_method(classMemory, "get_bytes", memory_get_bytes, 2);
@@ -1,21 +1,16 @@
1
- /*
2
- * File: AbstractMemory.h
3
- * Author: wayne
4
- *
5
- * Created on August 28, 2008, 5:52 PM
6
- */
7
-
8
1
  #ifndef _ABSTRACTMEMORY_H
9
2
  #define _ABSTRACTMEMORY_H
10
3
 
4
+ #include <sys/param.h>
11
5
  #include <sys/types.h>
6
+ #include <stdint.h>
12
7
 
13
8
  #ifdef __cplusplus
14
9
  extern "C" {
15
10
  #endif
16
11
 
17
12
  typedef struct {
18
- caddr_t address;
13
+ char* address; // Use char* instead of void* to ensure adding to it works correctly
19
14
  long size;
20
15
  } AbstractMemory;
21
16
 
@@ -28,6 +23,13 @@ checkBounds(AbstractMemory* mem, long off, long len)
28
23
  }
29
24
  }
30
25
 
26
+ #define MEMORY(obj) rb_FFI_AbstractMemory_cast((obj), rb_FFI_AbstractMemory_class)
27
+ #define MEMORY_PTR(obj) MEMORY((obj))->address
28
+ #define MEMORY_LEN(obj) MEMORY((obj))->size
29
+
30
+ extern AbstractMemory* rb_FFI_AbstractMemory_cast(VALUE obj, VALUE klass);
31
+
32
+ extern VALUE rb_FFI_AbstractMemory_class;
31
33
  #ifdef __cplusplus
32
34
  }
33
35
  #endif