rbs 2.0.0 → 2.2.2

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 (208) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +34 -0
  3. data/.github/workflows/ruby.yml +5 -0
  4. data/CHANGELOG.md +82 -0
  5. data/README.md +6 -1
  6. data/Rakefile +56 -21
  7. data/core/array.rbs +2866 -1086
  8. data/core/basic_object.rbs +150 -30
  9. data/core/binding.rbs +33 -0
  10. data/core/builtin.rbs +4 -4
  11. data/core/class.rbs +43 -5
  12. data/core/comparable.rbs +57 -0
  13. data/core/complex.rbs +170 -4
  14. data/core/constants.rbs +51 -0
  15. data/core/deprecated.rbs +7 -0
  16. data/core/dir.rbs +305 -20
  17. data/core/encoding.rbs +1214 -77
  18. data/core/enumerable.rbs +2173 -234
  19. data/core/enumerator.rbs +448 -182
  20. data/core/env.rbs +448 -1
  21. data/core/errno.rbs +1 -10
  22. data/core/errors.rbs +152 -2
  23. data/core/exception.rbs +201 -127
  24. data/core/false_class.rbs +27 -0
  25. data/core/fiber.rbs +118 -37
  26. data/core/fiber_error.rbs +8 -9
  27. data/core/file.rbs +1060 -142
  28. data/core/file_test.rbs +287 -32
  29. data/core/float.rbs +776 -300
  30. data/core/gc.rbs +185 -34
  31. data/core/global_variables.rbs +5 -1
  32. data/core/hash.rbs +1582 -649
  33. data/core/integer.rbs +974 -204
  34. data/core/io/buffer.rbs +710 -0
  35. data/core/io/wait.rbs +29 -8
  36. data/core/io.rbs +2438 -417
  37. data/core/kernel.rbs +2319 -318
  38. data/core/marshal.rbs +37 -2
  39. data/core/match_data.rbs +123 -6
  40. data/core/math.rbs +126 -6
  41. data/core/method.rbs +226 -102
  42. data/core/module.rbs +421 -45
  43. data/core/nil_class.rbs +64 -0
  44. data/core/numeric.rbs +620 -142
  45. data/core/object.rbs +453 -81
  46. data/core/object_space.rbs +92 -2
  47. data/core/proc.rbs +482 -285
  48. data/core/process.rbs +443 -34
  49. data/core/ractor.rbs +232 -9
  50. data/core/random.rbs +151 -52
  51. data/core/range.rbs +885 -160
  52. data/core/rational.rbs +122 -6
  53. data/core/rb_config.rbs +14 -4
  54. data/core/refinement.rbs +44 -0
  55. data/core/regexp.rbs +156 -14
  56. data/core/ruby_vm.rbs +42 -3
  57. data/core/signal.rbs +78 -39
  58. data/core/string.rbs +2123 -567
  59. data/core/string_io.rbs +204 -0
  60. data/core/struct.rbs +283 -28
  61. data/core/symbol.rbs +304 -30
  62. data/core/thread.rbs +1288 -688
  63. data/core/thread_group.rbs +66 -10
  64. data/core/time.rbs +643 -217
  65. data/core/trace_point.rbs +100 -12
  66. data/core/true_class.rbs +24 -0
  67. data/core/unbound_method.rbs +73 -7
  68. data/core/warning.rbs +37 -12
  69. data/docs/CONTRIBUTING.md +40 -34
  70. data/docs/stdlib.md +3 -102
  71. data/docs/syntax.md +54 -11
  72. data/ext/rbs_extension/extconf.rb +1 -0
  73. data/ext/rbs_extension/lexer.h +5 -0
  74. data/ext/rbs_extension/lexstate.c +6 -0
  75. data/ext/rbs_extension/parser.c +85 -10
  76. data/ext/rbs_extension/ruby_objs.c +4 -2
  77. data/ext/rbs_extension/ruby_objs.h +2 -2
  78. data/goodcheck.yml +0 -11
  79. data/lib/rbs/annotate/annotations.rb +197 -0
  80. data/lib/rbs/annotate/formatter.rb +80 -0
  81. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  82. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  83. data/lib/rbs/annotate.rb +6 -0
  84. data/lib/rbs/ast/members.rb +21 -13
  85. data/lib/rbs/buffer.rb +17 -11
  86. data/lib/rbs/cli.rb +48 -1
  87. data/lib/rbs/definition_builder/method_builder.rb +28 -16
  88. data/lib/rbs/definition_builder.rb +6 -2
  89. data/lib/rbs/environment.rb +8 -4
  90. data/lib/rbs/location_aux.rb +12 -0
  91. data/lib/rbs/namespace.rb +1 -1
  92. data/lib/rbs/prototype/rb.rb +12 -0
  93. data/lib/rbs/type_alias_regularity.rb +6 -4
  94. data/lib/rbs/type_name.rb +1 -1
  95. data/lib/rbs/types.rb +1 -1
  96. data/lib/rbs/validator.rb +6 -0
  97. data/lib/rbs/version.rb +1 -1
  98. data/lib/rbs/writer.rb +54 -4
  99. data/lib/rbs.rb +0 -2
  100. data/schema/typeParam.json +3 -3
  101. data/sig/annotate/annotations.rbs +102 -0
  102. data/sig/annotate/formatter.rbs +24 -0
  103. data/sig/annotate/rdoc_annotater.rbs +82 -0
  104. data/sig/annotate/rdoc_source.rbs +30 -0
  105. data/sig/buffer.rbs +6 -2
  106. data/sig/cli.rbs +2 -0
  107. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  108. data/sig/location.rbs +6 -0
  109. data/sig/members.rbs +24 -18
  110. data/sig/method_builder.rbs +5 -4
  111. data/sig/method_types.rbs +5 -1
  112. data/sig/polyfill.rbs +78 -0
  113. data/sig/validator.rbs +3 -1
  114. data/sig/writer.rbs +79 -2
  115. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  116. data/stdlib/abbrev/0/array.rbs +26 -0
  117. data/stdlib/base64/0/base64.rbs +31 -0
  118. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  119. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  120. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  121. data/stdlib/cgi/0/core.rbs +649 -21
  122. data/stdlib/coverage/0/coverage.rbs +164 -2
  123. data/stdlib/csv/0/csv.rbs +2862 -398
  124. data/stdlib/date/0/date.rbs +483 -25
  125. data/stdlib/date/0/date_time.rbs +187 -12
  126. data/stdlib/dbm/0/dbm.rbs +152 -17
  127. data/stdlib/digest/0/digest.rbs +146 -0
  128. data/stdlib/erb/0/erb.rbs +65 -245
  129. data/stdlib/fiber/0/fiber.rbs +73 -91
  130. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  131. data/stdlib/find/0/find.rbs +9 -0
  132. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  133. data/stdlib/io-console/0/io-console.rbs +227 -15
  134. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  135. data/stdlib/json/0/json.rbs +1147 -145
  136. data/stdlib/logger/0/formatter.rbs +24 -0
  137. data/stdlib/logger/0/log_device.rbs +64 -0
  138. data/stdlib/logger/0/logger.rbs +165 -13
  139. data/stdlib/logger/0/period.rbs +10 -0
  140. data/stdlib/logger/0/severity.rbs +26 -0
  141. data/stdlib/monitor/0/monitor.rbs +163 -0
  142. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  143. data/stdlib/net-http/0/manifest.yaml +1 -0
  144. data/stdlib/net-http/0/net-http.rbs +1513 -683
  145. data/stdlib/nkf/0/nkf.rbs +372 -0
  146. data/stdlib/objspace/0/objspace.rbs +149 -90
  147. data/stdlib/openssl/0/openssl.rbs +8108 -71
  148. data/stdlib/optparse/0/optparse.rbs +487 -19
  149. data/stdlib/pathname/0/pathname.rbs +425 -124
  150. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  151. data/stdlib/prime/0/integer-extension.rbs +20 -2
  152. data/stdlib/prime/0/prime.rbs +88 -21
  153. data/stdlib/pstore/0/pstore.rbs +102 -0
  154. data/stdlib/pty/0/pty.rbs +64 -14
  155. data/stdlib/resolv/0/resolv.rbs +420 -31
  156. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  157. data/stdlib/rubygems/0/config_file.rbs +33 -1
  158. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  159. data/stdlib/rubygems/0/installer.rbs +13 -1
  160. data/stdlib/rubygems/0/path_support.rbs +4 -1
  161. data/stdlib/rubygems/0/platform.rbs +5 -1
  162. data/stdlib/rubygems/0/request_set.rbs +44 -2
  163. data/stdlib/rubygems/0/requirement.rbs +65 -2
  164. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  165. data/stdlib/rubygems/0/source_list.rbs +13 -0
  166. data/stdlib/rubygems/0/specification.rbs +21 -1
  167. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  168. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  169. data/stdlib/rubygems/0/version.rbs +60 -157
  170. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  171. data/stdlib/set/0/set.rbs +423 -109
  172. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  173. data/stdlib/singleton/0/singleton.rbs +20 -0
  174. data/stdlib/socket/0/addrinfo.rbs +210 -9
  175. data/stdlib/socket/0/basic_socket.rbs +103 -11
  176. data/stdlib/socket/0/ip_socket.rbs +31 -9
  177. data/stdlib/socket/0/socket.rbs +586 -38
  178. data/stdlib/socket/0/tcp_server.rbs +22 -2
  179. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  180. data/stdlib/socket/0/udp_socket.rbs +25 -2
  181. data/stdlib/socket/0/unix_server.rbs +22 -2
  182. data/stdlib/socket/0/unix_socket.rbs +45 -5
  183. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  184. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  185. data/stdlib/time/0/time.rbs +208 -116
  186. data/stdlib/timeout/0/timeout.rbs +10 -0
  187. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  188. data/stdlib/tsort/0/cyclic.rbs +1 -0
  189. data/stdlib/tsort/0/interfaces.rbs +1 -0
  190. data/stdlib/tsort/0/tsort.rbs +42 -0
  191. data/stdlib/uri/0/common.rbs +57 -8
  192. data/stdlib/uri/0/file.rbs +55 -109
  193. data/stdlib/uri/0/ftp.rbs +6 -3
  194. data/stdlib/uri/0/generic.rbs +558 -329
  195. data/stdlib/uri/0/http.rbs +60 -114
  196. data/stdlib/uri/0/https.rbs +8 -102
  197. data/stdlib/uri/0/ldap.rbs +143 -137
  198. data/stdlib/uri/0/ldaps.rbs +8 -102
  199. data/stdlib/uri/0/mailto.rbs +3 -0
  200. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  201. data/stdlib/uri/0/ws.rbs +6 -3
  202. data/stdlib/uri/0/wss.rbs +5 -3
  203. data/stdlib/yaml/0/dbm.rbs +151 -87
  204. data/stdlib/yaml/0/store.rbs +6 -0
  205. data/stdlib/zlib/0/zlib.rbs +90 -31
  206. metadata +18 -6
  207. data/lib/rbs/location.rb +0 -221
  208. data/sig/char_scanner.rbs +0 -9
