ffi 1.0.9-x86-mingw32 → 1.0.12.pre-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (218) hide show
  1. data/Rakefile +16 -16
  2. data/ext/ffi_c/AbstractMemory.c +376 -14
  3. data/ext/ffi_c/AbstractMemory.h +8 -0
  4. data/ext/ffi_c/ArrayType.c +28 -0
  5. data/ext/ffi_c/Buffer.c +109 -25
  6. data/ext/ffi_c/Call.c +16 -5
  7. data/ext/ffi_c/ClosurePool.c +21 -8
  8. data/ext/ffi_c/DataConverter.c +29 -0
  9. data/ext/ffi_c/DynamicLibrary.c +71 -2
  10. data/ext/ffi_c/Function.c +122 -11
  11. data/ext/ffi_c/Function.h +6 -0
  12. data/ext/ffi_c/FunctionInfo.c +21 -1
  13. data/ext/ffi_c/LastError.c +24 -0
  14. data/ext/ffi_c/MappedType.c +22 -0
  15. data/ext/ffi_c/MemoryPointer.c +19 -1
  16. data/ext/ffi_c/MemoryPointer.h +6 -0
  17. data/ext/ffi_c/MethodHandle.c +26 -11
  18. data/ext/ffi_c/Platform.c +17 -3
  19. data/ext/ffi_c/Pointer.c +106 -0
  20. data/ext/ffi_c/Pointer.h +6 -0
  21. data/ext/ffi_c/Struct.c +10 -4
  22. data/ext/ffi_c/Struct.h +2 -1
  23. data/ext/ffi_c/StructByReference.c +8 -0
  24. data/ext/ffi_c/StructByValue.c +8 -0
  25. data/ext/ffi_c/StructLayout.c +8 -2
  26. data/ext/ffi_c/Thread.c +131 -1
  27. data/ext/ffi_c/Thread.h +6 -0
  28. data/ext/ffi_c/Type.c +111 -17
  29. data/ext/ffi_c/Types.c +9 -2
  30. data/ext/ffi_c/Types.h +4 -0
  31. data/ext/ffi_c/Variadic.c +13 -4
  32. data/ext/ffi_c/compat.h +8 -0
  33. data/ext/ffi_c/endian.h +10 -1
  34. data/ext/ffi_c/extconf.rb +51 -35
  35. data/ext/ffi_c/ffi.c +5 -0
  36. data/ext/ffi_c/libffi.darwin.mk +15 -15
  37. data/ext/ffi_c/libffi.gnu.mk +3 -3
  38. data/ext/ffi_c/libffi.mk +4 -4
  39. data/ext/ffi_c/libffi.vc.mk +26 -0
  40. data/ext/ffi_c/libffi.vc64.mk +26 -0
  41. data/ext/ffi_c/libffi/ChangeLog +541 -0
  42. data/ext/ffi_c/libffi/ChangeLog.libffi +13 -87
  43. data/ext/ffi_c/libffi/LICENSE +3 -3
  44. data/ext/ffi_c/libffi/Makefile.am +41 -32
  45. data/ext/ffi_c/libffi/Makefile.in +95 -66
  46. data/ext/ffi_c/libffi/Makefile.vc +141 -0
  47. data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
  48. data/ext/ffi_c/libffi/README +40 -4
  49. data/ext/ffi_c/libffi/aclocal.m4 +729 -7854
  50. data/ext/ffi_c/libffi/build-ios.sh +67 -0
  51. data/ext/ffi_c/libffi/compile +11 -10
  52. data/ext/ffi_c/libffi/config.guess +4 -1
  53. data/ext/ffi_c/libffi/config.sub +6 -3
  54. data/ext/ffi_c/libffi/configure +6264 -6354
  55. data/ext/ffi_c/libffi/configure.ac +155 -63
  56. data/ext/ffi_c/libffi/depcomp +81 -35
  57. data/ext/ffi_c/libffi/doc/libffi.info +78 -18
  58. data/ext/ffi_c/libffi/doc/libffi.texi +64 -5
  59. data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
  60. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  61. data/ext/ffi_c/libffi/fficonfig.h.in +18 -0
  62. data/ext/ffi_c/libffi/fficonfig.hw +57 -0
  63. data/ext/ffi_c/libffi/include/Makefile.in +21 -3
  64. data/ext/ffi_c/libffi/include/ffi.h.in +42 -14
  65. data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
  66. data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
  67. data/ext/ffi_c/libffi/include/ffi_common.h +9 -5
  68. data/ext/ffi_c/libffi/install-sh +364 -167
  69. data/ext/ffi_c/libffi/ltmain.sh +2599 -1369
  70. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
  71. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
  72. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
  73. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
  74. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  75. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
  76. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
  77. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
  78. data/ext/ffi_c/libffi/m4/libtool.m4 +1239 -768
  79. data/ext/ffi_c/libffi/m4/ltoptions.m4 +7 -6
  80. data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
  81. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +9 -3
  82. data/ext/ffi_c/libffi/man/Makefile.in +21 -3
  83. data/ext/ffi_c/libffi/mdate-sh +0 -0
  84. data/ext/ffi_c/libffi/missing +60 -44
  85. data/ext/ffi_c/libffi/msvcc.sh +197 -0
  86. data/ext/ffi_c/libffi/src/alpha/osf.S +39 -18
  87. data/ext/ffi_c/libffi/src/arm/ffi.c +443 -24
  88. data/ext/ffi_c/libffi/src/arm/ffitarget.h +17 -1
  89. data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
  90. data/ext/ffi_c/libffi/src/arm/sysv.S +206 -15
  91. data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
  92. data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
  93. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +2 -2
  94. data/ext/ffi_c/libffi/src/closures.c +17 -35
  95. data/ext/ffi_c/libffi/src/cris/ffi.c +1 -1
  96. data/ext/ffi_c/libffi/src/cris/ffitarget.h +2 -2
  97. data/ext/ffi_c/libffi/src/dlmalloc.c +66 -4
  98. data/ext/ffi_c/libffi/src/frv/ffitarget.h +2 -6
  99. data/ext/ffi_c/libffi/src/ia64/ffi.c +7 -5
  100. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +2 -2
  101. data/ext/ffi_c/libffi/src/java_raw_api.c +1 -1
  102. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +2 -2
  103. data/ext/ffi_c/libffi/src/m68k/ffi.c +10 -0
  104. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +2 -2
  105. data/ext/ffi_c/libffi/src/m68k/sysv.S +36 -0
  106. data/ext/ffi_c/libffi/src/mips/ffi.c +12 -5
  107. data/ext/ffi_c/libffi/src/mips/ffitarget.h +18 -11
  108. data/ext/ffi_c/libffi/src/mips/n32.S +4 -4
  109. data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
  110. data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
  111. data/ext/ffi_c/libffi/src/pa/ffi.c +7 -4
  112. data/ext/ffi_c/libffi/src/pa/ffitarget.h +6 -5
  113. data/ext/ffi_c/libffi/src/powerpc/aix.S +5 -1
  114. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +2 -0
  115. data/ext/ffi_c/libffi/src/powerpc/asm.h +1 -1
  116. data/ext/ffi_c/libffi/src/powerpc/darwin.S +215 -77
  117. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +358 -100
  118. data/ext/ffi_c/libffi/src/powerpc/ffi.c +11 -5
  119. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +603 -172
  120. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +17 -4
  121. data/ext/ffi_c/libffi/src/prep_cif.c +16 -13
  122. data/ext/ffi_c/libffi/src/s390/ffitarget.h +4 -2
  123. data/ext/ffi_c/libffi/src/sh/ffitarget.h +2 -2
  124. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +2 -2
  125. data/ext/ffi_c/libffi/src/sparc/ffi.c +55 -11
  126. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +5 -3
  127. data/ext/ffi_c/libffi/src/x86/ffi.c +54 -92
  128. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  129. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -14
  130. data/ext/ffi_c/libffi/src/x86/sysv.S +40 -26
  131. data/ext/ffi_c/libffi/src/x86/unix64.S +4 -0
  132. data/ext/ffi_c/libffi/src/x86/win32.S +379 -191
  133. data/ext/ffi_c/libffi/src/x86/win64.S +15 -7
  134. data/ext/ffi_c/libffi/testsuite/Makefile.am +1 -1
  135. data/ext/ffi_c/libffi/testsuite/Makefile.in +22 -4
  136. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
  137. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +1 -5
  138. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +1 -1
  139. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +1 -1
  140. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +1 -0
  141. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +1 -0
  142. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +3 -0
  143. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +2 -2
  144. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +3 -0
  145. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
  146. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +1 -1
  147. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +1 -0
  148. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +2 -3
  149. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -1
  150. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +36 -0
  151. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +17 -17
  152. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -0
  153. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +1 -0
  154. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +1 -1
  155. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +1 -3
  156. data/ext/ffi_c/win32/stdint.h +199 -0
  157. data/gen/Rakefile +18 -2
  158. data/lib/1.8/ffi_c.so +0 -0
  159. data/lib/ffi.rb +13 -9
  160. data/lib/ffi/autopointer.rb +88 -26
  161. data/lib/ffi/enum.rb +42 -0
  162. data/lib/ffi/errno.rb +6 -1
  163. data/lib/ffi/ffi.rb +1 -0
  164. data/lib/ffi/io.rb +13 -2
  165. data/lib/ffi/library.rb +219 -24
  166. data/lib/ffi/memorypointer.rb +1 -33
  167. data/lib/ffi/platform.rb +21 -7
  168. data/lib/ffi/platform/arm-linux/types.conf +102 -0
  169. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  170. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  171. data/lib/ffi/platform/i486-gnu/types.conf +107 -0
  172. data/lib/ffi/platform/ia64-linux/types.conf +102 -0
  173. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  174. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  175. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  176. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  177. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  178. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  179. data/lib/ffi/platform/x86_64-freebsd/types.conf +126 -0
  180. data/lib/ffi/platform/x86_64-netbsd/types.conf +126 -0
  181. data/lib/ffi/pointer.rb +44 -0
  182. data/lib/ffi/struct.rb +2 -6
  183. data/lib/ffi/struct_layout_builder.rb +2 -1
  184. data/lib/ffi/tools/const_generator.rb +78 -26
  185. data/lib/ffi/tools/types_generator.rb +8 -1
  186. data/lib/ffi/types.rb +21 -1
  187. data/spec/ffi/async_callback_spec.rb +2 -2
  188. data/spec/ffi/bool_spec.rb +6 -6
  189. data/spec/ffi/buffer_spec.rb +23 -23
  190. data/spec/ffi/callback_spec.rb +101 -102
  191. data/spec/ffi/custom_type_spec.rb +20 -24
  192. data/spec/ffi/dup_spec.rb +7 -7
  193. data/spec/ffi/enum_spec.rb +127 -127
  194. data/spec/ffi/errno_spec.rb +2 -2
  195. data/spec/ffi/ffi_spec.rb +3 -3
  196. data/spec/ffi/function_spec.rb +10 -10
  197. data/spec/ffi/library_spec.rb +30 -12
  198. data/spec/ffi/managed_struct_spec.rb +4 -4
  199. data/spec/ffi/number_spec.rb +40 -40
  200. data/spec/ffi/pointer_spec.rb +21 -24
  201. data/spec/ffi/rbx/memory_pointer_spec.rb +17 -15
  202. data/spec/ffi/rbx/struct_spec.rb +2 -2
  203. data/spec/ffi/spec_helper.rb +1 -1
  204. data/spec/ffi/string_spec.rb +9 -9
  205. data/spec/ffi/strptr_spec.rb +3 -3
  206. data/spec/ffi/struct_callback_spec.rb +7 -7
  207. data/spec/ffi/struct_initialize_spec.rb +2 -2
  208. data/spec/ffi/struct_packed_spec.rb +6 -6
  209. data/spec/ffi/struct_spec.rb +94 -84
  210. data/spec/ffi/typedef_spec.rb +15 -4
  211. data/spec/ffi/union_spec.rb +3 -3
  212. data/spec/ffi/variadic_spec.rb +17 -14
  213. data/tasks/extension.rake +0 -1
  214. data/tasks/gem.rake +0 -1
  215. data/tasks/rdoc.rake +1 -1
  216. data/tasks/yard.rake +11 -0
  217. metadata +50 -11
  218. data/lib/1.9/ffi_c.so +0 -0
