ffi 1.17.3-aarch64-mingw-ucrt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +498 -0
  3. data/COPYING +49 -0
  4. data/Gemfile +26 -0
  5. data/LICENSE +24 -0
  6. data/LICENSE.SPECS +22 -0
  7. data/README.md +138 -0
  8. data/Rakefile +209 -0
  9. data/Steepfile +8 -0
  10. data/ffi.gemspec +41 -0
  11. data/lib/3.4/ffi_c.so +0 -0
  12. data/lib/4.0/ffi_c.so +0 -0
  13. data/lib/ffi/abstract_memory.rb +44 -0
  14. data/lib/ffi/autopointer.rb +186 -0
  15. data/lib/ffi/buffer.rb +4 -0
  16. data/lib/ffi/callback.rb +4 -0
  17. data/lib/ffi/compat.rb +54 -0
  18. data/lib/ffi/data_converter.rb +67 -0
  19. data/lib/ffi/dynamic_library.rb +118 -0
  20. data/lib/ffi/enum.rb +302 -0
  21. data/lib/ffi/errno.rb +43 -0
  22. data/lib/ffi/ffi.rb +109 -0
  23. data/lib/ffi/function.rb +94 -0
  24. data/lib/ffi/io.rb +62 -0
  25. data/lib/ffi/library.rb +592 -0
  26. data/lib/ffi/library_path.rb +109 -0
  27. data/lib/ffi/managedstruct.rb +84 -0
  28. data/lib/ffi/memorypointer.rb +1 -0
  29. data/lib/ffi/platform/aarch64-darwin/types.conf +130 -0
  30. data/lib/ffi/platform/aarch64-freebsd/types.conf +128 -0
  31. data/lib/ffi/platform/aarch64-freebsd12/types.conf +181 -0
  32. data/lib/ffi/platform/aarch64-linux/types.conf +175 -0
  33. data/lib/ffi/platform/aarch64-openbsd/types.conf +134 -0
  34. data/lib/ffi/platform/aarch64-windows/types.conf +52 -0
  35. data/lib/ffi/platform/arm-freebsd/types.conf +152 -0
  36. data/lib/ffi/platform/arm-freebsd12/types.conf +152 -0
  37. data/lib/ffi/platform/arm-linux/types.conf +132 -0
  38. data/lib/ffi/platform/hppa1.1-linux/types.conf +178 -0
  39. data/lib/ffi/platform/hppa2.0-linux/types.conf +178 -0
  40. data/lib/ffi/platform/i386-cygwin/types.conf +3 -0
  41. data/lib/ffi/platform/i386-darwin/types.conf +100 -0
  42. data/lib/ffi/platform/i386-freebsd/types.conf +152 -0
  43. data/lib/ffi/platform/i386-freebsd12/types.conf +152 -0
  44. data/lib/ffi/platform/i386-gnu/types.conf +107 -0
  45. data/lib/ffi/platform/i386-linux/types.conf +103 -0
  46. data/lib/ffi/platform/i386-netbsd/types.conf +126 -0
  47. data/lib/ffi/platform/i386-openbsd/types.conf +128 -0
  48. data/lib/ffi/platform/i386-solaris/types.conf +122 -0
  49. data/lib/ffi/platform/i386-windows/types.conf +52 -0
  50. data/lib/ffi/platform/ia64-linux/types.conf +104 -0
  51. data/lib/ffi/platform/loongarch64-linux/types.conf +141 -0
  52. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  53. data/lib/ffi/platform/mips64-linux/types.conf +104 -0
  54. data/lib/ffi/platform/mips64el-linux/types.conf +104 -0
  55. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  56. data/lib/ffi/platform/mipsisa32r6-linux/types.conf +102 -0
  57. data/lib/ffi/platform/mipsisa32r6el-linux/types.conf +102 -0
  58. data/lib/ffi/platform/mipsisa64r6-linux/types.conf +104 -0
  59. data/lib/ffi/platform/mipsisa64r6el-linux/types.conf +104 -0
  60. data/lib/ffi/platform/powerpc-aix/types.conf +180 -0
  61. data/lib/ffi/platform/powerpc-darwin/types.conf +100 -0
  62. data/lib/ffi/platform/powerpc-linux/types.conf +130 -0
  63. data/lib/ffi/platform/powerpc-openbsd/types.conf +156 -0
  64. data/lib/ffi/platform/powerpc64-linux/types.conf +104 -0
  65. data/lib/ffi/platform/powerpc64le-linux/types.conf +100 -0
  66. data/lib/ffi/platform/riscv64-linux/types.conf +104 -0
  67. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  68. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  69. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  70. data/lib/ffi/platform/sparc-solaris/types.conf +128 -0
  71. data/lib/ffi/platform/sparcv9-linux/types.conf +102 -0
  72. data/lib/ffi/platform/sparcv9-openbsd/types.conf +156 -0
  73. data/lib/ffi/platform/sparcv9-solaris/types.conf +128 -0
  74. data/lib/ffi/platform/sw_64-linux/types.conf +141 -0
  75. data/lib/ffi/platform/x86_64-cygwin/types.conf +3 -0
  76. data/lib/ffi/platform/x86_64-darwin/types.conf +130 -0
  77. data/lib/ffi/platform/x86_64-dragonflybsd/types.conf +130 -0
  78. data/lib/ffi/platform/x86_64-freebsd/types.conf +128 -0
  79. data/lib/ffi/platform/x86_64-freebsd12/types.conf +158 -0
  80. data/lib/ffi/platform/x86_64-haiku/types.conf +117 -0
  81. data/lib/ffi/platform/x86_64-linux/types.conf +132 -0
  82. data/lib/ffi/platform/x86_64-msys/types.conf +119 -0
  83. data/lib/ffi/platform/x86_64-netbsd/types.conf +128 -0
  84. data/lib/ffi/platform/x86_64-openbsd/types.conf +134 -0
  85. data/lib/ffi/platform/x86_64-solaris/types.conf +122 -0
  86. data/lib/ffi/platform/x86_64-windows/types.conf +52 -0
  87. data/lib/ffi/platform.rb +187 -0
  88. data/lib/ffi/pointer.rb +167 -0
  89. data/lib/ffi/struct.rb +317 -0
  90. data/lib/ffi/struct_by_reference.rb +72 -0
  91. data/lib/ffi/struct_layout.rb +96 -0
  92. data/lib/ffi/struct_layout_builder.rb +227 -0
  93. data/lib/ffi/tools/const_generator.rb +232 -0
  94. data/lib/ffi/tools/generator.rb +105 -0
  95. data/lib/ffi/tools/generator_task.rb +32 -0
  96. data/lib/ffi/tools/struct_generator.rb +195 -0
  97. data/lib/ffi/types.rb +222 -0
  98. data/lib/ffi/union.rb +43 -0
  99. data/lib/ffi/variadic.rb +80 -0
  100. data/lib/ffi/version.rb +3 -0
  101. data/lib/ffi.rb +27 -0
  102. data/samples/getlogin.rb +8 -0
  103. data/samples/getpid.rb +8 -0
  104. data/samples/gettimeofday.rb +18 -0
  105. data/samples/hello.rb +8 -0
  106. data/samples/hello_ractor.rb +19 -0
  107. data/samples/inotify.rb +60 -0
  108. data/samples/pty.rb +75 -0
  109. data/samples/qsort.rb +20 -0
  110. data/samples/qsort_ractor.rb +36 -0
  111. data/sig/ffi/abstract_memory.rbs +165 -0
  112. data/sig/ffi/auto_pointer.rbs +26 -0
  113. data/sig/ffi/buffer.rbs +18 -0
  114. data/sig/ffi/data_converter.rbs +10 -0
  115. data/sig/ffi/dynamic_library.rbs +9 -0
  116. data/sig/ffi/enum.rbs +38 -0
  117. data/sig/ffi/errno.rbs +8 -0
  118. data/sig/ffi/function.rbs +39 -0
  119. data/sig/ffi/library.rbs +42 -0
  120. data/sig/ffi/native_type.rbs +86 -0
  121. data/sig/ffi/platform.rbs +49 -0
  122. data/sig/ffi/pointer.rbs +42 -0
  123. data/sig/ffi/struct.rbs +76 -0
  124. data/sig/ffi/struct_by_reference.rbs +11 -0
  125. data/sig/ffi/struct_by_value.rbs +7 -0
  126. data/sig/ffi/struct_layout.rbs +9 -0
  127. data/sig/ffi/struct_layout_builder.rbs +5 -0
  128. data/sig/ffi/type.rbs +39 -0
  129. data/sig/ffi.rbs +29 -0
  130. metadata +179 -0