@@ -0,0 +1,710 @@
1
+ %a{annotate:rdoc:skip}
2
+ class IO
3
+ # <!-- rdoc-file=io_buffer.c -->
4
+ # IO::Buffer is a low-level efficient buffer for input/output. There are three
5
+ # ways of using buffer:
6
+ #
7
+ # * Create an empty buffer with ::new, fill it with data using #copy or
8
+ # #set_value, #set_string, get data with #get_string;
9
+ # * Create a buffer mapped to some string with ::for, then it could be used
10
+ # both for reading with #get_string or #get_value, and writing (writing will
11
+ # change the source string, too);
12
+ # * Create a buffer mapped to some file with ::map, then it could be used for
13
+ # reading and writing the underlying file.
14
+ #
15
+ #
16
+ # Interaction with string and file memory is performed by efficient low-level C
17
+ # mechanisms like `memcpy`.
18
+ #
19
+ # The class is meant to be an utility for implementing more high-level
20
+ # mechanisms like Fiber::SchedulerInterface#io_read and
21
+ # Fiber::SchedulerInterface#io_write.
22
+ #
23
+ # **Examples of usage:**
24
+ #
25
+ # Empty buffer:
26
+ #
27
+ # buffer = IO::Buffer.new(8) # create empty 8-byte buffer
28
+ # # =>
29
+ # # #<IO::Buffer 0x0000555f5d1a5c50+8 INTERNAL>
30
+ # # ...
31
+ # buffer
32
+ # # =>
33
+ # # <IO::Buffer 0x0000555f5d156ab0+8 INTERNAL>
34
+ # # 0x00000000 00 00 00 00 00 00 00 00
35
+ # buffer.set_string('test', 2) # put there bytes of the "test" string, starting from offset 2
36
+ # # => 4
37
+ # buffer.get_string # get the result
38
+ # # => "\x00\x00test\x00\x00"
39
+ #
40
+ # Buffer from string:
41
+ #
42
+ # string = 'data'
43
+ # buffer = IO::Buffer.for(str)
44
+ # # =>
45
+ # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
46
+ # # ...
47
+ # buffer
48
+ # # =>
49
+ # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
50
+ # # 0x00000000 64 61 74 61 data
51
+ #
52
+ # buffer.get_string(2) # read content starting from offset 2
53
+ # # => "ta"
54
+ # buffer.set_string('---', 1) # write content, starting from offset 1
55
+ # # => 3
56
+ # buffer
57
+ # # =>
58
+ # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
59
+ # # 0x00000000 64 2d 2d 2d d---
60
+ # string # original string changed, too
61
+ # # => "d---"
62
+ #
63
+ # Buffer from file:
64
+ #
65
+ # File.write('test.txt', 'test data')
66
+ # # => 9
67
+ # buffer = IO::Buffer.map(File.open('test.txt'))
68
+ # # =>
69
+ # # #<IO::Buffer 0x00007f3f0768c000+9 MAPPED IMMUTABLE>
70
+ # # ...
71
+ # buffer.get_string(5, 2) # read 2 bytes, starting from offset 5
72
+ # # => "da"
73
+ # buffer.set_string('---', 1) # attempt to write
74
+ # # in `set_string': Buffer is not writable! (IO::Buffer::AccessError)
75
+ #
76
+ # # To create writable file-mapped buffer
77
+ # # Open file for read-write, pass size, offset, and flags=0
78
+ # buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 9, 0, 0)
79
+ # buffer.set_string('---', 1)
80
+ # # => 3 -- bytes written
81
+ # File.read('test.txt')
82
+ # # => "t--- data"
83
+ #
84
+ # **The class is experimental and the interface is subject to change.**
85
+ #
86
+ class Buffer
87
+ include Comparable
88
+
89
+ # <!--
90
+ # rdoc-file=io_buffer.c
91
+ # - IO::Buffer.for(string) -> io_buffer
92
+ # -->
93
+ # Creates a IO::Buffer from the given string's memory. The buffer remains
94
+ # associated with the string, and writing to a buffer will update the string's
95
+ # contents.
96
+ #
97
+ # Until #free is invoked on the buffer, either explicitly or via the garbage
98
+ # collector, the source string will be locked and cannot be modified.
99
+ #
100
+ # If the string is frozen, it will create a read-only buffer which cannot be
101
+ # modified.
102
+ #
103
+ # string = 'test'
104
+ # buffer = IO::Buffer.for(str)
105
+ # buffer.external? #=> true
106
+ #
107
+ # buffer.get_string(0, 1)
108
+ # # => "t"
109
+ # string
110
+ # # => "best"
111
+ #
112
+ # buffer.resize(100)
113
+ # # in `resize': Cannot resize external buffer! (IO::Buffer::AccessError)
114
+ #
115
+ def self.for: (String) -> Buffer
116
+
117
+ # <!--
118
+ # rdoc-file=io_buffer.c
119
+ # - IO::Buffer.map(file, [size, [offset, [flags]]]) -> io_buffer
120
+ # -->
121
+ # Create an IO::Buffer for reading from `file` by memory-mapping the file.
122
+ # `file_io` should be a `File` instance, opened for reading.
123
+ #
124
+ # Optional `size` and `offset` of mapping can be specified.
125
+ #
126
+ # By default, the buffer would be immutable (read only); to create a writable
127
+ # mapping, you need to open a file in read-write mode, and explicitly pass
128
+ # `flags` argument without IO::Buffer::IMMUTABLE.
129
+ #
130
+ # File.write('test.txt', 'test')
131
+ #
132
+ # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
133
+ # # => #<IO::Buffer 0x00000001014a0000+4 MAPPED READONLY>
134
+ #
135
+ # buffer.readonly? # => true
136
+ #
137
+ # buffer.get_string
138
+ # # => "test"
139
+ #
140
+ # buffer.set_string('b', 0)
141
+ # # `set_string': Buffer is not writable! (IO::Buffer::AccessError)
142
+ #
143
+ # # create read/write mapping: length 4 bytes, offset 0, flags 0
144
+ # buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 4, 0)
145
+ # buffer.set_string('b', 0)
146
+ # # => 1
147
+ #
148
+ # # Check it
149
+ # File.read('test.txt')
150
+ # # => "best"
151
+ #
152
+ # Note that some operating systems may not have cache coherency between mapped
153
+ # buffers and file reads.
154
+ #
155
+ def self.map: (File file, ?Integer? size, ?Integer offset, ?Integer flags) -> Buffer
156
+
157
+ public
158
+
159
+ # <!--
160
+ # rdoc-file=io_buffer.c
161
+ # - <=>(other) -> true or false
162
+ # -->
163
+ # Buffers are compared by size and exact contents of the memory they are
164
+ # referencing using `memcmp`.
165
+ #
166
+ def <=>: (Buffer) -> Integer
167
+
168
+ # <!--
169
+ # rdoc-file=io_buffer.c
170
+ # - clear(value = 0, [offset, [length]]) -> self
171
+ # -->
172
+ # Fill buffer with `value`, starting with `offset` and going for `length` bytes.
173
+ #
174
+ # buffer = IO::Buffer.for('test')
175
+ # # =>
176
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
177
+ # # 0x00000000 74 65 73 74 test
178
+ #
179
+ # buffer.clear
180
+ # # =>
181
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
182
+ # # 0x00000000 00 00 00 00 ....
183
+ #
184
+ # buf.clear(1) # fill with 1
185
+ # # =>
186
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
187
+ # # 0x00000000 01 01 01 01 ....
188
+ #
189
+ # buffer.clear(2, 1, 2) # fill with 2, starting from offset 1, for 2 bytes
190
+ # # =>
191
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
192
+ # # 0x00000000 01 02 02 01 ....
193
+ #
194
+ # buffer.clear(2, 1) # fill with 2, starting from offset 1
195
+ # # =>
196
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
197
+ # # 0x00000000 01 02 02 02 ....
198
+ #
199
+ def clear: (?Integer value, ?Integer offset, ?Integer length) -> self
200
+
201
+ # <!--
202
+ # rdoc-file=io_buffer.c
203
+ # - copy(source, [offset, [length, [source_offset]]]) -> size
204
+ # -->
205
+ # Efficiently copy data from a source IO::Buffer into the buffer, at `offset`
206
+ # using `memcpy`. For copying String instances, see #set_string.
207
+ #
208
+ # buffer = IO::Buffer.new(32)
209
+ # # =>
210
+ # # #<IO::Buffer 0x0000555f5ca22520+32 INTERNAL>
211
+ # # 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
212
+ # # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
213
+ #
214
+ # buffer.copy(IO::Buffer.for("test"), 8)
215
+ # # => 4 -- size of data copied
216
+ # buffer
217
+ # # =>
218
+ # # #<IO::Buffer 0x0000555f5cf8fe40+32 INTERNAL>
219
+ # # 0x00000000 00 00 00 00 00 00 00 00 74 65 73 74 00 00 00 00 ........test....
220
+ # # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
221
+ #
222
+ # #copy can be used to put data into strings associated with buffer:
223
+ #
224
+ # string= "data: "
225
+ # # => "data: "
226
+ # buffer = IO::Buffer.for(str)
227
+ # buffer.copy(IO::Buffer.for("test"), 5)
228
+ # # => 4
229
+ # string
230
+ # # => "data:test"
231
+ #
232
+ # Attempt to copy into a read-only buffer will fail:
233
+ #
234
+ # File.write('test.txt', 'test')
235
+ # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
236
+ # buffer.copy(IO::Buffer.for("test"), 8)
237
+ # # in `copy': Buffer is not writable! (IO::Buffer::AccessError)
238
+ #
239
+ # See ::map for details of creation of mutable file mappings, this will work:
240
+ #
241
+ # buffer = IO::Buffer.map(File.open('test.txt', 'r+'))
242
+ # buffer.copy("boom", 0)
243
+ # # => 4
244
+ # File.read('test.txt')
245
+ # # => "boom"
246
+ #
247
+ # Attempt to copy the data which will need place outside of buffer's bounds will
248
+ # fail:
249
+ #
250
+ # buffer = IO::Buffer.new(2)
251
+ # buffer.copy('test', 0)
252
+ # # in `copy': Specified offset+length exceeds source size! (ArgumentError)
253
+ #
254
+ def copy: (Buffer source, ?Integer offset, ?Integer length, ?Integer source_offset) -> Integer
255
+
256
+ # <!--
257
+ # rdoc-file=io_buffer.c
258
+ # - external? -> true or false
259
+ # -->
260
+ # If the buffer is _external_, meaning it references from memory which is not
261
+ # allocated or mapped by the buffer itself.
262
+ #
263
+ # A buffer created using ::for has an external reference to the string's
264
+ # memory.
265
+ #
266
+ # External buffer can't be resized.
267
+ #
268
+ def empty?: () -> bool
269
+
270
+ # <!--
271
+ # rdoc-file=io_buffer.c
272
+ # - external?()
273
+ # -->
274
+ #
275
+ def external?: () -> bool
276
+
277
+ # <!--
278
+ # rdoc-file=io_buffer.c
279
+ # - free -> self
280
+ # -->
281
+ # If the buffer references memory, release it back to the operating system.
282
+ # * for a *mapped* buffer (e.g. from file): unmap.
283
+ # * for a buffer created from scratch: free memory.
284
+ # * for a buffer created from string: undo the association.
285
+ #
286
+ #
287
+ # After the buffer is freed, no further operations can't be performed on it.
288
+ #
289
+ # buffer = IO::Buffer.for('test')
290
+ # buffer.free
291
+ # # => #<IO::Buffer 0x0000000000000000+0 NULL>
292
+ #
293
+ # buffer.get_value(:U8, 0)
294
+ # # in `get_value': The buffer is not allocated! (IO::Buffer::AllocationError)
295
+ #
296
+ # buffer.get_string
297
+ # # in `get_string': The buffer is not allocated! (IO::Buffer::AllocationError)
298
+ #
299
+ # buffer.null?
300
+ # # => true
301
+ #
302
+ # You can resize a freed buffer to re-allocate it.
303
+ #
304
+ def free: () -> self
305
+
306
+ # <!--
307
+ # rdoc-file=io_buffer.c
308
+ # - get_string([offset, [length, [encoding]]]) -> string
309
+ # -->
310
+ # Read a chunk or all of the buffer into a string, in the specified `encoding`.
311
+ # If no encoding is provided `Encoding::BINARY` is used.
312
+ #
313
+ # buffer = IO::Buffer.for('test')
314
+ # buffer.get_string
315
+ # # => "test"
316
+ # buffer.get_string(2)
317
+ # # => "st"
318
+ # buffer.get_string(2, 1)
319
+ # # => "s"
320
+ #
321
+ def get_string: (?Integer offset, ?Integer length, ?Encoding encoding) -> String
322
+
323
+ # <!--
324
+ # rdoc-file=io_buffer.c
325
+ # - get_value(type, offset) -> numeric
326
+ # -->
327
+ # Read from buffer a value of `type` at `offset`. `type` should be one of
328
+ # symbols:
329
+ #
330
+ # * `:U8`: unsigned integer, 1 byte
331
+ # * `:S8`: signed integer, 1 byte
332
+ # * `:u16`: unsigned integer, 2 bytes, little-endian
333
+ # * `:U16`: unsigned integer, 2 bytes, big-endian
334
+ # * `:s16`: signed integer, 2 bytes, little-endian
335
+ # * `:S16`: signed integer, 2 bytes, big-endian
336
+ # * `:u32`: unsigned integer, 4 bytes, little-endian
337
+ # * `:U32`: unsigned integer, 4 bytes, big-endian
338
+ # * `:s32`: signed integer, 4 bytes, little-endian
339
+ # * `:S32`: signed integer, 4 bytes, big-endian
340
+ # * `:u64`: unsigned integer, 8 bytes, little-endian
341
+ # * `:U64`: unsigned integer, 8 bytes, big-endian
342
+ # * `:s64`: signed integer, 8 bytes, little-endian
343
+ # * `:S64`: signed integer, 8 bytes, big-endian
344
+ # * `:f32`: float, 4 bytes, little-endian
345
+ # * `:F32`: float, 4 bytes, big-endian
346
+ # * `:f64`: double, 8 bytes, little-endian
347
+ # * `:F64`: double, 8 bytes, big-endian
348
+ #
349
+ #
350
+ # Example:
351
+ #
352
+ # string = [1.5].pack('f')
353
+ # # => "\x00\x00\xC0?"
354
+ # IO::Buffer.for(string).get_value(:f32, 0)
355
+ # # => 1.5
356
+ #
357
+ def get_value: (int_get_type, Integer offset) -> Integer
358
+ | (float_get_type, Integer offset) -> Float
359
+
360
+ type int_get_type = :U8 | :S8
361
+ | :u16 | :U16 | :s16 | :S16
362
+ | :u32 | :U32 | :s32 | :S32
363
+ | :u64 | :U64 | :s64 | :S64
364
+
365
+ type float_get_type = :f32 | :F32 | :f64 | :F64
366
+
367
+ # <!--
368
+ # rdoc-file=io_buffer.c
369
+ # - hexdump()
370
+ # -->
371
+ #
372
+ def hexdump: () -> String
373
+
374
+ # <!--
375
+ # rdoc-file=io_buffer.c
376
+ # - inspect()
377
+ # -->
378
+ #
379
+ def inspect: () -> String
380
+
381
+ # <!--
382
+ # rdoc-file=io_buffer.c
383
+ # - internal? -> true or false
384
+ # -->
385
+ # If the buffer is *internal*, meaning it references memory allocated by the
386
+ # buffer itself.
387
+ #
388
+ # An internal buffer is not associated with any external memory (e.g. string) or
389
+ # file mapping.
390
+ #
391
+ # Internal buffers are created using ::new and is the default when the requested
392
+ # size is less than the IO::Buffer::PAGE_SIZE and it was not requested to be
393
+ # mapped on creation.
394
+ #
395
+ # Internal buffers can be resized, and such an operation will typically
396
+ # invalidate all slices, but not always.
397
+ #
398
+ def internal?: () -> bool
399
+
400
+ # <!--
401
+ # rdoc-file=io_buffer.c
402
+ # - locked { ... }
403
+ # -->
404
+ # Allows to process a buffer in exclusive way, for concurrency-safety. While the
405
+ # block is performed, the buffer is considered locked, and no other code can
406
+ # enter the lock. Also, locked buffer can't be changed with #resize or #free.
407
+ #
408
+ # buffer = IO::Buffer.new(4)
409
+ # buffer.locked? #=> false
410
+ #
411
+ # Fiber.schedule do
412
+ # buffer.locked do
413
+ # buffer.write(io) # theoretical system call interface
414
+ # end
415
+ # end
416
+ #
417
+ # Fiber.schedule do
418
+ # # in `locked': Buffer already locked! (IO::Buffer::LockedError)
419
+ # buffer.locked do
420
+ # buffer.set_string(...)
421
+ # end
422
+ # end
423
+ #
424
+ # The following operations acquire a lock: #resize, #free.
425
+ #
426
+ # Locking is not thread safe. It is designed as a safety net around non-blocking
427
+ # system calls. You can only share a buffer between threads with appropriate
428
+ # synchronisation techniques.
429
+ #
430
+ def locked: [A] () { (IO::Buffer) -> A } -> A
431
+
432
+ # <!--
433
+ # rdoc-file=io_buffer.c
434
+ # - locked? -> true or false
435
+ # -->
436
+ # If the buffer is *locked*, meaning it is inside #locked block execution.
437
+ # Locked buffer can't be resized or freed, and another lock can't be acquired on
438
+ # it.
439
+ #
440
+ # Locking is not thread safe, but is a semantic used to ensure buffers don't
441
+ # move while being used by a system call.
442
+ #
443
+ # buffer.locked do
444
+ # buffer.write(io) # theoretical system call interface
445
+ # end
446
+ #
447
+ def locked?: () -> bool
448
+
449
+ # <!--
450
+ # rdoc-file=io_buffer.c
451
+ # - mapped? -> true or false
452
+ # -->
453
+ # If the buffer is *mapped*, meaning it references memory mapped by the buffer.
454
+ #
455
+ # Mapped buffers are either anonymous, if created by ::new with the
456
+ # IO::Buffer::MAPPED flag or if the size was at least IO::Buffer::PAGE_SIZE, or
457
+ # backed by a file if created with ::map.
458
+ #
459
+ # Mapped buffers can usually be resized, and such an operation will typically
460
+ # invalidate all slices, but not always.
461
+ #
462
+ def mapped?: () -> bool
463
+
464
+ # <!--
465
+ # rdoc-file=io_buffer.c
466
+ # - null? -> true or false
467
+ # -->
468
+ # If the buffer was freed with #free or was never allocated in the first place.
469
+ #
470
+ def null?: () -> bool
471
+
472
+ # <!--
473
+ # rdoc-file=io_buffer.c
474
+ # - pread(p1, p2, p3)
475
+ # -->
476
+ #
477
+ def pread: (untyped, untyped, untyped) -> untyped
478
+
479
+ # <!--
480
+ # rdoc-file=io_buffer.c
481
+ # - pwrite(p1, p2, p3)
482
+ # -->
483
+ #
484
+ def pwrite: (untyped, untyped, untyped) -> untyped
485
+
486
+ # <!--
487
+ # rdoc-file=io_buffer.c
488
+ # - read(p1, p2)
489
+ # -->
490
+ #
491
+ def read: (untyped, untyped) -> untyped
492
+
493
+ # <!--
494
+ # rdoc-file=io_buffer.c
495
+ # - readonly?()
496
+ # -->
497
+ #
498
+ def readonly?: () -> bool
499
+
500
+ # <!--
501
+ # rdoc-file=io_buffer.c
502
+ # - resize(new_size) -> self
503
+ # -->
504
+ # Resizes a buffer to a `new_size` bytes, preserving its content. Depending on
505
+ # the old and new size, the memory area associated with the buffer might be
506
+ # either extended, or rellocated at different address with content being copied.
507
+ #
508
+ # buffer = IO::Buffer.new(4)
509
+ # buffer.set_string("test", 0)
510
+ # buffer.resize(8) # resize to 8 bytes
511
+ # # =>
512
+ # # #<IO::Buffer 0x0000555f5d1a1630+8 INTERNAL>
513
+ # # 0x00000000 74 65 73 74 00 00 00 00 test....
514
+ #
515
+ # External buffer (created with ::for), and locked buffer can not be resized.
516
+ #
517
+ def resize: (Integer) -> self
518
+
519
+ # <!--
520
+ # rdoc-file=io_buffer.c
521
+ # - set_string(*args)
522
+ # -->
523
+ #
524
+ def set_string: (*untyped) -> untyped
525
+
526
+ # <!--
527
+ # rdoc-file=io_buffer.c
528
+ # - set_value(type, offset, value) -> offset
529
+ # -->
530
+ # Write to a buffer a `value` of `type` at `offset`. `type` should be one of
531
+ # symbols described in #get_value.
532
+ #
533
+ # buffer = IO::Buffer.new(8)
534
+ # # =>
535
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
536
+ # # 0x00000000 00 00 00 00 00 00 00 00
537
+ # buffer.set_value(:U8, 1, 111)
538
+ # # => 1
539
+ # buffer
540
+ # # =>
541
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
542
+ # # 0x00000000 00 6f 00 00 00 00 00 00 .o......
543
+ #
544
+ # Note that if the `type` is integer and `value` is Float, the implicit
545
+ # truncation is performed:
546
+ #
547
+ # buffer = IO::Buffer.new(8)
548
+ # buffer.set_value(:U32, 0, 2.5)
549
+ # buffer
550
+ # # =>
551
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
552
+ # # 0x00000000 00 00 00 02 00 00 00 00
553
+ # # ^^ the same as if we'd pass just integer 2
554
+ #
555
+ def set_value: (int_get_type | float_get_type, Integer offset, Float | Integer value) -> Integer
556
+
557
+ # <!--
558
+ # rdoc-file=io_buffer.c
559
+ # - size -> integer
560
+ # -->
561
+ # Returns the size of the buffer that was explicitly set (on creation with ::new
562
+ # or on #resize), or deduced on buffer's creation from string or file.
563
+ #
564
+ def size: () -> Integer
565
+
566
+ # <!--
567
+ # rdoc-file=io_buffer.c
568
+ # - slice(offset, length) -> io_buffer
569
+ # -->
570
+ # Produce another IO::Buffer which is a slice (or view into) the current one
571
+ # starting at `offset` bytes and going for `length` bytes.
572
+ #
573
+ # The slicing happens without copying of memory, and the slice keeps being
574
+ # associated with the original buffer's source (string, or file), if any.
575
+ #
576
+ # Raises RuntimeError if the <tt>offset+length<tt> is out of the current
577
+ # buffer's bounds.
578
+ #
579
+ # string = 'test'
580
+ # buffer = IO::Buffer.for(string)
581
+ #
582
+ # slice = buffer.slice(1, 2)
583
+ # # =>
584
+ # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
585
+ # # 0x00000000 65 73 es
586
+ #
587
+ # # Put "o" into 0s position of the slice
588
+ # slice.set_string('o', 0)
589
+ # slice
590
+ # # =>
591
+ # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
592
+ # # 0x00000000 6f 73 os
593
+ #
594
+ # # it is also visible at position 1 of the original buffer
595
+ # buffer
596
+ # # =>
597
+ # # #<IO::Buffer 0x00007fc3d31e2d80+4 SLICE>
598
+ # # 0x00000000 74 6f 73 74 tost
599
+ #
600
+ # # ...and original string
601
+ # string
602
+ # # => tost
603
+ #
604
+ def slice: (Integer offset, Integer length) -> Buffer
605
+
606
+ # <!--
607
+ # rdoc-file=io_buffer.c
608
+ # - to_s -> string
609
+ # -->
610
+ # Short representation of the buffer. It includes the address, size and symbolic
611
+ # flags. This format is subject to change.
612
+ #
613
+ # puts IO::Buffer.new(4) # uses to_s internally
614
+ # # #<IO::Buffer 0x000055769f41b1a0+4 INTERNAL>
615
+ #
616
+ def to_s: () -> String
617
+
618
+ # <!--
619
+ # rdoc-file=io_buffer.c
620
+ # - transfer -> new_io_buffer
621
+ # -->
622
+ # Transfers ownership to a new buffer, deallocating the current one.
623
+ #
624
+ # buffer = IO::Buffer.new('test')
625
+ # other = buffer.transfer
626
+ # other
627
+ # # =>
628
+ # # #<IO::Buffer 0x00007f136a15f7b0+4 SLICE>
629
+ # # 0x00000000 74 65 73 74 test
630
+ # buffer
631
+ # # =>
632
+ # # #<IO::Buffer 0x0000000000000000+0 NULL>
633
+ # buffer.null?
634
+ # # => true
635
+ #
636
+ def transfer: () -> Buffer
637
+
638
+ # <!--
639
+ # rdoc-file=io_buffer.c
640
+ # - valid? -> true or false
641
+ # -->
642
+ # Returns whether the buffer data is accessible.
643
+ #
644
+ # A buffer becomes invalid if it is a slice of another buffer which has been
645
+ # freed.
646
+ #
647
+ def valid?: () -> bool
648
+
649
+ # <!--
650
+ # rdoc-file=io_buffer.c
651
+ # - write(p1, p2)
652
+ # -->
653
+ #
654
+ def write: (untyped, untyped) -> untyped
655
+
656
+ private
657
+
658
+ # <!--
659
+ # rdoc-file=io_buffer.c
660
+ # - IO::Buffer.new([size = DEFAULT_SIZE, [flags = 0]]) -> io_buffer
661
+ # -->
662
+ # Create a new zero-filled IO::Buffer of `size` bytes. By default, the buffer
663
+ # will be *internal*: directly allocated chunk of the memory. But if the
664
+ # requested `size` is more than OS-specific IO::Bufer::PAGE_SIZE, the buffer
665
+ # would be allocated using the virtual memory mechanism (anonymous `mmap` on
666
+ # Unix, `VirtualAlloc` on Windows). The behavior can be forced by passing
667
+ # IO::Buffer::MAPPED as a second parameter.
668
+ #
669
+ # Examples
670
+ #
671
+ # buffer = IO::Buffer.new(4)
672
+ # # =>
673
+ # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
674
+ # # 0x00000000 00 00 00 00 ....
675
+ #
676
+ # buffer.get_string(0, 1) # => "\x00"
677
+ #
678
+ # buffer.set_string("test")
679
+ # buffer
680
+ # # =>
681
+ # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
682
+ # # 0x00000000 74 65 73 74 test
683
+ #
684
+ def initialize: (?Integer size, ?Integer flags) -> void
685
+
686
+ BIG_ENDIAN: Integer
687
+
688
+ DEFAULT_SIZE: Integer
689
+
690
+ EXTERNAL: Integer
691
+
692
+ HOST_ENDIAN: Integer
693
+
694
+ INTERNAL: Integer
695
+
696
+ LITTLE_ENDIAN: Integer
697
+
698
+ LOCKED: Integer
699
+
700
+ MAPPED: Integer
701
+
702
+ NETWORK_ENDIAN: Integer
703
+
704
+ PAGE_SIZE: Integer
705
+
706
+ PRIVATE: Integer
707
+
708
+ READONLY: Integer
709
+ end
710
+ end