Ruby: internal/io.h Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

io.h
1#ifndef INTERNAL_IO_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_IO_H
11#include "ruby/ruby.h" /* for VALUE */
12
13#define HAVE_RB_IO_T
14struct rb_io;
15
16#include "ruby/io.h" /* for rb_io_t */
17#include "ccan/list/list.h"
18#include "serial.h"
19
20#define IO_WITHOUT_GVL(func, arg) rb_nogvl(func, arg, RUBY_UBF_IO, 0, RB_NOGVL_OFFLOAD_SAFE)
21#define IO_WITHOUT_GVL_INT(func, arg) (int)(VALUE)IO_WITHOUT_GVL(func, arg)
22
23// Represents an in-flight blocking operation:
24 struct rb_io_blocking_operation {
25 // The linked list data structure.
26 struct ccan_list_node list;
27
28 // The execution context of the blocking operation.
29 struct rb_execution_context_struct *ec;
30};
31
33struct rb_io {
34
36 VALUE self;
37
39 FILE *stdio_file;
40
42 int fd;
43
45 enum rb_io_mode mode;
46
48 rb_pid_t pid;
49
51 int lineno;
52
54 VALUE pathv;
55
57 void (*finalize)(struct rb_io*,int);
58
60 rb_io_buffer_t wbuf;
61
66 rb_io_buffer_t rbuf;
67
73 VALUE tied_io_for_writing;
74
75 struct rb_io_encoding encs;
76
78 rb_econv_t *readconv;
79
84 rb_io_buffer_t cbuf;
85
87 rb_econv_t *writeconv;
88
95 VALUE writeconv_asciicompat;
96
98 int writeconv_initialized;
99
104 int writeconv_pre_ecflags;
105
110 VALUE writeconv_pre_ecopts;
111
119 VALUE write_lock;
120
124 VALUE timeout;
125
131 struct ccan_list_head blocking_operations;
132 struct rb_execution_context_struct *closing_ec;
133 VALUE wakeup_mutex;
134
135 // The fork generation of the blocking operations list.
136 rb_serial_t fork_generation;
137};
138
139/* io.c */
140void ruby_set_inplace_mode(const char *);
141void rb_stdio_set_default_encoding(void);
142 VALUE rb_io_flush_raw(VALUE, int);
143size_t rb_io_memsize(const rb_io_t *);
144int rb_stderr_tty_p(void);
145 VALUE rb_io_popen(VALUE pname, VALUE pmode, VALUE env, VALUE opt);
146
147 VALUE rb_io_prep_stdin(void);
148 VALUE rb_io_prep_stdout(void);
149 VALUE rb_io_prep_stderr(void);
150
151int rb_io_notify_close(struct rb_io *fptr);
152
153RUBY_SYMBOL_EXPORT_BEGIN
154/* io.c (export) */
155void rb_maygvl_fd_fix_cloexec(int fd);
156int rb_gc_for_fd(int err);
157void rb_write_error_str(VALUE mesg);
158
159 VALUE rb_io_blocking_region_wait(struct rb_io *io, rb_blocking_function_t *function, void *argument, enum rb_io_event events);
160 VALUE rb_io_blocking_region(struct rb_io *io, rb_blocking_function_t *function, void *argument);
161RUBY_SYMBOL_EXPORT_END
162
163#endif /* INTERNAL_IO_H */
io.h
rb_io_event
rb_io_event
Type of events that an IO can wait.
Definition io.h:96
rb_io_buffer_t
struct rb_io_internal_buffer rb_io_buffer_t
Just another name of rb_io_buffer_t.
Definition io.h:125
ruby.h
rb_econv_t
Definition transcode.c:132
rb_execution_context_struct
Definition vm_core.h:1034
rb_io_blocking_operation
Definition io.h:24
rb_io_encoding
Decomposed encoding flags (e.g.
Definition io.h:134
rb_io
Ruby's IO, metadata and buffers.
Definition io.h:295
rb_io::wbuf
rb_io_buffer_t wbuf
Write buffer.
Definition io.h:330
rb_io::mode
enum rb_io_mode mode
mode flags: FMODE_XXXs
Definition io.h:310
rb_io::finalize
void(* finalize)(struct rb_io *, int)
finalize proc
Definition io.h:326
rb_io::readconv
rb_econv_t * readconv
Encoding converter used when reading from this IO.
Definition io.h:352
rb_io::writeconv
rb_econv_t * writeconv
Encoding converter used when writing to this IO.
Definition io.h:363
rb_io::encs
struct rb_io_encoding encs
Decomposed encoding flags.
Definition io.h:348
rb_io::self
VALUE self
The IO's Ruby level counterpart.
Definition io.h:298
rb_io::write_lock
VALUE write_lock
This is a Ruby level mutex.
Definition io.h:400
rb_io::timeout
VALUE timeout
The timeout associated with this IO when performing blocking operations.
Definition io.h:406
rb_io::stdio_file
FILE * stdio_file
stdio ptr for read/write, if available.
Definition io.h:302
rb_io::writeconv_pre_ecopts
VALUE writeconv_pre_ecopts
Value of rb_io_t::rb_io_enc_t::ecopts stored right before initialising rb_io_t::writeconv.
Definition io.h:390
rb_io::tied_io_for_writing
VALUE tied_io_for_writing
Duplex IO object, if set.
Definition io.h:345
rb_io::writeconv_initialized
int writeconv_initialized
Whether rb_io_t::writeconv is already set up.
Definition io.h:376
rb_io::fd
int fd
file descriptor.
Definition io.h:306
rb_io::rbuf
rb_io_buffer_t rbuf
(Byte) read buffer.
Definition io.h:337
rb_io::lineno
int lineno
number of lines read
Definition io.h:318
rb_io::blocking_operations
struct ccan_list_head blocking_operations
Threads that are performing a blocking operation without the GVL using this IO.
Definition io.h:131
rb_io::writeconv_asciicompat
VALUE writeconv_asciicompat
This is, when set, an instance of rb_cString which holds the "common" encoding.
Definition io.h:372
rb_io::cbuf
rb_io_buffer_t cbuf
rb_io_ungetc() destination.
Definition io.h:359
rb_io::pid
rb_pid_t pid
child's pid (for pipes)
Definition io.h:314
rb_io::writeconv_pre_ecflags
int writeconv_pre_ecflags
Value of rb_io_t::rb_io_enc_t::ecflags stored right before initialising rb_io_t::writeconv.
Definition io.h:383
rb_io::pathv
VALUE pathv
pathname for file
Definition io.h:322
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40