data/Rakefile CHANGED
@@ -14,19 +14,19 @@ require 'rbconfig'
14
14
 
15
15
  load 'tasks/setup.rb'
16
16
 
17
- LIBEXT = case Config::CONFIG['host_os'].downcase
17
+ LIBEXT = case RbConfig::CONFIG['host_os'].downcase
18
18
  when /darwin/
19
19
  "dylib"
20
20
  when /mswin|mingw/
21
21
  "dll"
22
22
  else
23
- Config::CONFIG['DLEXT']
23
+ RbConfig::CONFIG['DLEXT']
24
24
  end
25
25
 
26
- CPU = case Config::CONFIG['host_cpu'].downcase
26
+ CPU = case RbConfig::CONFIG['host_cpu'].downcase
27
27
  when /i[3456]86/
28
28
  # Darwin always reports i686, even when running in 64bit mode
29
- if Config::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
29
+ if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
30
30
  "x86_64"
31
31
  else
32
32
  "i386"
@@ -42,10 +42,10 @@ CPU = case Config::CONFIG['host_cpu'].downcase
42
42
  "powerpc"
43
43
 
44
44
  else
45
- Config::CONFIG['host_cpu']
45
+ RbConfig::CONFIG['host_cpu']
46
46
  end
47
47
 
48
- OS = case Config::CONFIG['host_os'].downcase
48
+ OS = case RbConfig::CONFIG['host_os'].downcase
49
49
  when /linux/
