mruby-io: reorder struct mrb_io to keep fd at offset 0

move fd, fd2, pid fields before the bitfield flags while keeping
the pointer field last. this preserves the 24-byte struct size
(same as 3.4.0) while restoring fd to offset 0 (same as 3.3.0).

some external gems (e.g. mruby-polarssl) pass struct mrb_io
pointers directly to libraries like mbedtls that expect an int fd
at offset 0. the 3.4.0 reorder moved bitfield flags to offset 0,
causing these gems to read garbage instead of the file descriptor.

fixes #6713

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-14 12:04:14 +09:00
parent cac1c99c6c
commit 12bc2cfaa1
+3 -3
View File
@@ -32,6 +32,9 @@ struct mrb_io_buf {
};
struct mrb_io {
int fd; /* file descriptor, or -1 */
int fd2; /* file descriptor to write if it's different from fd, or -1 */
int pid; /* child's pid (for pipes) */
unsigned int readable:1,
writable:1,
eof:1,
@@ -39,9 +42,6 @@ struct mrb_io {
is_socket:1,
close_fd:1,
close_fd2:1;
int fd; /* file descriptor, or -1 */
int fd2; /* file descriptor to write if it's different from fd, or -1 */
int pid; /* child's pid (for pipes) */
struct mrb_io_buf *buf;
};