27 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 6f202d6c2b mruby-io: use mrb_int consistently in IO HAL interface
Replace all int64_t, uint64_t, uint32_t, and int32_t with mrb_int
in the HAL struct, timeval, and function signatures. All values
originate from or end up as mrb_int at the Ruby layer. Also removes
dead overflow checks in callers and the stdint.h dependency from
io_hal.h.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:35 +09:00
Yukihiro "Matz" Matsumoto b70c393039 mruby-io: use mrb_int for mrb_hal_io_readlink() return type
int64_t was unnecessary; readlink(2) returns ssize_t (bounded by
PATH_MAX), and the Windows HAL just raises NotImplementedError.

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-23 19:25:35 +09:00
Yukihiro "Matz" Matsumoto 12bc2cfaa1 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>
2026-02-14 12:05:20 +09:00
Yukihiro "Matz" Matsumoto 2813f794a2 mruby-io: rename mruby/ext/io.h to mruby/io.h
Simplify the header path to be consistent with mruby/time.h.
The ext/ subdirectory was unnecessary.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:11 +09:00
Yukihiro "Matz" Matsumoto 610ff67906 HAL: rename functions to mrb_hal_<feature>_<name> convention
rename all HAL functions from mrb_<feature>_hal_<name>() to
mrb_hal_<feature>_<name>() for better grouping and clarity. this makes all
HAL functions immediately identifiable with the mrb_hal_* prefix.

affected gems:
- mruby-task: mrb_task_hal_* -> mrb_hal_task_*
- mruby-io: mrb_io_hal_* -> mrb_hal_io_*
- mruby-socket: mrb_socket_hal_* -> mrb_hal_socket_*
- mruby-dir: mrb_dir_hal_* -> mrb_hal_dir_*

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 09:59:03 +09:00
Yukihiro "Matz" Matsumoto 74ca22f281 mruby-io: introduce HAL for platform abstraction
separates platform-specific code into hal-posix-io and hal-win-io gems,
making mruby-io platform-independent. HAL interface defined in
mrbgems/mruby-io/include/io_hal.h covers file operations, I/O operations,
and process operations. follows mruby-task dependency pattern where HAL
gems depend on feature gem. ws2_32 library linked in hal-win-io gem.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-15 11:53:38 +09:00
dearblue ce1abfb2c9 Change MRB_WITH_IO_PREAD_PWRITE configuration name
Change to `MRB_USE_IO_PREAD_PWRITE` for consistency with mruby configuration macros.
Similarly, `MRB_WITHOUT_IO_PREAD_PWRITE` is changed to `MRB_NO_IO_PREAD_PWRITE`.

The previous names are available for compatibility but are deprecated.
2024-12-12 22:18:34 +09:00
dearblue 384db9054d Suppress presym in mruby/ext/io.h file
When defining macro constants for error classes in public header files, it is preferable to use `MRB_ERROR_SYM()`.
2024-12-09 22:05:01 +09:00
Yukihiro "Matz" Matsumoto 492d8331e1 mruby-io/ext/io.h: reorder struct mrb_io to reduce the size; #6231
The `sizeof(struct mrb_io)` is reduced from 32 bytes to 24 bytes on
x86_64-linux.
2024-04-10 13:35:03 +09:00
Asmod4n 96b5cd757d Add a way to let other gems handle closing of FDs 2024-04-07 13:46:11 +02:00
dearblue 5caf8e14cf Retrieving the IO exception class with presym 2024-01-20 22:33:43 +09:00
Yukihiro "Matz" Matsumoto 91727f38de mruby-io/io.c: change the implementation of read buffers
The original implementations used plain Ruby strings referenced from
instance variable (`@buf`) as buffers. We replaced those buffers by C
structure (`struct mrb_io_buf`) referenced directly from `fptr`.

The result is significant improvement of both performance and memory
consumption. Our simple benchmarks (reading `README.md` 10,000 times)
runs 5+ times faster, and `mrbtest` test suites consumes 85% less
memory.

