@@ -84,37 +84,14 @@ typedef enum {
84
84
RUBY_IO_PRIORITY = RB_WAITFD_PRI, /* *< `IO::PRIORITY` */
85
85
} rb_io_event_t ;
86
86
87
- /* *
88
- * IO buffers. This is an implementation detail of ::rb_io_t::wbuf and
89
- * ::rb_io_t::rbuf. People don't manipulate it directly.
90
- */
91
- RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN ()
92
- struct rb_io_buffer_t {
93
-
94
- /* * Pointer to the underlying memory region, of at least `capa` bytes. */
95
- char *ptr; /* off + len <= capa */
96
-
97
- /* * Offset inside of `ptr`. */
98
- int off;
99
-
100
- /* * Length of the buffer. */
101
- int len;
102
-
103
- /* * Designed capacity of the buffer. */
104
- int capa;
105
- } RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END();
106
-
107
- /* * @alias{rb_io_buffer_t} */
108
- typedef struct rb_io_buffer_t rb_io_buffer_t ;
109
-
110
87
/* * Decomposed encoding flags (e.g. `"enc:enc2""`). */
111
88
/*
112
89
* enc enc2 read action write action
113
90
* NULL NULL force_encoding(default_external) write the byte sequence of str
114
91
* e1 NULL force_encoding(e1) convert str.encoding to e1
115
92
* e1 e2 convert from e2 to e1 convert str.encoding to e2
116
93
*/
117
- struct rb_io_enc_t {
94
+ struct rb_io_encoding {
118
95
/* * Internal encoding. */
119
96
rb_encoding *enc;
120
97
/* * External encoding. */
@@ -135,103 +112,10 @@ struct rb_io_enc_t {
135
112
VALUE ecopts;
136
113
};
137
114
138
- /* * Ruby's IO, metadata and buffers. */
139
- typedef struct rb_io_t {
140
-
141
- /* * The IO's Ruby level counterpart. */
142
- VALUE self;
143
-
144
- /* * stdio ptr for read/write, if available. */
145
- FILE *stdio_file;
146
-
147
- /* * file descriptor. */
148
- int fd;
149
-
150
- /* * mode flags: FMODE_XXXs */
151
- int mode;
152
-
153
- /* * child's pid (for pipes) */
154
- rb_pid_t pid;
155
-
156
- /* * number of lines read */
157
- int lineno;
158
-
159
- /* * pathname for file */
160
- VALUE pathv;
161
-
162
- /* * finalize proc */
163
- void (*finalize)(struct rb_io_t *,int );
164
-
165
- /* * Write buffer. */
166
- rb_io_buffer_t wbuf;
167
-
168
- /* *
169
- * (Byte) read buffer. Note also that there is a field called
170
- * ::rb_io_t::cbuf, which also concerns read IO.
171
- */
172
- rb_io_buffer_t rbuf;
173
-
174
- /* *
175
- * Duplex IO object, if set.
176
- *
177
- * @see rb_io_set_write_io()
178
- */
179
- VALUE tied_io_for_writing;
180
-
181
- struct rb_io_enc_t encs; /* *< Decomposed encoding flags. */
182
-
183
- /* * Encoding converter used when reading from this IO. */
184
- rb_econv_t *readconv;
185
-
186
- /* *
187
- * rb_io_ungetc() destination. This buffer is read before checking
188
- * ::rb_io_t::rbuf
189
- */
190
- rb_io_buffer_t cbuf;
191
-
192
- /* * Encoding converter used when writing to this IO. */
193
- rb_econv_t *writeconv;
194
-
195
- /* *
196
- * This is, when set, an instance of ::rb_cString which holds the "common"
197
- * encoding. Write conversion can convert strings twice... In case
198
- * conversion from encoding X to encoding Y does not exist, Ruby finds an
199
- * encoding Z that bridges the two, so that X to Z to Y conversion happens.
200
- */
201
- VALUE writeconv_asciicompat;
202
-
203
- /* * Whether ::rb_io_t::writeconv is already set up. */
204
- int writeconv_initialized;
115
+ struct rb_io ;
116
+ typedef struct rb_io rb_io_t ;
205
117
206
- /* *
207
- * Value of ::rb_io_t::rb_io_enc_t::ecflags stored right before
208
- * initialising ::rb_io_t::writeconv.
209
- */
210
- int writeconv_pre_ecflags;
211
-
212
- /* *
213
- * Value of ::rb_io_t::rb_io_enc_t::ecopts stored right before initialising
214
- * ::rb_io_t::writeconv.
215
- */
216
- VALUE writeconv_pre_ecopts;
217
-
218
- /* *
219
- * This is a Ruby level mutex. It avoids multiple threads to write to an
220
- * IO at once; helps for instance rb_io_puts() to ensure newlines right
221
- * next to its arguments.
222
- *
223
- * This of course doesn't help inter-process IO interleaves, though.
224
- */
225
- VALUE write_lock;
226
-
227
- /* *
228
- * The timeout associated with this IO when performing blocking operations.
229
- */
230
- VALUE timeout;
231
- } rb_io_t ;
232
-
233
- /* * @alias{rb_io_enc_t} */
234
- typedef struct rb_io_enc_t rb_io_enc_t ;
118
+ typedef struct rb_io_encoding rb_io_enc_t ;
235
119
236
120
/* *
237
121
* @private
@@ -331,7 +215,16 @@ typedef struct rb_io_enc_t rb_io_enc_t;
331
215
* Setting this one and #FMODE_BINMODE at the same time is a contradiction.
332
216
*/
333
217
#define FMODE_TEXTMODE 0x00001000
334
- /* #define FMODE_PREP 0x00010000 */
218
+ /* *
219
+ * This flag means that an IO object is wrapping an "external" file descriptor,
220
+ * which is owned by something outside the Ruby interpreter (usually a C extension).
221
+ * Ruby will not close this file when the IO object is garbage collected.
222
+ * If this flag is set, then IO#autoclose? is false, and vice-versa.
223
+ *
224
+ * This flag was previously called FMODE_PREP internally.
225
+ */
226
+ #define FMODE_EXTERNAL 0x00010000
227
+
335
228
/* #define FMODE_SIGNAL_ON_EPIPE 0x00020000 */
336
229
337
230
/* *
@@ -345,6 +238,18 @@ typedef struct rb_io_enc_t rb_io_enc_t;
345
238
346
239
/* * @} */
347
240
241
+ /* *
242
+ * Allocate a new IO object, with the given file descriptor.
243
+ */
244
+ VALUE rb_io_open_descriptor (VALUE klass, int descriptor, int mode, VALUE path, VALUE timeout, struct rb_io_encoding *encoding);
245
+
246
+ /* *
247
+ * Returns whether or not the underlying IO is closed.
248
+ *
249
+ * @return Whether the underlying IO is closed.
250
+ */
251
+ VALUE rb_io_closed_p (VALUE io);
252
+
348
253
/* *
349
254
* Queries the underlying IO pointer.
350
255
*
@@ -703,6 +608,12 @@ VALUE rb_io_set_write_io(VALUE io, VALUE w);
703
608
*/
704
609
void rb_io_set_nonblock (rb_io_t *fptr);
705
610
611
+ /* *
612
+ * Returns the path for the given IO.
613
+ *
614
+ */
615
+ VALUE rb_io_path (VALUE io);
616
+
706
617
/* *
707
618
* Returns an integer representing the numeric file descriptor for
708
619
* <em>io</em>.
@@ -712,6 +623,12 @@ void rb_io_set_nonblock(rb_io_t *fptr);
712
623
*/
713
624
int rb_io_descriptor (VALUE io);
714
625
626
+ /* *
627
+ * Get the mode of the IO.
628
+ *
629
+ */
630
+ int rb_io_mode (VALUE io);
631
+
715
632
/* *
716
633
* This function breaks down the option hash that `IO#initialize` takes into
717
634
* components. This is an implementation detail of rb_io_extract_modeenc()
0 commit comments