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
@@ -9,9 +9,11 @@ extern "C" {
9
9
 
10
10
 
11
11
  extern void rb_FFI_Pointer_Init(void);
12
- extern VALUE rb_FFI_Pointer_new(caddr_t addr);
12
+ extern void rb_FFI_NullPointer_Init();
13
+ extern VALUE rb_FFI_Pointer_new(void* addr);
13
14
  extern VALUE rb_FFI_Pointer_class;
14
-
15
+ extern VALUE rb_FFI_NullPointer_class;
16
+ extern VALUE rb_FFI_NullPointer_singleton;
15
17
 
16
18
  #ifdef __cplusplus
17
19
  }
@@ -0,0 +1,542 @@
1
+ #include <sys/types.h>
2
+ #include <sys/param.h>
3
+ #include <stdint.h>
4
+ #include <stdbool.h>
5
+ #include <ruby.h>
6
+ #include "rbffi.h"
7
+ #include "compat.h"
8
+ #include "AbstractMemory.h"
9
+ #include "Pointer.h"
10
+ #include "MemoryPointer.h"
11
+ #include "Types.h"
12
+ #include "Struct.h"
13
+
14
+ typedef struct StructField {
15
+ unsigned int type;
16
+ unsigned int offset;
17
+ unsigned int size;
18
+ unsigned int align;
19
+ } StructField;
20
+
21
+ typedef struct StructLayout {
22
+ VALUE rbFields;
23
+ unsigned int fieldCount;
24
+ int size;
25
+ int align;
26
+ } StructLayout;
27
+
28
+ typedef struct StructLayoutBuilder {
29
+ unsigned int offset;
30
+ } StructLayoutBuilder;
31
+
32
+ static void struct_field_mark(StructField *);
33
+ static void struct_field_free(StructField *);
34
+ static void struct_mark(Struct *);
35
+ static void struct_free(Struct *);
36
+ static void struct_layout_mark(StructLayout *);
37
+ static void struct_layout_free(StructLayout *);
38
+
39
+ VALUE rb_FFI_Struct_class = Qnil;
40
+ static VALUE classStruct = Qnil, classStructLayout = Qnil;
41
+ static VALUE classStructField = Qnil, classStructLayoutBuilder = Qnil;
42
+ static ID pointerID = 0, layoutID = 0, SIZE_ID, ALIGN_ID;
43
+ static ID getID = 0, putID = 0, to_ptr = 0;
44
+
45
+ #define FIELD_CAST(obj) ((StructField *)((TYPE(obj) == T_DATA && rb_obj_is_kind_of(obj, classStructField)) \
46
+ ? DATA_PTR(obj) : (rb_raise(rb_eArgError, "StructField expected"), NULL)))
47
+
48
+ #define LAYOUT_CAST(obj) ((StructLayout *)((TYPE(obj) == T_DATA && rb_obj_is_kind_of(obj, classStructLayout)) \
49
+ ? DATA_PTR(obj) : (rb_raise(rb_eArgError, "StructLayout expected"), NULL)))
50
+
51
+ static VALUE
52
+ struct_field_allocate(VALUE klass)
53
+ {
54
+ StructField* field;
55
+ return Data_Make_Struct(klass, StructField, struct_field_mark, struct_field_free, field);
56
+ }
57
+
58
+ static VALUE
59
+ struct_field_initialize(int argc, VALUE* argv, VALUE self)
60
+ {
61
+ VALUE offset = Qnil, info = Qnil;
62
+ StructField* field;
63
+ int nargs;
64
+
65
+ Data_Get_Struct(self, StructField, field);
66
+
67
+ nargs = rb_scan_args(argc, argv, "11", &offset, &info);
68
+
69
+ field->offset = NUM2UINT(offset);
70
+ if (rb_const_defined(CLASS_OF(self), rb_intern("TYPE"))) {
71
+ field->type = NUM2UINT(rb_const_get(CLASS_OF(self), rb_intern("TYPE")));
72
+ } else {
73
+ field->type = ~0;
74
+ }
75
+ #ifdef notyet
76
+ field->size = NUM2UINT(rb_const_get(klass, rb_intern("SIZE")));
77
+ field->align = NUM2UINT(rb_const_get(klass, rb_intern("ALIGN")));
78
+ #endif
79
+ rb_iv_set(self, "@off", offset);
80
+ rb_iv_set(self, "@info", info);
81
+ return self;
82
+ }
83
+
84
+ static VALUE
85
+ struct_field_offset(VALUE self)
86
+ {
87
+ StructField* field;
88
+ Data_Get_Struct(self, StructField, field);
89
+ return UINT2NUM(field->offset);
90
+ }
91
+
92
+ static void
93
+ struct_field_mark(StructField *f)
94
+ {
95
+ }
96
+ static void
97
+ struct_field_free(StructField *f)
98
+ {
99
+ if (f != NULL) {
100
+ xfree(f);
101
+ }
102
+ }
103
+
104
+ static inline char*
105
+ memory_address(VALUE self)
106
+ {
107
+ return ((AbstractMemory *)DATA_PTR((self)))->address;
108
+ }
109
+
110
+ static inline char*
111
+ pointer_native(VALUE value)
112
+ {
113
+ const int type = TYPE(value);
114
+
115
+ if (rb_obj_is_kind_of(value, rb_FFI_Pointer_class) && type == T_DATA) {
116
+ return memory_address(value);
117
+ } else if (type == T_NIL) {
118
+ return NULL;
119
+ } else if (type == T_FIXNUM) {
120
+ return (char *)(uintptr_t) FIX2INT(value);
121
+ } else if (type == T_BIGNUM) {
122
+ return (char *)(uintptr_t) NUM2ULL(value);
123
+ } else if (rb_respond_to(value, to_ptr)) {
124
+ VALUE ptr = rb_funcall2(value, to_ptr, 0, NULL);
125
+ if (rb_obj_is_kind_of(ptr, rb_FFI_Pointer_class) && TYPE(ptr) == T_DATA) {
126
+ return memory_address(ptr);
127
+ } else {
128
+ rb_raise(rb_eArgError, "to_ptr returned an invalid pointer");
129
+ }
130
+ } else {
131
+ rb_raise(rb_eArgError, "value is not a pointer");
132
+ }
133
+ }
134
+
135
+ static inline VALUE
136
+ pointer_new(char* value)
137
+ {
138
+ return rb_FFI_Pointer_new(value);
139
+ }
140
+
141
+ static inline char*
142
+ string_to_native(VALUE value)
143
+ {
144
+ rb_raise(rb_eArgError, "Cannot set :string fields");
145
+ }
146
+
147
+ static inline VALUE
148
+ string_from_native(char* value)
149
+ {
150
+ return value != NULL ? rb_tainted_str_new2(value) : Qnil;
151
+ }
152
+
153
+ #define FIELD_OP(name, type, toNative, fromNative) \
154
+ static VALUE struct_field_put_##name(VALUE self, VALUE pointer, VALUE value); \
155
+ static inline void ptr_put_##name(AbstractMemory* ptr, StructField* field, VALUE value); \
156
+ static inline VALUE ptr_get_##name(AbstractMemory* ptr, StructField* field); \
157
+ static inline void \
158
+ ptr_put_##name(AbstractMemory* ptr, StructField* field, VALUE value) \
159
+ { \
160
+ type tmp = toNative(value); \
161
+ memcpy(ptr->address + field->offset, &tmp, sizeof(tmp)); \
162
+ } \
163
+ static inline VALUE \
164
+ ptr_get_##name(AbstractMemory* ptr, StructField* field) \
165
+ { \
166
+ type tmp; \
167
+ memcpy(&tmp, ptr->address + field->offset, sizeof(tmp)); \
168
+ return fromNative(tmp); \
169
+ } \
170
+ static VALUE \
171
+ struct_field_put_##name(VALUE self, VALUE pointer, VALUE value) \
172
+ { \
173
+ StructField* f; Data_Get_Struct(self, StructField, f); \
174
+ ptr_put_##name(MEMORY(pointer), f, value); \
175
+ return self; \
176
+ } \
177
+ static VALUE struct_field_get_##name(VALUE self, VALUE pointer); \
178
+ static VALUE \
179
+ struct_field_get_##name(VALUE self, VALUE pointer) \
180
+ { \
181
+ StructField* f; Data_Get_Struct(self, StructField, f); \
182
+ return ptr_get_##name(MEMORY(pointer), f); \
183
+ }
184
+
185
+ FIELD_OP(int8, int8_t, NUM2INT, INT2NUM);
186
+ FIELD_OP(uint8, uint8_t, NUM2UINT, UINT2NUM);
187
+ FIELD_OP(int16, int16_t, NUM2INT, INT2NUM);
188
+ FIELD_OP(uint16, uint16_t, NUM2UINT, UINT2NUM);
189
+ FIELD_OP(int32, int32_t, NUM2INT, INT2NUM);
190
+ FIELD_OP(uint32, uint32_t, NUM2UINT, UINT2NUM);
191
+ FIELD_OP(int64, int64_t, NUM2LL, LL2NUM);
192
+ FIELD_OP(uint64, uint64_t, NUM2ULL, ULL2NUM);
193
+ FIELD_OP(float32, float, NUM2DBL, rb_float_new);
194
+ FIELD_OP(float64, double, NUM2DBL, rb_float_new);
195
+ FIELD_OP(pointer, char*, pointer_native, pointer_new);
196
+ FIELD_OP(string, char*, string_to_native, string_from_native);
197
+
198
+ static VALUE
199
+ struct_allocate(VALUE klass)
200
+ {
201
+ Struct* s;
202
+ VALUE retval = Data_Make_Struct(klass, Struct, struct_mark, struct_free, s);
203
+
204
+ s->rbPointer = Qnil;
205
+ s->pointer = NULL;
206
+ s->rbLayout = Qnil;
207
+ s->layout = NULL;
208
+
209
+ if (rb_cvar_defined(klass, layoutID)) {
210
+ s->rbLayout = rb_cvar_get(klass, layoutID);
211
+ Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
212
+ }
213
+ return retval;
214
+ }
215
+
216
+ static VALUE
217
+ struct_initialize(int argc, VALUE* argv, VALUE self)
218
+ {
219
+ Struct* s;
220
+ VALUE rbPointer = Qnil, rest = Qnil;
221
+ int nargs;
222
+
223
+ Data_Get_Struct(self, Struct, s);
224
+
225
+ nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest);
226
+
227
+ /* Call up into ruby code to adjust the layout */
228
+ if (nargs > 1) {
229
+ s->rbLayout = rb_funcall2(CLASS_OF(self), rb_intern("layout"), RARRAY_LEN(rest), RARRAY_PTR(rest));
230
+ if (!rb_obj_is_kind_of(s->rbLayout, classStructLayout)) {
231
+ rb_raise(rb_eRuntimeError, "Invalid Struct layout");
232
+ }
233
+
234
+ Data_Get_Struct(s->rbLayout, StructLayout, s->layout);
235
+ }
236
+
237
+ if (rbPointer == Qnil) {
238
+ rbPointer = rb_FFI_MemoryPointer_new(s->layout->size, 1, true);
239
+ }
240
+
241
+ s->rbPointer = rbPointer;
242
+ s->pointer = MEMORY(rbPointer);
243
+
244
+ return self;
245
+ }
246
+
247
+ static void
248
+ struct_mark(Struct *s)
249
+ {
250
+ if (s->rbPointer != Qnil) {
251
+ rb_gc_mark(s->rbPointer);
252
+ }
253
+ if (s->rbLayout != Qnil) {
254
+ rb_gc_mark(s->rbLayout);
255
+ }
256
+ }
257
+
258
+ static void struct_free(Struct *s)
259
+ {
260
+ xfree(s);
261
+ }
262
+
263
+ static VALUE
264
+ struct_field(Struct* s, VALUE fieldName)
265
+ {
266
+ StructLayout* layout = s->layout;
267
+ VALUE rbField;
268
+ if (layout == NULL) {
269
+ rb_raise(rb_eRuntimeError, "layout not set for Struct");
270
+ }
271
+ rbField = rb_hash_aref(layout->rbFields, fieldName);
272
+ if (rbField == Qnil) {
273
+ VALUE str = rb_funcall2(fieldName, rb_intern("to_s"), 0, NULL);
274
+ rb_raise(rb_eArgError, "No such field '%s'", StringValuePtr(str));
275
+ }
276
+ return rbField;
277
+ }
278
+
279
+ static VALUE
280
+ struct_get_field(VALUE self, VALUE fieldName)
281
+ {
282
+ Struct* s;
283
+ VALUE rbField;
284
+ StructField* f;
285
+
286
+ Data_Get_Struct(self, Struct, s);
287
+ rbField = struct_field(s, fieldName);
288
+ f = FIELD_CAST(rbField);
289
+
290
+ switch (f->type) {
291
+ case NATIVE_INT8:
292
+ return ptr_get_int8(s->pointer, f);
293
+ case NATIVE_UINT8:
294
+ return ptr_get_uint8(s->pointer, f);
295
+ case NATIVE_INT16:
296
+ return ptr_get_int16(s->pointer, f);
297
+ case NATIVE_UINT16:
298
+ return ptr_get_uint16(s->pointer, f);
299
+ case NATIVE_INT32:
300
+ return ptr_get_int32(s->pointer, f);
301
+ case NATIVE_UINT32:
302
+ return ptr_get_uint32(s->pointer, f);
303
+ case NATIVE_INT64:
304
+ return ptr_get_int64(s->pointer, f);
305
+ case NATIVE_UINT64:
306
+ return ptr_get_uint64(s->pointer, f);
307
+ case NATIVE_FLOAT32:
308
+ return ptr_get_float32(s->pointer, f);
309
+ case NATIVE_FLOAT64:
310
+ return ptr_get_float64(s->pointer, f);
311
+ case NATIVE_POINTER:
312
+ return ptr_get_pointer(s->pointer, f);
313
+ case NATIVE_STRING:
314
+ return ptr_get_string(s->pointer, f);
315
+ default:
316
+ /* call up to the ruby code to fetch the value */
317
+ return rb_funcall2(rbField, getID, 1, &s->rbPointer);
318
+ }
319
+ }
320
+
321
+ static VALUE
322
+ struct_put_field(VALUE self, VALUE fieldName, VALUE value)
323
+ {
324
+ Struct* s;
325
+ VALUE rbField;
326
+ StructField* f;
327
+ VALUE argv[2];
328
+
329
+ Data_Get_Struct(self, Struct, s);
330
+ rbField = struct_field(s, fieldName);
331
+ f = FIELD_CAST(rbField);
332
+
333
+ switch (f->type) {
334
+ case NATIVE_INT8:
335
+ ptr_put_int8(s->pointer, f, value);
336
+ break;
337
+ case NATIVE_UINT8:
338
+ ptr_put_uint8(s->pointer, f, value);
339
+ break;
340
+ case NATIVE_INT16:
341
+ ptr_put_int16(s->pointer, f, value);
342
+ break;
343
+ case NATIVE_UINT16:
344
+ ptr_put_uint16(s->pointer, f, value);
345
+ break;
346
+ case NATIVE_INT32:
347
+ ptr_put_int32(s->pointer, f, value);
348
+ break;
349
+ case NATIVE_UINT32:
350
+ ptr_put_uint32(s->pointer, f, value);
351
+ break;
352
+ case NATIVE_INT64:
353
+ ptr_put_int64(s->pointer, f, value);
354
+ break;
355
+ case NATIVE_UINT64:
356
+ ptr_put_uint64(s->pointer, f, value);
357
+ break;
358
+ case NATIVE_FLOAT32:
359
+ ptr_put_float32(s->pointer, f, value);
360
+ break;
361
+ case NATIVE_FLOAT64:
362
+ ptr_put_float64(s->pointer, f, value);
363
+ break;
364
+ case NATIVE_POINTER:
365
+ ptr_put_pointer(s->pointer, f, value);
366
+ break;
367
+ case NATIVE_STRING:
368
+ rb_raise(rb_eArgError, "Cannot set :string fields");
369
+ default:
370
+ /* call up to the ruby code to set the value */
371
+ argv[0] = s->rbPointer;
372
+ argv[1] = value;
373
+ rb_funcall2(rbField, putID, 2, argv);
374
+ break;
375
+ }
376
+ return self;
377
+ }
378
+
379
+ static VALUE
380
+ struct_set_pointer(VALUE self, VALUE pointer)
381
+ {
382
+ Struct* s;
383
+
384
+ if (!rb_obj_is_kind_of(pointer, rb_FFI_AbstractMemory_class)) {
385
+ rb_raise(rb_eArgError, "Invalid pointer");
386
+ }
387
+
388
+ Data_Get_Struct(self, Struct, s);
389
+ s->pointer = MEMORY(pointer);
390
+ s->rbPointer = pointer;
391
+ rb_ivar_set(self, pointerID, pointer);
392
+ return self;
393
+ }
394
+
395
+ static VALUE
396
+ struct_get_pointer(VALUE self)
397
+ {
398
+ Struct* s;
399
+ Data_Get_Struct(self, Struct, s);
400
+ return s->rbPointer;
401
+ }
402
+
403
+ static VALUE
404
+ struct_set_layout(VALUE self, VALUE layout)
405
+ {
406
+ Struct* s;
407
+ Data_Get_Struct(self, Struct, s);
408
+
409
+ if (!rb_obj_is_kind_of(layout, classStructLayout)) {
410
+ rb_raise(rb_eArgError, "Invalid Struct layout");
411
+ }
412
+ Data_Get_Struct(layout, StructLayout, s->layout);
413
+ rb_ivar_set(self, layoutID, layout);
414
+ return self;
415
+ }
416
+
417
+ static VALUE
418
+ struct_get_layout(VALUE self)
419
+ {
420
+ Struct* s;
421
+ Data_Get_Struct(self, Struct, s);
422
+
423
+ return s->rbLayout;
424
+ }
425
+
426
+ static VALUE
427
+ struct_layout_allocate(VALUE klass)
428
+ {
429
+ StructLayout* layout;
430
+ return Data_Make_Struct(klass, StructLayout, struct_layout_mark, struct_layout_free, layout);
431
+ }
432
+
433
+ static VALUE
434
+ struct_layout_initialize(VALUE self, VALUE field_names, VALUE fields, VALUE size, VALUE align)
435
+ {
436
+ StructLayout* layout;
437
+
438
+ Data_Get_Struct(self, StructLayout, layout);
439
+ layout->rbFields = fields;
440
+ layout->size = NUM2INT(size);
441
+ layout->align = NUM2INT(align);
442
+
443
+ rb_iv_set(self, "@field_names", field_names);
444
+ rb_iv_set(self, "@fields", fields);
445
+ rb_iv_set(self, "@size", size);
446
+ rb_iv_set(self, "@align", align);
447
+
448
+ return self;
449
+ }
450
+
451
+ static VALUE
452
+ struct_layout_aref(VALUE self, VALUE field)
453
+ {
454
+ StructLayout* layout;
455
+
456
+ Data_Get_Struct(self, StructLayout, layout);
457
+ return rb_hash_aref(layout->rbFields, field);
458
+ }
459
+
460
+
461
+ static void
462
+ struct_layout_mark(StructLayout *layout)
463
+ {
464
+ if (layout->rbFields != Qnil) {
465
+ rb_gc_mark(layout->rbFields);
466
+ }
467
+ }
468
+
469
+ static void
470
+ struct_layout_free(StructLayout *layout)
471
+ {
472
+ xfree(layout);
473
+ }
474
+
475
+ void
476
+ rb_FFI_Struct_Init()
477
+ {
478
+ VALUE moduleFFI = rb_define_module("FFI");
479
+ VALUE klass;
480
+ rb_FFI_Struct_class = classStruct = rb_define_class_under(moduleFFI, "Struct", rb_cObject);
481
+ classStructLayout = rb_define_class_under(moduleFFI, "StructLayout", rb_cObject);
482
+ classStructLayoutBuilder = rb_define_class_under(moduleFFI, "StructLayoutBuilder", rb_cObject);
483
+ classStructField = rb_define_class_under(classStructLayoutBuilder, "Field", rb_cObject);
484
+
485
+ rb_define_alloc_func(classStruct, struct_allocate);
486
+ rb_define_method(classStruct, "initialize", struct_initialize, -1);
487
+
488
+ rb_define_alias(rb_singleton_class(classStruct), "alloc_in", "new");
489
+ rb_define_alias(rb_singleton_class(classStruct), "alloc_out", "new");
490
+ rb_define_alias(rb_singleton_class(classStruct), "alloc_inout", "new");
491
+ rb_define_alias(rb_singleton_class(classStruct), "new_in", "new");
492
+ rb_define_alias(rb_singleton_class(classStruct), "new_out", "new");
493
+ rb_define_alias(rb_singleton_class(classStruct), "new_inout", "new");
494
+
495
+ rb_define_method(classStruct, "pointer", struct_get_pointer, 0);
496
+ rb_define_private_method(classStruct, "pointer=", struct_set_pointer, 1);
497
+
498
+ rb_define_method(classStruct, "layout", struct_get_layout, 0);
499
+ rb_define_private_method(classStruct, "layout=", struct_set_layout, 1);
500
+
501
+ rb_define_method(classStruct, "[]", struct_get_field, 1);
502
+ rb_define_method(classStruct, "[]=", struct_put_field, 2);
503
+
504
+ rb_define_alloc_func(classStructField, struct_field_allocate);
505
+ rb_define_method(classStructField, "initialize", struct_field_initialize, -1);
506
+ rb_define_method(classStructField, "offset", struct_field_offset, 0);
507
+
508
+ rb_define_alloc_func(classStructLayout, struct_layout_allocate);
509
+ rb_define_method(classStructLayout, "initialize", struct_layout_initialize, 4);
510
+ rb_define_method(classStructLayout, "[]", struct_layout_aref, 1);
511
+
512
+ pointerID = rb_intern("@pointer");
513
+ layoutID = rb_intern("@layout");
514
+ getID = rb_intern("get");
515
+ putID = rb_intern("put");
516
+ to_ptr = rb_intern("to_ptr");
517
+ SIZE_ID = rb_intern("SIZE");
518
+ ALIGN_ID = rb_intern("ALIGN");
519
+ #undef FIELD
520
+ #define FIELD(name, typeName, nativeType, T) do { \
521
+ typedef struct { char c; T v; } s; \
522
+ klass = rb_define_class_under(classStructLayoutBuilder, #name, classStructField); \
523
+ rb_define_method(klass, "put", struct_field_put_##typeName, 2); \
524
+ rb_define_method(klass, "get", struct_field_get_##typeName, 1); \
525
+ rb_define_const(klass, "ALIGN", INT2NUM((sizeof(s) - sizeof(T)) * 8)); \
526
+ rb_define_const(klass, "SIZE", INT2NUM(sizeof(T)* 8)); \
527
+ rb_define_const(klass, "TYPE", INT2NUM(nativeType)); \
528
+ } while(0)
529
+
530
+ FIELD(Signed8, int8, NATIVE_INT8, char);
531
+ FIELD(Unsigned8, uint8, NATIVE_UINT8, unsigned char);
532
+ FIELD(Signed16, int16, NATIVE_INT16, short);
533
+ FIELD(Unsigned16, uint16, NATIVE_UINT16, unsigned short);
534
+ FIELD(Signed32, int32, NATIVE_INT32, int);
535
+ FIELD(Unsigned32, uint32, NATIVE_UINT32, unsigned int);
536
+ FIELD(Signed64, int64, NATIVE_INT64, long long);
537
+ FIELD(Unsigned64, uint64, NATIVE_UINT64, unsigned long long);
538
+ FIELD(FloatField, float32, NATIVE_FLOAT32, float);
539
+ FIELD(DoubleField, float64, NATIVE_FLOAT64, double);
540
+ FIELD(PointerField, pointer, NATIVE_POINTER, char *);
541
+ FIELD(StringField, string, NATIVE_STRING, char *);
542
+ }