50
50
  "linux"
51
51
  when /darwin/
@@ -59,23 +59,23 @@ OS = case Config::CONFIG['host_os'].downcase
59
59
  when /mswin|mingw/
60
60
  "win32"
61
61
  else
62
- Config::CONFIG['host_os'].downcase
62
+ RbConfig::CONFIG['host_os'].downcase
63
63
  end
64
64
 
65
- CC=ENV['CC'] || Config::CONFIG['CC'] || "gcc"
65
+ CC=ENV['CC'] || RbConfig::CONFIG['CC'] || "gcc"
66
66
 
67
- GMAKE = Config::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? "gmake" : "make"
67
+ GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make'
68
68
 
69
69
  LIBTEST = "build/libtest.#{LIBEXT}"
70
70
  BUILD_DIR = "build"
71
- BUILD_EXT_DIR = File.join(BUILD_DIR, "#{Config::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
71
+ BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
72
72
 
73
73
  # Project general information
74
74
  PROJ.name = 'ffi'
75
75
  PROJ.authors = 'Wayne Meissner'
76
76
  PROJ.email = 'wmeissner@gmail.com'
77
77
  PROJ.url = 'http://wiki.github.com/ffi/ffi'
78
- PROJ.version = '1.0.9'
78
+ PROJ.version = '1.0.12.pre'
79
79
  PROJ.rubyforge.name = 'ffi'
80
80
  PROJ.readme_file = 'README.rdoc'
81
81
 
@@ -116,23 +116,23 @@ TEST_DEPS = [ LIBTEST ]
116
116
  if RUBY_PLATFORM == "java"
117
117
  desc "Run all specs"
118
118
  task :specs => TEST_DEPS do
119
- sh %{#{Gem.ruby} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
119
+ sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
120
120
  end
121
121
  desc "Run rubinius specs"
122
122
  task :rbxspecs => TEST_DEPS do
123
- sh %{#{Gem.ruby} -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
123
+ sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
124
124
  end
125
125
  else
126
126
  TEST_DEPS.unshift :compile
127
127
  desc "Run all specs"
128
128
  task :specs => TEST_DEPS do
129
129
  ENV["MRI_FFI"] = "1"
130
- sh %{#{Gem.ruby} -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
130
+ sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
131
131
  end
132
132
  desc "Run rubinius specs"
133
133
  task :rbxspecs => TEST_DEPS do
134
134
  ENV["MRI_FFI"] = "1"
135
- sh %{#{Gem.ruby} -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
135
+ sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
136
136
  end
137
137
  end
138
138
 
@@ -146,7 +146,7 @@ task :install => 'gem:install'
146
146
  desc "Clean all built files"
147
147
  task :distclean => :clobber do
148
148
  FileUtils.rm_rf('build')
149
- FileUtils.rm_rf(Dir["lib/**/ffi_c.#{Config::CONFIG['DLEXT']}"])
149
+ FileUtils.rm_rf(Dir["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"])
150
150
  FileUtils.rm_rf('lib/1.8')
151
151
  FileUtils.rm_rf('lib/1.9')
152
152
  FileUtils.rm_rf('lib/ffi/types.conf')
@@ -19,11 +19,20 @@
19
19
  */
20
20
 
21
21
  #include <sys/types.h>
22
+ #ifndef _MSC_VER
22
23
  #include <sys/param.h>
23
24
  #include <stdint.h>
24
25
  #include <stdbool.h>
26
+ #else
27
+ typedef int bool;
28
+ #define true 1
29
+ #define false 0
30
+ #endif
25
31
  #include <limits.h>
26
32
  #include <ruby.h>
33
+ #if defined(_MSC_VER) && !defined(INT8_MIN)
34
+ # include "win32/stdint.h"
35
+ #endif
27
36
  #include "rbffi.h"
28
37
  #include "compat.h"
29
38
  #include "AbstractMemory.h"
@@ -256,6 +265,26 @@ get_pointer_value(VALUE value)
256
265
 
257
266
  NUM_OP(pointer, void *, get_pointer_value, rbffi_Pointer_NewInstance, NOSWAP);
258
267
 
268
+ static inline uint8_t
269
+ rbffi_bool_value(VALUE value)
270
+ {
271
+ return RTEST(value);
272
+ }
273
+
274
+ static inline VALUE
275
+ rbffi_bool_new(uint8_t value)
276
+ {
277
+ return (value & 1) != 0 ? Qtrue : Qfalse;
278
+ }
279
+
280
+ NUM_OP(bool, unsigned char, rbffi_bool_value, rbffi_bool_new, NOSWAP);
281
+
282
+
283
+ /*
284
+ * call-seq: memory.clear
285
+ * Set the memory to all-zero.
286
+ * @return [self]
287
+ */
259
288
  static VALUE
260
289
  memory_clear(VALUE self)
261
290
  {
@@ -264,6 +293,11 @@ memory_clear(VALUE self)
264
293
  return self;
265
294
  }
266
295
 
296
+ /*
297
+ * call-seq: memory.size
298
+ * Return memory size in bytes (alias: #total)
299
+ * @return [Numeric]
300
+ */
267
301
  static VALUE
268
302
  memory_size(VALUE self)
269
303
  {
@@ -274,6 +308,15 @@ memory_size(VALUE self)
274
308
  return LONG2NUM(ptr->size);
275
309
  }
276
310
 
311
+ /*
312
+ * call-seq: memory.get_string(offset, length=nil)
313
+ * Return string contained in memory.
314
+ * @param [Numeric] offset point in buffer to start from
315
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
316
+ * @return [String]
317
+ * @raise {IndexError} if +length+ is too great
318
+ * @raise {NullPointerError} if memory not initialized
319
+ */
277
320
  static VALUE
278
321
  memory_get_string(int argc, VALUE* argv, VALUE self)
279
322
  {
@@ -293,6 +336,15 @@ memory_get_string(int argc, VALUE* argv, VALUE self)
293
336
  (end != NULL ? end - ptr->address - off : len));
294
337
  }
295
338
 
339
+ /*
340
+ * call-seq: memory.get_array_of_string(offset, count=nil)
341
+ * Return an array of strings contained in memory.
342
+ * @param [Numeric] offset point in memory to start from
343
+ * @param [Numeric] count number of strings to get. If nil, return all strings
344
+ * @return [Array<String>]
345
+ * @raise {IndexError} if +offset+ is too great
346
+ * @raise {NullPointerError} if memory not initialized
347
+ */
296
348
  static VALUE
297
349
  memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
298
350
  {
@@ -333,6 +385,13 @@ memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
333
385
  return retVal;
334
386
  }
335
387
 
388
+ /*
389
+ * call-seq: memory.read_array_of_string(count=nil)
390
+ * Return an array of strings contained in memory. Same as:
391
+ * memory.get_array_of_string(0, count)
392
+ * @param [Numeric] count number of strings to get. If nil, return all strings
393
+ * @return [Array<String>]
394
+ */
336
395
  static VALUE
337
396
  memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
338
397
  {
@@ -348,6 +407,16 @@ memory_read_array_of_string(int argc, VALUE* argv, VALUE self)
348
407
  }
349
408
 
350
409
 
410
+ /*
411
+ * call-seq: memory.put_string(offset, str)
412
+ * @param [Numeric] offset
413
+ * @param [String] str
414
+ * @return [self]
415
+ * @raise {SecurityError} when writing unsafe string to memory
416
+ * @raise {IndexError} if +offset+ is too great
417
+ * @raise {NullPointerError} if memory not initialized
418
+ * Put a string in memory.
419
+ */
351
420
  static VALUE
352
421
  memory_put_string(VALUE self, VALUE offset, VALUE str)
353
422
  {
@@ -372,6 +441,15 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
372
441
  return self;
373
442
  }
374
443
 
444
+ /*
445
+ * call-seq: memory.get_bytes(offset, length)
446
+ * Return string contained in memory.
447
+ * @param [Numeric] offset point in buffer to start from
448
+ * @param [Numeric] length string's length in bytes.
449
+ * @return [String]
450
+ * @raise {IndexError} if +length+ is too great
451
+ * @raise {NullPointerError} if memory not initialized
452
+ */
375
453
  static VALUE
376
454
  memory_get_bytes(VALUE self, VALUE offset, VALUE length)
377
455
  {
@@ -387,6 +465,19 @@ memory_get_bytes(VALUE self, VALUE offset, VALUE length)
387
465
  return rb_tainted_str_new((char *) ptr->address + off, len);
388
466
  }
389
467
 
468
+ /*
469
+ * call-seq: memory.put_bytes(offset, str, index=0, length=nil)
470
+ * Put a string in memory.
471
+ * @param [Numeric] offset point in buffer to start from
472
+ * @param [String] str string to put to memory
473
+ * @param [Numeric] index
474
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
475
+ * @return [self]
476
+ * @raise {IndexError} if +length+ is too great
477
+ * @raise {NullPointerError} if memory not initialized
478
+ * @raise {RangeError} if +index+ is negative, or if index+length is greater than size of string
479
+ * @raise {SecurityError} when writing unsafe string to memory
480
+ */
390
481
  static VALUE
391
482
  memory_put_bytes(int argc, VALUE* argv, VALUE self)
392
483
  {
@@ -421,12 +512,28 @@ memory_put_bytes(int argc, VALUE* argv, VALUE self)
421
512
  return self;
422
513
  }
423
514
 
515
+ /*
516
+ * call-seq: memory.read_bytes(length)
517
+ * @param [Numeric] length of string to return
518
+ * @return [String]
519
+ * equivalent to :
520
+ * memory.get_bytes(0, length)
521
+ */
424
522
  static VALUE
425
523
  memory_read_bytes(VALUE self, VALUE length)
426
524
  {
427
525
  return memory_get_bytes(self, INT2FIX(0), length);
428
526
  }
429
527
 
528
+ /*
529
+ * call-seq: memory.write_bytes(str, index=0, length=nil)
530
+ * @param [String] str string to put to memory
531
+ * @param [Numeric] index
532
+ * @param [Numeric] length string's length in bytes. If nil, a (memory size - offset) length string is returned).
533
+ * @return [self]
534
+ * equivalent to :
535
+ * memory.put_bytes(0, str, index, length)
536
+ */
430
537
  static VALUE
431
538
  memory_write_bytes(int argc, VALUE* argv, VALUE self)
432
539
  {
@@ -441,6 +548,11 @@ memory_write_bytes(int argc, VALUE* argv, VALUE self)
441
548
  return memory_put_bytes(argc + 1, wargv, self);
442
549
  }
443
550
 
551
+ /*
552
+ * call-seq: memory.type_size
553
+ * @return [Numeric] type size in bytes
554
+ * Get the memory's type size.
555
+ */
444
556
  static VALUE
445
557
  memory_type_size(VALUE self)
446
558
  {
@@ -451,6 +563,13 @@ memory_type_size(VALUE self)
451
563
  return INT2NUM(ptr->typeSize);
452
564
  }
453
565
 
566
+ /*
567
+ * Document-method: []
568
+ * call-seq: memory[idx]
569
+ * @param [Numeric] idx index to access in memory
570
+ * @return
571
+ * Memory read accessor.
572
+ */
454
573
  static VALUE
455
574
  memory_aref(VALUE self, VALUE idx)
456
575
  {
@@ -521,31 +640,64 @@ static MemoryOp memory_op_strptr = { memory_op_get_strptr, memory_op_put_strptr
521
640
  //static MemoryOp memory_op_pointer = { memory_op_get_pointer, memory_op_put_pointer };
522
641
 
523
642
  MemoryOps rbffi_AbstractMemoryOps = {
524
- .int8 = &memory_op_int8,
525
- .uint8 = &memory_op_uint8,
526
- .int16 = &memory_op_int16,
527
- .uint16 = &memory_op_uint16,
528
- .int32 = &memory_op_int32,
529
- .uint32 = &memory_op_uint32,
530
- .int64 = &memory_op_int64,
531
- .uint64 = &memory_op_uint64,
532
- .slong = &memory_op_long,
533
- .uslong = &memory_op_ulong,
534
- .float32 = &memory_op_float32,
535
- .float64 = &memory_op_float64,
536
- .pointer = &memory_op_pointer,
537
- .strptr = &memory_op_strptr,
643
+ &memory_op_int8, //.int8
644
+ &memory_op_uint8, //.uint8
645
+ &memory_op_int16, //.int16
646
+ &memory_op_uint16, //.uint16
647
+ &memory_op_int32, //.int32
648
+ &memory_op_uint32, //.uint32
649
+ &memory_op_int64, //.int64
650
+ &memory_op_uint64, //.uint64
651
+ &memory_op_long, //.slong
652
+ &memory_op_ulong, //.uslong
653
+ &memory_op_float32, //.float32
654
+ &memory_op_float64, //.float64
655
+ &memory_op_pointer, //.pointer
656
+ &memory_op_strptr, //.strptr
657
+ &memory_op_bool //.boolOp
538
658
  };
539
659
 
540
660
  void
541
661
  rbffi_AbstractMemory_Init(VALUE moduleFFI)
542
662
  {
663
+ /*
664
+ * Document-class: FFI::AbstractMemory
665
+ *
666
+ * {AbstractMemory} is the base class for many memory management classes such as {Buffer}.
667
+ *
668
+ * This class has a lot of methods to work with integers :
669
+ * * put_int<i>size</i>(offset, value)
670
+ * * get_int<i>size</i>(offset)
671
+ * * put_uint<i>size</i>(offset, value)
672
+ * * get_uint<i>size</i>(offset)
673
+ * * writeuint<i>size</i>(value)
674
+ * * read_int<i>size</i>
675
+ * * write_uint<i>size</i>(value)
676
+ * * read_uint<i>size</i>
677
+ * * put_array_of_int<i>size</i>(offset, ary)
678
+ * * get_array_of_int<i>size</i>(offset, length)
679
+ * * put_array_of_uint<i>size</i>(offset, ary)
680
+ * * get_array_of_uint<i>size</i>(offset, length)
681
+ * * write_array_of_int<i>size</i>(ary)
682
+ * * read_array_of_int<i>size</i>(length)
683
+ * * write_array_of_uint<i>size</i>(ary)
684
+ * * read_array_of_uint<i>size</i>(length)
685
+ * where _size_ is 8, 16, 32 or 64. Same methods exist for long type.
686
+ *
687
+ * Aliases exist : _char_ for _int8_, _short_ for _int16_, _int_ for _int32_ and <i>long_long</i> for _int64_.
688
+ *
689
+ * Others methods are listed below.
690
+ */
543
691
  VALUE classMemory = rb_define_class_under(moduleFFI, "AbstractMemory", rb_cObject);
544
692
  rbffi_AbstractMemoryClass = classMemory;
693
+ /*
694
+ * Document-variable: FFI::AbstractMemory
695
+ */
545
696
  rb_global_variable(&rbffi_AbstractMemoryClass);
546
697
  rb_define_alloc_func(classMemory, memory_allocate);
547
698
 
548
699
  NullPointerErrorClass = rb_define_class_under(moduleFFI, "NullPointerError", rb_eRuntimeError);
700
+ /* Document-variable: NullPointerError */
549
701
  rb_global_variable(&NullPointerErrorClass);
550
702
 
551
703
 
@@ -597,37 +749,247 @@ rbffi_AbstractMemory_Init(VALUE moduleFFI)
597
749
  ALIAS(int, int32);
598
750
  ALIAS(long_long, int64);
599
751
 
752
+ /*
753
+ * Document-method: put_float32
754
+ * call-seq: memory.put_float32offset, value)
755
+ * @param [Numeric] offset
756
+ * @param [Numeric] value
757
+ * @return [self]
758
+ * Put +value+ as a 32-bit float in memory at offset +offset+ (alias: #put_float).
759
+ */
600
760
  rb_define_method(classMemory, "put_float32", memory_put_float32, 2);
761
+ /*
762
+ * Document-method: get_float32
763
+ * call-seq: memory.get_float32(offset)
764
+ * @param [Numeric] offset
765
+ * @return [Float]
766
+ * Get a 32-bit float from memory at offset +offset+ (alias: #get_float).
767
+ */
601
768
  rb_define_method(classMemory, "get_float32", memory_get_float32, 1);
602
769
  rb_define_alias(classMemory, "put_float", "put_float32");
603
770
  rb_define_alias(classMemory, "get_float", "get_float32");
771
+ /*
772
+ * Document-method: write_float
773
+ * call-seq: memory.write_float(value)
774
+ * @param [Numeric] value
775
+ * @return [self]
776
+ * Write +value+ as a 32-bit float in memory.
777
+ *
778
+ * Same as:
779
+ * memory.put_float(0, value)
780
+ */
604
781
  rb_define_method(classMemory, "write_float", memory_write_float32, 1);
782
+ /*
783
+ * Document-method: read_float
784
+ * call-seq: memory.read_float
785
+ * @return [Float]
786
+ * Read a 32-bit float from memory.
787
+ *
788
+ * Same as:
789
+ * memory.get_float(0)
790
+ */
605
791
  rb_define_method(classMemory, "read_float", memory_read_float32, 0);
792
+ /*
793
+ * Document-method: put_array_of_float32
794
+ * call-seq: memory.put_array_of_float32(offset, ary)
795
+ * @param [Numeric] offset
796
+ * @param [Array<Numeric>] ary
797
+ * @return [self]
798
+ * Put values from +ary+ as 32-bit floats in memory from offset +offset+ (alias: #put_array_of_float).
799
+ */
606
800
  rb_define_method(classMemory, "put_array_of_float32", memory_put_array_of_float32, 2);
801
+ /*
802
+ * Document-method: get_array_of_float32
803
+ * call-seq: memory.get_array_of_float32(offset, length)
804
+ * @param [Numeric] offset
805
+ * @param [Numeric] length number of Float to get
806
+ * @return [Array<Float>]
807
+ * Get 32-bit floats in memory from offset +offset+ (alias: #get_array_of_float).
808
+ */
607
809
  rb_define_method(classMemory, "get_array_of_float32", memory_get_array_of_float32, 2);
810
+ /*
811
+ * Document-method: write_array_of_float
812
+ * call-seq: memory.write_array_of_float(ary)
813
+ * @param [Array<Numeric>] ary
814
+ * @return [self]
815
+ * Write values from +ary+ as 32-bit floats in memory.
816
+ *
817
+ * Same as:
818
+ * memory.put_array_of_float(0, ary)
819
+ */
608
820
  rb_define_method(classMemory, "write_array_of_float", memory_write_array_of_float32, 1);
821
+ /*
822
+ * Document-method: read_array_of_float
823
+ * call-seq: memory.read_array_of_float(length)
824
+ * @param [Numeric] length number of Float to read
825
+ * @return [Array<Float>]
826
+ * Read 32-bit floats from memory.
827
+ *
828
+ * Same as:
829
+ * memory.get_array_of_float(0, ary)
830
+ */
609
831
  rb_define_method(classMemory, "read_array_of_float", memory_read_array_of_float32, 1);
610
832
  rb_define_alias(classMemory, "put_array_of_float", "put_array_of_float32");
611
833
  rb_define_alias(classMemory, "get_array_of_float", "get_array_of_float32");
834
+ /*
835
+ * Document-method: put_float64
836
+ * call-seq: memory.put_float64(offset, value)
837
+ * @param [Numeric] offset
838
+ * @param [Numeric] value
839
+ * @return [self]
840
+ * Put +value+ as a 64-bit float (double) in memory at offset +offset+ (alias: #put_double).
841
+ */
612
842
  rb_define_method(classMemory, "put_float64", memory_put_float64, 2);
843
+ /*
844
+ * Document-method: get_float64
845
+ * call-seq: memory.get_float64(offset)
846
+ * @param [Numeric] offset
847
+ * @return [Float]
848
+ * Get a 64-bit float (double) from memory at offset +offset+ (alias: #get_double).
849
+ */
613
850
  rb_define_method(classMemory, "get_float64", memory_get_float64, 1);
614
851
  rb_define_alias(classMemory, "put_double", "put_float64");
615
852
  rb_define_alias(classMemory, "get_double", "get_float64");
853
+ /*
854
+ * Document-method: write_double
855
+ * call-seq: memory.write_double(value)
856
+ * @param [Numeric] value
857
+ * @return [self]
858
+ * Write +value+ as a 64-bit float (double) in memory.
859
+ *
860
+ * Same as:
861
+ * memory.put_double(0, value)
862
+ */
616
863
  rb_define_method(classMemory, "write_double", memory_write_float64, 1);
864
+ /*
865
+ * Document-method: read_double
866
+ * call-seq: memory.read_double
867
+ * @return [Float]
868
+ * Read a 64-bit float (double) from memory.
869
+ *
870
+ * Same as:
871
+ * memory.get_double(0)
872
+ */
617
873
  rb_define_method(classMemory, "read_double", memory_read_float64, 0);
874
+ /*
875
+ * Document-method: put_array_of_float64
876
+ * call-seq: memory.put_array_of_float64(offset, ary)
877
+ * @param [Numeric] offset
878
+ * @param [Array<Numeric>] ary
879
+ * @return [self]
880
+ * Put values from +ary+ as 64-bit floats (doubles) in memory from offset +offset+ (alias: #put_array_of_double).
881
+ */
618
882
  rb_define_method(classMemory, "put_array_of_float64", memory_put_array_of_float64, 2);
883
+ /*
884
+ * Document-method: get_array_of_float64
885
+ * call-seq: memory.get_array_of_float64(offset, length)
886
+ * @param [Numeric] offset
887
+ * @param [Numeric] length number of Float to get
888
+ * @return [Array<Float>]
889
+ * Get 64-bit floats (doubles) in memory from offset +offset+ (alias: #get_array_of_double).
890
+ */
619
891
  rb_define_method(classMemory, "get_array_of_float64", memory_get_array_of_float64, 2);
892
+ /*
893
+ * Document-method: write_array_of_double
894
+ * call-seq: memory.write_array_of_double(ary)
895
+ * @param [Array<Numeric>] ary
896
+ * @return [self]
897
+ * Write values from +ary+ as 64-bit floats (doubles) in memory.
898
+ *
899
+ * Same as:
900
+ * memory.put_array_of_double(0, ary)
901
+ */
620
902
  rb_define_method(classMemory, "write_array_of_double", memory_write_array_of_float64, 1);
903
+ /*
904
+ * Document-method: read_array_of_double
905
+ * call-seq: memory.read_array_of_double(length)
906
+ * @param [Numeric] length number of Float to read
907
+ * @return [Array<Float>]
908
+ * Read 64-bit floats (doubles) from memory.
909
+ *
910
+ * Same as:
911
+ * memory.get_array_of_double(0, ary)
912
+ */
621
913
  rb_define_method(classMemory, "read_array_of_double", memory_read_array_of_float64, 1);
622
914
  rb_define_alias(classMemory, "put_array_of_double", "put_array_of_float64");
623
915
  rb_define_alias(classMemory, "get_array_of_double", "get_array_of_float64");
916
+ /*
917
+ * Document-method: put_pointer
918
+ * call-seq: memory.put_pointer(offset, value)
919
+ * @param [Numeric] offset
920
+ * @param [nil,Pointer, Integer, #to_ptr] value
921
+ * @return [self]
922
+ * Put +value+ in memory from +offset+..
923
+ */
624
924
  rb_define_method(classMemory, "put_pointer", memory_put_pointer, 2);
925
+ /*
926
+ * Document-method: get_pointer
927
+ * call-seq: memory.get_pointer(offset)
928
+ * @param [Numeric] offset
929
+ * @return [Pointer]
930
+ * Get a {Pointer} to the memory from +offset+.
931
+ */
625
932
  rb_define_method(classMemory, "get_pointer", memory_get_pointer, 1);
933
+ /*
934
+ * Document-method: write_pointer
935
+ * call-seq: memory.write_pointer(value)
936
+ * @param [nil,Pointer, Integer, #to_ptr] value
937
+ * @return [self]
938
+ * Write +value+ in memory.
939
+ *
940
+ * Equivalent to:
941
+ * memory.put_pointer(0, value)
942
+ */
626
943
  rb_define_method(classMemory, "write_pointer", memory_write_pointer, 1);
944
+ /*
945
+ * Document-method: read_pointer
946
+ * call-seq: memory.read_pointer
947
+ * @return [Pointer]
948
+ * Get a {Pointer} to the memory from base address.
949
+ *
950
+ * Equivalent to:
951
+ * memory.get_pointer(0)
952
+ */
627
953
  rb_define_method(classMemory, "read_pointer", memory_read_pointer, 0);
954
+ /*
955
+ * Document-method: put_array_of_pointer
956
+ * call-seq: memory.put_array_of_pointer(offset, ary)
957
+ * @param [Numeric] offset
958
+ * @param [Array<#to_ptr>] ary
959
+ * @return [self]
960
+ * Put an array of {Pointer} into memory from +offset+.
961
+ */
628
962
  rb_define_method(classMemory, "put_array_of_pointer", memory_put_array_of_pointer, 2);
963
+ /*
964
+ * Document-method: get_array_of_pointer
965
+ * call-seq: memory.get_array_of_pointer(offset, length)
966
+ * @param [Numeric] offset
967
+ * @param [Numeric] length
968
+ * @return [Array<Pointer>]
969
+ * Get an array of {Pointer} of length +length+ from +offset+.
970
+ */
629
971
  rb_define_method(classMemory, "get_array_of_pointer", memory_get_array_of_pointer, 2);
972
+ /*
973
+ * Document-method: write_array_of_pointer
974
+ * call-seq: memory.write_array_of_pointer(ary)
975
+ * @param [Array<#to_ptr>] ary
976
+ * @return [self]
977
+ * Write an array of {Pointer} into memory from +offset+.
978
+ *
979
+ * Same as :
980
+ * memory.put_array_of_pointer(0, ary)
981
+ */
630
982
  rb_define_method(classMemory, "write_array_of_pointer", memory_write_array_of_pointer, 1);
983
+ /*
984
+ * Document-method: read_array_of_pointer
985
+ * call-seq: memory.read_array_of_pointer(length)
986
+ * @param [Numeric] length
987
+ * @return [Array<Pointer>]
988
+ * Read an array of {Pointer} of length +length+.
989
+ *
990
+ * Same as:
991
+ * memory.get_array_of_pointer(0, length)
992
+ */
631
993
  rb_define_method(classMemory, "read_array_of_pointer", memory_read_array_of_pointer, 1);
632
994
 
633
995
  rb_define_method(classMemory, "get_string", memory_get_string, -1);