@@ -0,0 +1,8 @@
1
+ require 'ffi'
2
+
3
+ module Foo
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ attach_function :getlogin, [ ], :string
7
+ end
8
+ puts "getlogin=#{Foo.getlogin}"
data/samples/getpid.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'ffi'
2
+
3
+ module Foo
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ attach_function :getpid, [ ], :int
7
+ end
8
+ puts "My pid=#{Foo.getpid}"
@@ -0,0 +1,18 @@
1
+ require 'ffi'
2
+ require 'rbconfig'
3
+
4
+ class Timeval < FFI::Struct
5
+ layout tv_sec: :ulong, tv_usec: :ulong
6
+ end
7
+ module LibC
8
+ extend FFI::Library
9
+ if FFI::Platform.windows?
10
+ ffi_lib RbConfig::CONFIG["LIBRUBY_SO"]
11
+ else
12
+ ffi_lib FFI::Library::LIBC
13
+ end
14
+ attach_function :gettimeofday, [ :pointer, :pointer ], :int
15
+ end
16
+ t = Timeval.new
17
+ LibC.gettimeofday(t.pointer, nil)
18
+ puts "t.tv_sec=#{t[:tv_sec]} t.tv_usec=#{t[:tv_usec]}"
data/samples/hello.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'ffi'
2
+
3
+ module Foo
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ attach_function("cputs", "puts", [ :string ], :int)
7
+ end
8
+ Foo.cputs("Hello, World via libc puts using FFI on MRI ruby")
@@ -0,0 +1,19 @@
1
+ # See the ffi wiki for how to use FFI with Ractors:
2
+ # https://github.com/ffi/ffi/wiki/Ractors
3
+
4
+ require 'ffi'
5
+
6
+ class Ractor
7
+ # compat with Ruby-3.4 and older
8
+ alias value take unless method_defined? :value
9
+ end
10
+
11
+ module Foo
12
+ extend FFI::Library
13
+ ffi_lib FFI::Library::LIBC
14
+ attach_function("cputs", "puts", [ :string ], :int)
15
+ freeze
16
+ end
17
+ Ractor.new do
18
+ Foo.cputs("Hello, World via libc puts using FFI in a Ractor")
19
+ end.value
@@ -0,0 +1,60 @@
1
+ require 'ffi'
2
+
3
+ module Inotify
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ class Event < FFI::Struct
7
+ layout \
8
+ :wd, :int,
9
+ :mask, :uint,
10
+ :cookie, :uint,
11
+ :len, :uint
12
+ end
13
+ attach_function :init, :inotify_init, [ ], :int
14
+ attach_function :add_watch, :inotify_add_watch, [ :int, :string, :uint ], :int
15
+ attach_function :rm_watch, :inotify_rm_watch, [ :int, :uint ], :int
16
+ attach_function :read, [ :int, :buffer_out, :uint ], :int
17
+ IN_ACCESS=0x00000001
18
+ IN_MODIFY=0x00000002
19
+ IN_ATTRIB=0x00000004
20
+ IN_CLOSE_WRITE=0x00000008
21
+ IN_CLOSE_NOWRITE=0x00000010
22
+ IN_CLOSE=(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
23
+ IN_OPEN=0x00000020
24
+ IN_MOVED_FROM=0x00000040
25
+ IN_MOVED_TO=0x00000080
26
+ IN_MOVE= (IN_MOVED_FROM | IN_MOVED_TO)
27
+ IN_CREATE=0x00000100
28
+ IN_DELETE=0x00000200
29
+ IN_DELETE_SELF=0x00000400
30
+ IN_MOVE_SELF=0x00000800
31
+ # Events sent by the kernel.
32
+ IN_UNMOUNT=0x00002000
33
+ IN_Q_OVERFLOW=0x00004000
34
+ IN_IGNORED=0x00008000
35
+ IN_ONLYDIR=0x01000000
36
+ IN_DONT_FOLLOW=0x02000000
37
+ IN_MASK_ADD=0x20000000
38
+ IN_ISDIR=0x40000000
39
+ IN_ONESHOT=0x80000000
40
+ IN_ALL_EVENTS=(IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE \
41
+ | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM \
42
+ | IN_MOVED_TO | IN_CREATE | IN_DELETE \
43
+ | IN_DELETE_SELF | IN_MOVE_SELF)
44
+
45
+ end
46
+ if $0 == __FILE__
47
+ fd = Inotify.init
48
+ puts "fd=#{fd}"
49
+ wd = Inotify.add_watch(fd, "/tmp/", Inotify::IN_ALL_EVENTS)
50
+ fp = FFI::IO.for_fd(fd)
51
+ puts "wfp=#{fp}"
52
+ while true
53
+ buf = FFI::Buffer.alloc_out(Inotify::Event.size + 4096, 1, false)
54
+ ev = Inotify::Event.new buf
55
+ ready = IO.select([ fp ], nil, nil, nil)
56
+ n = Inotify.read(fd, buf, buf.total)
57
+ puts "Read #{n} bytes from inotify fd"
58
+ puts "event.wd=#{ev[:wd]} mask=#{ev[:mask]} len=#{ev[:len]} name=#{ev[:len] > 0 ? buf.get_string(16) : 'unknown'}"
59
+ end
60
+ end
data/samples/pty.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'ffi'
2
+
3
+ module PTY
4
+ private
5
+ module LibC
6
+ extend FFI::Library
7
+ ffi_lib FFI::Library::LIBC
8
+ attach_function :forkpty, [ :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
9
+ attach_function :openpty, [ :buffer_out, :buffer_out, :buffer_out, :buffer_in, :buffer_in ], :int
10
+ attach_function :login_tty, [ :int ], :int
11
+ attach_function :close, [ :int ], :int
12
+ attach_function :strerror, [ :int ], :string
13
+ attach_function :fork, [], :int
14
+ attach_function :execv, [ :string, :buffer_in ], :int
15
+ attach_function :execvp, [ :string, :buffer_in ], :int
16
+ attach_function :dup2, [ :int, :int ], :int
17
+ attach_function :dup, [ :int ], :int
18
+ end
19
+ Buffer = FFI::Buffer
20
+ def self.build_args(args)
21
+ cmd = args.shift
22
+ cmd_args = args.map do |arg|
23
+ MemoryPointer.from_string(arg)
24
+ end
25
+ exec_args = MemoryPointer.new(:pointer, 1 + cmd_args.length + 1)
26
+ exec_cmd = MemoryPointer.from_string(cmd)
27
+ exec_args[0].put_pointer(0, exec_cmd)
28
+ cmd_args.each_with_index do |arg, i|
29
+ exec_args[i + 1].put_pointer(0, arg)
30
+ end
31
+ [ cmd, exec_args ]
32
+ end
33
+ public
34
+ def self.getpty(*args)
35
+ mfdp = Buffer.new :int
36
+ name = Buffer.new 1024
37
+ #
38
+ # All the execv setup is done in the parent, since doing anything other than
39
+ # execv in the child after fork is really flakey
40
+ #
41
+ exec_cmd, exec_args = build_args(args)
42
+ pid = LibC.forkpty(mfdp, name, nil, nil)
43
+ raise "forkpty failed: #{LibC.strerror(FFI.errno)}" if pid < 0
44
+ if pid == 0
45
+ LibC.execvp(exec_cmd, exec_args)
46
+ exit 1
47
+ end
48
+ masterfd = mfdp.get_int(0)
49
+ rfp = FFI::IO.for_fd(masterfd, "r")
50
+ wfp = FFI::IO.for_fd(LibC.dup(masterfd), "w")
51
+ if block_given?
52
+ yield rfp, wfp, pid
53
+ rfp.close unless rfp.closed?
54
+ wfp.close unless wfp.closed?
55
+ else
56
+ [ rfp, wfp, pid ]
57
+ end
58
+ end
59
+ def self.spawn(*args, &block)
60
+ self.getpty("/bin/sh", "-c", args[0], &block)
61
+ end
62
+ end
63
+ module LibC
64
+ extend FFI::Library
65
+ attach_function :close, [ :int ], :int
66
+ attach_function :write, [ :int, :buffer_in, :ulong ], :long
67
+ attach_function :read, [ :int, :buffer_out, :ulong ], :long
68
+ end
69
+ PTY.getpty("/bin/ls", "-alR", "/") { |rfd, wfd, pid|
70
+ #PTY.spawn("ls -laR /") { |rfd, wfd, pid|
71
+ puts "child pid=#{pid}"
72
+ while !rfd.eof? && (buf = rfd.gets)
73
+ puts "child: '#{buf.strip}'"
74
+ end
75
+ }
data/samples/qsort.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'ffi'
2
+
3
+ module LibC
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+ callback :qsort_cmp, [ :pointer, :pointer ], :int
7
+ attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int
8
+ end
9
+
10
+ p = FFI::MemoryPointer.new(:int, 2)
11
+ p.put_array_of_int32(0, [ 2, 1 ])
12
+ puts "ptr=#{p.inspect}"
13
+ puts "Before qsort #{p.get_array_of_int32(0, 2).join(', ')}"
14
+ LibC.qsort(p, 2, 4) do |p1, p2|
15
+ i1 = p1.get_int32(0)
16
+ i2 = p2.get_int32(0)
17
+ puts "In block: comparing #{i1} and #{i2}"
18
+ i1 < i2 ? -1 : i1 > i2 ? 1 : 0
19
+ end
20
+ puts "After qsort #{p.get_array_of_int32(0, 2).join(', ')}"
@@ -0,0 +1,36 @@
1
+ # See the ffi wiki for how to use FFI with Ractors:
2
+ # https://github.com/ffi/ffi/wiki/Ractors
3
+
4
+ require 'ffi'
5
+
6
+ class Ractor
7
+ # compat with Ruby-3.4 and older
8
+ alias value take unless method_defined? :value
9
+ end
10
+
11
+ module LibC
12
+ extend FFI::Library
13
+ ffi_lib FFI::Library::LIBC
14
+ callback :qsort_cmp, [ :pointer, :pointer ], :int
15
+ attach_function :qsort, [ :pointer, :ulong, :ulong, :qsort_cmp ], :int
16
+
17
+ freeze # Freeze the module variables, so that it can be shared across ractors.
18
+ end
19
+
20
+ p = FFI::MemoryPointer.new(:int, 3)
21
+ p.put_array_of_int32(0, [ 2, 3, 1 ]) # Write some unsorted data into the memory
22
+ # Ractor.make_shareable(p) # freeze the pointer to be shared between ractors instead of copied
23
+ puts "main -ptr=#{p.inspect}"
24
+ res = Ractor.new(p) do |p|
25
+ puts "ractor-ptr=#{p.inspect}"
26
+ puts "Before qsort #{p.get_array_of_int32(0, 3).join(', ')}"
27
+ LibC.qsort(p, 3, 4) do |p1, p2|
28
+ i1 = p1.get_int32(0)
29
+ i2 = p2.get_int32(0)
30
+ puts "In block: comparing #{i1} and #{i2}"
31
+ i1 < i2 ? -1 : i1 > i2 ? 1 : 0
32
+ end
33
+ puts "After qsort #{p.get_array_of_int32(0, 3).join(', ')}"
34
+ end.value
35
+
36
+ puts "After ractor termination #{p.get_array_of_int32(0, 3).join(', ')}"
@@ -0,0 +1,165 @@
1
+ module FFI
2
+ class AbstractMemory
3
+ interface _Size
4
+ def size: () -> Integer
5
+ end
6
+ include _Size
7
+ type type_size = Integer | _Size | Symbol
8
+
9
+ type order_out = :big | :little
10
+ type order_in = order_out | :network
11
+
12
+ def []: (Integer idx) -> instance
13
+ def clear: () -> self
14
+ def freeze: ...
15
+ def get: (ffi_type type, Integer offset) -> top
16
+ def put: (ffi_type type, Integer offset, top value) -> nil
17
+ def size_limit?: () -> bool
18
+ def type_size: () -> Integer
19
+ alias total size
20
+
21
+ def get_int8: (Integer offset) -> Integer
22
+ def get_int16: (Integer offset) -> Integer
23
+ def get_int32: (Integer offset) -> Integer
24
+ def get_int64: (Integer offset) -> Integer
25
+ def get_uint8: (Integer offset) -> Integer
26
+ def get_uint16: (Integer offset) -> Integer
27
+ def get_uint32: (Integer offset) -> Integer
28
+ def get_uint64: (Integer offset) -> Integer
29
+ def get_char: (Integer offset) -> Integer
30
+ def get_short: (Integer offset) -> Integer
31
+ def get_int: (Integer offset) -> Integer
32
+ def get_long_long: (Integer offset) -> Integer
33
+ def get_float32: (Integer offset) -> Float
34
+ def get_float64: (Integer offset) -> Float
35
+ def get_pointer: (Integer offset) -> Pointer
36
+ def get_bytes: (Integer offset, Integer length) -> String
37
+ def get_string: (Integer offset, ?Integer? length) -> String
38
+ alias get_float get_float32
39
+ alias get_double get_float64
40
+
41
+ def put_int8: (Integer offset, int value) -> self
42
+ def put_int16: (Integer offset, int value) -> self
43
+ def put_int32: (Integer offset, int value) -> self
44
+ def put_int64: (Integer offset, int value) -> self
45
+ def put_uint8: (Integer offset, int value) -> self
46
+ def put_uint16: (Integer offset, int value) -> self
47
+ def put_uint32: (Integer offset, int value) -> self
48
+ def put_uint64: (Integer offset, int value) -> self
49
+ def put_char: (Integer offset, int value) -> self
50
+ def put_short: (Integer offset, int value) -> self
51
+ def put_int: (Integer offset, int value) -> self
52
+ def put_long_long: (Integer offset, int value) -> self
53
+ def put_float32: (Integer offset, Numeric value) -> self
54
+ def put_float64: (Integer offset, Numeric value) -> self
55
+ def put_pointer: (Integer offset, pointer value) -> self
56
+ def put_bytes: (Integer offset, String str, ?Integer index, ?Integer? length) -> self
57
+ def put_string: (Integer offset, String value) -> self
58
+ alias put_float put_float32
59
+ alias put_double put_float64
60
+
61
+ def read_int8: () -> Integer
62
+ def read_int16: () -> Integer
63
+ def read_int32: () -> Integer
64
+ def read_int64: () -> Integer
65
+ def read_uint8: () -> Integer
66
+ def read_uint16: () -> Integer
67
+ def read_uint32: () -> Integer
68
+ def read_uint64: () -> Integer
69
+ def read_char: () -> Integer
70
+ def read_short: () -> Integer
71
+ def read_int: () -> Integer
72
+ def read_long_long: () -> Integer
73
+ def read_float: () -> Float
74
+ def read_double: () -> Float
75
+ def read_pointer: () -> Pointer
76
+ def read_bytes: (Integer length) -> String
77
+
78
+ def write_int8: (int value) -> self
79
+ def write_int16: (int value) -> self
80
+ def write_int32: (int value) -> self
81
+ def write_int64: (int value) -> self
82
+ def write_uint8: (int value) -> self
83
+ def write_uint16: (int value) -> self
84
+ def write_uint32: (int value) -> self
85
+ def write_uint64: (int value) -> self
86
+ def write_char: (int value) -> self
87
+ def write_short: (int value) -> self
88
+ def write_int: (int value) -> self
89
+ def write_long_long: (int value) -> self
90
+ def write_float: (Numeric value) -> self
91
+ def write_double: (Numeric value) -> self
92
+ def write_pointer: (pointer value) -> self
93
+ def write_bytes: (String str, ?Integer index, ?Integer? length) -> self
94
+
95
+ def get_array_of_int8: (Integer offset, Integer length) -> Array[Integer]
96
+ def get_array_of_int16: (Integer offset, Integer length) -> Array[Integer]
97
+ def get_array_of_int32: (Integer offset, Integer length) -> Array[Integer]
98
+ def get_array_of_int64: (Integer offset, Integer length) -> Array[Integer]
99
+ def get_array_of_uint8: (Integer offset, Integer length) -> Array[Integer]
100
+ def get_array_of_uint16: (Integer offset, Integer length) -> Array[Integer]
101
+ def get_array_of_uint32: (Integer offset, Integer length) -> Array[Integer]
102
+ def get_array_of_uint64: (Integer offset, Integer length) -> Array[Integer]
103
+ def get_array_of_char: (Integer offset, Integer length) -> Array[Integer]
104
+ def get_array_of_short: (Integer offset, Integer length) -> Array[Integer]
105
+ def get_array_of_int: (Integer offset, Integer length) -> Array[Integer]
106
+ def get_array_of_long_long: (Integer offset, Integer length) -> Array[Integer]
107
+ def get_array_of_float32: (Integer offset, Integer length) -> Array[Float]
108
+ def get_array_of_float64: (Integer offset, Integer length) -> Array[Float]
109
+ def get_array_of_pointer: (Integer offset, Integer length) -> Array[Pointer]
110
+ def get_array_of_string: (Integer offset, ?Integer? count) -> Array[String?]
111
+ alias get_array_of_float get_array_of_float32
112
+ alias get_array_of_double get_array_of_float64
113
+
114
+ def put_array_of_int8: (Integer offset, Array[int] ary) -> self
115
+ def put_array_of_int16: (Integer offset, Array[int] ary) -> self
116
+ def put_array_of_int32: (Integer offset, Array[int] ary) -> self
117
+ def put_array_of_int64: (Integer offset, Array[int] ary) -> self
118
+ def put_array_of_uint8: (Integer offset, Array[int] ary) -> self
119
+ def put_array_of_uint16: (Integer offset, Array[int] ary) -> self
120
+ def put_array_of_uint32: (Integer offset, Array[int] ary) -> self
121
+ def put_array_of_uint64: (Integer offset, Array[int] ary) -> self
122
+ def put_array_of_char: (Integer offset, Array[int] ary) -> self
123
+ def put_array_of_short: (Integer offset, Array[int] ary) -> self
124
+ def put_array_of_int: (Integer offset, Array[int] ary) -> self
125
+ def put_array_of_long_long: (Integer offset, Array[int] ary) -> self
126
+ def put_array_of_float32: (Integer offset, Array[Numeric] ary) -> self
127
+ def put_array_of_float64: (Integer offset, Array[Numeric] ary) -> self
128
+ def put_array_of_pointer: (Integer offset, Array[pointer] ary) -> self
129
+ alias put_array_of_float put_array_of_float32
130
+ alias put_array_of_double put_array_of_float64
131
+
132
+ def read_array_of_int8: (Integer length) -> Array[Integer]
133
+ def read_array_of_int16: (Integer length) -> Array[Integer]
134
+ def read_array_of_int32: (Integer length) -> Array[Integer]
135
+ def read_array_of_int64: (Integer length) -> Array[Integer]
136
+ def read_array_of_uint8: (Integer length) -> Array[Integer]
137
+ def read_array_of_uint16: (Integer length) -> Array[Integer]
138
+ def read_array_of_uint32: (Integer length) -> Array[Integer]
139
+ def read_array_of_uint64: (Integer length) -> Array[Integer]
140
+ def read_array_of_char: (Integer length) -> Array[Integer]
141
+ def read_array_of_short: (Integer length) -> Array[Integer]
142
+ def read_array_of_int: (Integer length) -> Array[Integer]
143
+ def read_array_of_long_long: (Integer length) -> Array[Integer]
144
+ def read_array_of_float: (Integer length) -> Array[Float]
145
+ def read_array_of_double: (Integer length) -> Array[Float]
146
+ def read_array_of_pointer: (Integer length) -> Array[Pointer]
147
+ def read_array_of_string: (?Integer? count) -> Array[String?]
148
+
149
+ def write_array_of_int8: (Array[int] ary) -> self
150
+ def write_array_of_int16: (Array[int] ary) -> self
151
+ def write_array_of_int32: (Array[int] ary) -> self
152
+ def write_array_of_int64: (Array[int] ary) -> self
153
+ def write_array_of_uint8: (Array[int] ary) -> self
154
+ def write_array_of_uint16: (Array[int] ary) -> self
155
+ def write_array_of_uint32: (Array[int] ary) -> self
156
+ def write_array_of_uint64: (Array[int] ary) -> self
157
+ def write_array_of_char: (Array[int] ary) -> self
158
+ def write_array_of_short: (Array[int] ary) -> self
159
+ def write_array_of_int: (Array[int] ary) -> self
160
+ def write_array_of_long_long: (Array[int] ary) -> self
161
+ def write_array_of_float: (Array[Numeric] ary) -> self
162
+ def write_array_of_double: (Array[Numeric] ary) -> self
163
+ def write_array_of_pointer: (Array[pointer] ary) -> self
164
+ end
165
+ end
@@ -0,0 +1,26 @@
1
+ module FFI
2
+ class AutoPointer < Pointer
3
+ class Releaser
4
+ attr_accessor autorelease: boolish
5
+ interface _Proc[P < Pointer]
6
+ def call: (P) -> void
7
+ end
8
+ def initialize: [P < Pointer] (P ptr, _Proc[P] proc) -> void
9
+
10
+ def call: (*untyped) -> void
11
+ def free: () -> nil
12
+ def release: (Pointer ptr) -> void
13
+ end
14
+
15
+ def initialize: (Pointer pointer, Method | ^(instance) -> void | Releaser::_Proc[instance] callable) -> self
16
+ | (Pointer pointer) -> self # where class < `def self.release: (instance pointer) -> void`
17
+
18
+ extend DataConverter[Pointer, instance, nil]
19
+ def self.from_native: ...
20
+ def self.native_type: () -> Type::Builtin
21
+
22
+ def autorelease?: ...
23
+ def autorelease=: ...
24
+ def free: () -> nil
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ module FFI
2
+ class Buffer < AbstractMemory
3
+ def initialize: (AbstractMemory::type_size, ?Integer count, boolish clear) -> self
4
+ alias self.alloc_inout self.new
5
+ alias self.new_inout self.alloc_inout
6
+ alias self.alloc_in self.alloc_inout
7
+ alias self.new_in self.alloc_in
8
+ alias self.alloc_out self.alloc_inout
9
+ alias self.new_out self.alloc_out
10
+
11
+ def +: (Integer) -> Buffer
12
+ def inspect: ...
13
+ def order: () -> AbstractMemory::order_out
14
+ | (AbstractMemory::order_in order) -> Buffer
15
+ | (untyped order) -> (self | Buffer)
16
+ def slice: (Integer offset, Integer length) -> Buffer
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ module FFI
2
+ interface _DataConverter[N, R, in C]
3
+ def from_native: (N value, C ctx) -> R
4
+ def native_type: (?ffi_auto_type? type) -> Type
5
+ def to_native: (R value, C ctx) -> N
6
+ end
7
+ module DataConverter[N, R, in C]
8
+ include _DataConverter[N, R, C]
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module FFI
2
+ class DynamicLibrary
3
+ # TODO
4
+
5
+ class Symbol < Pointer
6
+ # TODO
7
+ end
8
+ end
9
+ end
data/sig/ffi/enum.rbs ADDED
@@ -0,0 +1,38 @@
1
+ module FFI
2
+ class Enums
3
+ def initialize: () -> void
4
+
5
+ def <<: (Enum enum) -> void
6
+ def __map_symbol: (Symbol symbol) -> Integer?
7
+ def find: (Symbol query) -> Enum
8
+ end
9
+
10
+ class Enum
11
+ include DataConverter[Integer, Symbol | Integer, untyped]
12
+
13
+ attr_reader native_type: Type
14
+ attr_reader tag: Symbol?
15
+ def initialize: (Enumerable[Symbol | Integer], ?Symbol? tag, *untyped) -> void
16
+ | (Type native_type, Enumerable[Symbol | Integer], ?Symbol? tag, *untyped) -> void
17
+
18
+ def []: (Symbol query) -> Integer?
19
+ | (Integer query) -> Symbol?
20
+ def symbol_map: () -> Hash[Symbol, Integer]
21
+ alias to_h symbol_map
22
+ alias to_hash symbol_map
23
+ def symbols: () -> Array[Symbol]
24
+ def to_native: (Symbol | int value, untyped ctx) -> Integer
25
+ end
26
+
27
+ class Bitmask < Enum
28
+ def initialize: ...
29
+
30
+ def []: (*Symbol query) -> Integer
31
+ | (Array[Symbol] query) -> Integer
32
+ | (*Integer query) -> Array[Symbol]
33
+ | (Array[Integer] query) -> Array[Symbol]
34
+ def from_native: (Integer, untyped ctx) -> Array[Symbol | Integer]
35
+ def to_native: (Array[Symbol | int] value, untyped ctx) -> Integer
36
+ | ...
37
+ end
38
+ end
data/sig/ffi/errno.rbs ADDED
@@ -0,0 +1,8 @@
1
+ module FFI
2
+ module LastError
3
+ def self?.error: () -> Integer
4
+ def self?.error=: (Integer) -> Integer
5
+ def self?.winapi_error: () -> Integer?
6
+ def self?.winapi_error=: (Integer? error) -> void
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ module FFI
2
+ interface _Function
3
+ # TODO: leads to a endless recursion when used with -rrbs/test/setup
4
+ # def attach: (Module mod, String name) -> self
5
+ def call: (*untyped args) -> untyped
6
+ def param_types: () -> Array[Type]
7
+ def return_type: () -> Type
8
+ end
9
+
10
+ class Function < Pointer
11
+ include _Function
12
+ # ?blocking: boolish?, ?convention: Library::convention?, ?enums: Enums?
13
+ def initialize:
14
+ (
15
+ ffi_type return_type, Array[ffi_type] param_types,
16
+ ?Hash[Symbol, untyped] options
17
+ ) { (*untyped) -> untyped } -> self
18
+ | (
19
+ ffi_type return_type, Array[ffi_type] param_types, Proc | Pointer proc,
20
+ ?Hash[Symbol, untyped] options
21
+ ) -> self
22
+
23
+ def autorelease?: ...
24
+ alias autorelease autorelease?
25
+ def autorelease=: ...
26
+ def free: () -> self
27
+ end
28
+
29
+ class VariadicInvoker
30
+ include _Function
31
+ def initialize:
32
+ (
33
+ Pointer function, Array[ffi_type] parameter_types, ffi_type return_type,
34
+ Hash[Symbol, untyped] options #TODO
35
+ ) -> void
36
+
37
+ def invoke: (Array[Type] parameter_types, Array[untyped] parameter_values) -> untyped
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ module FFI
2
+ module Library
3
+ type convention = :default | :stdcall
4
+ type ffi_lib_flag = :global | :local | :lazy | :now
5
+ type ffi_lib_type = ffi_auto_type | singleton(Struct)
6
+
7
+ CURRENT_PROCESS: current_process
8
+ LIBC: String
9
+ FlagsMap: Hash[ffi_lib_flag, Integer]
10
+
11
+ def self.extended: ...
12
+
13
+ def attach_function: ( _ToS func, Array[ffi_lib_type] args, ffi_lib_type? returns, ?blocking: boolish, ?convention: convention, ?enums: Enums, ?type_map: type_map) -> (Function | VariadicInvoker)
14
+ | (_ToS name, _ToS func, Array[ffi_lib_type] args, ?ffi_lib_type? returns, ?blocking: boolish, ?convention: convention, ?enums: Enums, ?type_map: type_map) -> (Function | VariadicInvoker)
15
+ def attach_variable: (?_ToS mname, _ToS cname, ffi_lib_type type) -> DynamicLibrary::Symbol
16
+ def attached_functions: () -> Hash[Symbol, Function | VariadicInvoker]
17
+ def attached_variables: () -> Hash[Symbol, Type | singleton(Struct)]
18
+
19
+ def bitmask: (?Type native_type, Symbol name, Array[Symbol | Integer] values) -> Bitmask
20
+ | (?Type native_type, *Symbol | Integer args) -> Bitmask
21
+ | (?Type native_type, Array[Symbol | Integer] values) -> Bitmask
22
+ def enum: (?Type native_type, Symbol name, Array[Symbol | Integer] values) -> Enum
23
+ | (?Type native_type, *Symbol | Integer args) -> Enum
24
+ | (?Type native_type, Array[Symbol | Integer] values) -> Enum
25
+ def enum_type: (Symbol name) -> Enum?
26
+ def enum_for: (Symbol name) -> Integer?
27
+
28
+ def callback: (?Symbol name, Array[ffi_lib_type] params, ffi_lib_type ret) -> CallbackInfo
29
+ def ffi_convention: (?convention? convention) -> convention
30
+ def ffi_lib: (*_ToS names) -> Array[DynamicLibrary]
31
+ def ffi_lib_flags: (*ffi_lib_flag flags) -> Integer
32
+ def ffi_libraries: () -> Array[DynamicLibrary]
33
+ def find_type: (ffi_lib_type t) -> Type
34
+ def freeze: () -> void
35
+ def function_names: (_ToS name, Array[Type | singleton(Struct)] arg_types) -> Array[String]
36
+ def typedef: [T < Type, N, R, C] (T old, Symbol | DataConverter[N, R, C] add, ?untyped) -> T
37
+ | (Symbol old, Symbol add, ?untyped) -> (Type | Enum)
38
+ | [X < DataConverter[N, R, C], N, R, C] (X old, Symbol add, ?untyped) -> Type::Mapped[X, N, R, C]
39
+ | (:enum old, Array[Symbol | Integer] add, ?untyped) -> Enum
40
+ | (:enum old, Symbol | Type add, Array[Symbol | Integer] info) -> Enum
41
+ end
42
+ end