Recent changes on `mruby-io` is preparation for this improvement.
2023-01-09 10:18:35 +09:00
Yukihiro "Matz" Matsumoto 1bc0be3e43 mruby-io/io.c: implement IO#eof? in C 2023-01-05 19:50:14 +09:00
Yukihiro "Matz" Matsumoto 5401d95017 mruby-io/ext/io.h: remove unused macros 2022-12-29 11:22:37 +09:00
Yukihiro "Matz" Matsumoto 5d37160455 Use MRB_SYM() more extensively. 2021-02-26 15:05:55 +09:00
KOBAYASHI Shuji 3d056d084a Rename MRB_{ENABLE,DISABLE}_ to MRB_{USE,NO}_; close #5163
|        Previous Name         |        New Name         |
|------------------------------|-------------------------|
| MRB_ENABLE_ALL_SYMBOLS       | MRB_USE_ALL_SYMBOLS     |
| MRB_ENABLE_SYMBOLL_ALL       | MRB_USE_ALL_SYMBOLS     |
| MRB_ENABLE_CXX_ABI           | MRB_USE_CXX_ABI         |
| MRB_ENABLE_CXX_EXCEPTION     | MRB_USE_CXX_EXCEPTION   |
| MRB_ENABLE_DEBUG_HOOK        | MRB_USE_DEBUG_HOOK      |
| MRB_DISABLE_DIRECT_THREADING | MRB_NO_DIRECT_THREADING |
| MRB_DISABLE_STDIO            | MRB_NO_STDIO            |
| ENABLE_LINENOISE             | MRB_USE_LINENOISE       |
| ENABLE_READLINE              | MRB_USE_READLINE        |
| DISABLE_MIRB_UNDERSCORE      | MRB_NO_MIRB_UNDERSCORE  |
| DISABLE_GEMS                 | MRB_NO_GEMS             |

* `MRB_ENABLE_SYMBOLL_ALL` seems to be a typo, so it is fixed.
* `MRB_` prefix is added to those without.
* The previous names can also be used for compatibility.
2020-11-21 21:14:40 +09:00
Yukihiro "Matz" Matsumoto 33742d941f Move build_config.rb -> build_config/default.rb; ref #5098
In addition, update the documents referring `build_config.rb` which is
no longer used. The new `build_config.rb` describes the new configuration
structure in the comment.
2020-10-29 11:49:05 +09:00
Yukihiro "Matz" Matsumoto 49d97d6051 Add pread/pwrite support on __MACH__ (MacOS) in addition to __unix__. 2020-05-15 12:31:18 +09:00
dearblue 095aae5e2c Removed comments mentioning MRB_WITHOUT_FLOAT; ref 2e661e8
The comment is for messages when `MRB_INT16` and `MRB_WITHOUT_FLOAT` are
specified at the same time.
The comment itself is no longer needed now that `MRB_INT16` is gone.
2020-04-24 21:47:20 +09:00
Yukihiro "Matz" Matsumoto 2e661e82d1 Removed comments mentioning MRB_INT16. 2020-04-21 20:47:22 +09:00
dearblue 67606170e3 Add configuration guard for MRB_DISABLE_STDIO
ref #4576 and ref #4947

* Need MRBAPI functions without `MRB_DISABLE_STDIO`:
  * mrbgems/mruby-bin-debugger
  * mrbgems/mruby-bin-mirb
  * mrbgems/mruby-bin-mrbc
  * mrbgems/mruby-bin-mruby
  * mrbgems/mruby-bin-strip
* Need `stdio.h`:
  * mrbgems/mruby-io
  * mrbgems/mruby-print
* Need `snprintf()` in `stdio.h`:
  * mrbgems/mruby-pack
  * mrbgems/mruby-sprintf
2020-03-08 21:57:17 +09:00
dearblue 4c6d524c47 Implement IO#pread and IO#pwrite
It is available by default in environments where `__unix__` is defined.
Other environments are enabled by defining `MRB_WITH_IO_PREAD_PWRITE`
(requires an implementation of `pread()` and `pwrite()` functions).

In any case, you can disable it by defining
`MRB_WITHOUT_IO_PREAD_PWRITE`.
2020-02-02 21:20:25 +09:00
Yukihiro "Matz" Matsumoto e7e999414c Merge pull request #4873 from dearblue/open-flags
Support bit flags for `IO.open`
2020-01-28 11:09:33 +09:00
Yukihiro "Matz" Matsumoto b545f62aeb Avoid Boxing/Unboxing of file descriptors; ref #4872 2020-01-06 18:57:43 +09:00
dearblue 69619aeeb1 Support bit flags for IO.open
Note that this bit flags are not compatible with the native flags
defined in `#include <fcntl.h>`.
2019-12-14 15:19:13 +09:00
Takeshi Watanabe 949bf6ca43 Fix socket closing by using closesocket API in windows instead. 2017-12-14 00:05:23 +09:00
Yukihiro "Matz" Matsumoto d75266dd1b Add 'mrbgems/mruby-io/' from commit '3c8e1f94c44252c836f79a48bb17726da28e2756'
git-subtree-dir: mrbgems/mruby-io
git-subtree-mainline: 10ed730e4b
git-subtree-split: 3c8e1f94c4
2017-12-07 18:11:06 +09:00