1939 Commits
Author SHA1 Message Date
Nobuyoshi Nakada 0c8ab2a111 [Bug #22311] Check the availability of APIs added in macOS 27
To account for cases where binaries for older OS versions are built
using the new SDK, check at runtime whether the API functions are
available actually.
2026-09-17 09:54:30 +09:00
Peter Zhu 52c54450f9 Don't use non blocking pipes for RUBY_CRASH_REPORT
[Bug #21703]

RUBY_CRASH_REPORT does not work in some cases when shelling out on Linux.
For example, given the following shell script dump.sh:

    #!/usr/bin/env bash
    cat > /tmp/crash

And we see it fails like this:

    $ RUBY_CRASH_REPORT="|dump.sh" ruby -rfiddle -e "Fiddle::Pointer.new(1, 10)[0]"
    cat: -: Resource temporarily unavailable
2026-09-17 09:54:30 +09:00
Hiroshi SHIBATA fecabc3145 Revert "merge revision(s) 190b017fc6: [Backport #21703]"
This reverts commit 83637aea6e.
2026-03-24 15:39:44 +09:00
Hiroshi SHIBATA 83637aea6e merge revision(s) 190b017fc6: [Backport #21703]
[PATCH] Don't use non blocking pipes for RUBY_CRASH_REPORT

	[Bug #21703]

	RUBY_CRASH_REPORT does not work in some cases when shelling out on Linux.
	For example, given the following shell script dump.sh:

	    #!/usr/bin/env bash
	    cat > /tmp/crash

	And we see it fails like this:

	    $ RUBY_CRASH_REPORT="|dump.sh" ruby -rfiddle -e "Fiddle::Pointer.new(1, 10)[0]"
	    cat: -: Resource temporarily unavailable
2026-03-24 14:49:12 +09:00
nagachika 30f661951b merge revision(s) 12350eb9e0: [Backport #21625]
[PATCH] [Bug #21625] Allow io/wait methods with `IO#ungetc` in text mode
2025-11-02 13:28:40 +09:00
nagachika 51dee044c1 merge revision(s) 5f77f9bea6: [Backport #21195]
Fix handling of `error`/`errno` in `io_internal_wait`. (#12961)

	[Bug #21195]
2025-03-30 12:11:59 +09:00
nagachika f85e5e01ba merge revision(s) f423f6e10c: [Backport #21131]
Ensure IO.copy_stream buffer is an independent string

	Otherwise, changes to the buffer by the destination write method
	could result in data changing for supposedly independent strings.

	Fixes [Bug #21131]
2025-03-16 20:35:27 +09:00
Takashi Kokubun 12a0807965 merge revision(s) 8034e9c3d0: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
2025-01-14 17:59:12 -08:00
Takashi Kokubun 00147cbab5 merge revision(s) e90b447655: [Backport #20924]
[Bug #20924] Fix reading with delimiter in wide character encodings
2025-01-14 17:53:38 -08:00
Takashi Kokubun 2330146397 merge revision(s) 773d140f65: [Backport #20787]
[Bug #20787] Check the separator in `IO#readline` as well as 3.2
2025-01-14 17:38:34 -08:00
Takashi Kokubun b77b5c1915 merge revision(s) 5e0c171451: [Backport #20169]
Make io_fwrite safe for compaction

	[Bug #20169]

	Embedded strings are not safe for system calls without the GVL because
	compaction can cause pages to be locked causing the operation to fail
	with EFAULT. This commit changes io_fwrite to use rb_str_tmp_frozen_no_embed_acquire,
	which guarantees that the return string is not embedded.
2024-05-28 14:22:45 -07:00
NARUSE, Yui 288d84d827 merge revision(s) 2554c5d3b8: [Backport #20231] (#9831)
Don't wait in `io_binwrite_string` if not necessary. (#9792)

	---
	 io.c | 8 +++-----
	 1 file changed, 3 insertions(+), 5 deletions(-)
2024-02-05 08:41:56 +00:00
Koichi Sasada beec3d07c9 MN: skip waiting on `read_nonblock'
if the IO for `IO#read_nonblock` is not ready, it needs
to return (or raise) immediately.
2023-12-23 08:10:41 +09:00
Koichi Sasada 7a0dfdea8c use rb_thread_io_blocking_call() more
use `rb_thread_io_blocking_call()` instead of
`rb_thread_io_blocking_region()` more.

See https://github.com/ruby/ruby/pull/9178#issuecomment-1858711533
2023-12-20 07:00:41 +09:00
Nobuyoshi Nakada e9b0b6015e [DOC] Add documents of constants for IO#wait event mask 2023-12-18 20:17:44 +09:00
Ryan Davis 6ecc1ca9b1 [DOC] Update ARGF.readlines documentation to match/reference IO.readlines. 2023-12-01 22:51:08 +00:00
Jean Boussier b013aae0c6 IO#read always check the provided buffer is mutable
Otherwise you can have work in some circumstance but not in others.
2023-11-09 11:45:02 +01:00
Charles Oliver NutterandNobuyoshi Nakada 55d954721e Raise TypeError for bad IO::Buffer.map argument (#8728)
* Raise TypeError when IO::Buffer.map argument is neither IO nor implements #fileno

* Use UNREACHABLE_CODE

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

* Use macro for undef check

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

---------

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-10-21 17:30:40 +13:00
Herwin cd0b8d2441 [DOC] Fix typo in docs of IO: #. -> $. 2023-10-04 23:02:08 +09:00
Aaron Patterson d3574c117a Move IO#readline to Ruby
This commit moves IO#readline to Ruby.  In order to call C functions,
keyword arguments must be converted to hashes.  Prior to this commit,
code like `io.readline(chomp: true)` would allocate a hash.  This
commits moves the keyword "denaturing" to Ruby, allowing us to send
positional arguments to the C API and avoiding the hash allocation.

Here is an allocation benchmark for the method:

```
x = GC.stat(:total_allocated_objects)
File.open("/usr/share/dict/words") do |f|
  f.readline(chomp: true) until f.eof?
end
p ALLOCATIONS: GC.stat(:total_allocated_objects) - x
```

Before this commit, the output was this:

```
$ make run
./miniruby -I./lib -I. -I.ext/common  -r./arm64-darwin22-fake  ./test.rb
{:ALLOCATIONS=>707939}
```

Now it is this:

```
$ make run
./miniruby -I./lib -I. -I.ext/common  -r./arm64-darwin22-fake  ./test.rb
{:ALLOCATIONS=>471962}
```

[Bug #19890] [ruby-core:114803]
2023-09-28 10:43:45 -07:00
Nobuyoshi Nakada 7e2775b057 Invoke the command when RUBY_BUGREPORT_PATH starts with | 2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada ab637cad2b [Bug #19624] Clean up backquote IO
It should not be hidden, since it can be grabbed by a fiber scheduler.
2023-09-21 10:23:14 +09:00
Nobuyoshi Nakada 72772a3caa [DOC] Mention "-" in ARGF 2023-09-17 22:05:58 +09:00
Herwin b926ac51cc [DOC] Fix a typo in "Open Options" section of IO
The word "and" was missing.
2023-09-10 19:33:48 +09:00
Herwin f867e936a9 [DOC] Fix layout in documentation of IO#fcntl 2023-09-03 01:49:40 +09:00
Jeremy Evans ae609a995e Document that Kernel#p is for debugging and may be uninterruptible [ci skip]
Fixes [Bug #18810]
2023-08-30 21:21:02 +01:00
Nobuyoshi Nakada 00ac3a64ba Introduce at_char_boundary function 2023-08-26 08:58:02 +09:00
Nobuyoshi Nakada 7d3634a121 Extract GC for fd parts as TRY_WITH_GC 2023-08-16 22:53:00 +09:00
Nobuyoshi Nakada f0edcd8283 Extract platform dependent part as fdopen_internal 2023-08-16 22:53:00 +09:00
BurdetteLamar 546c5cfe4c [DOC] Don't suppress autolinks 2023-08-12 13:04:04 -04:00
Mike Dalessio d2343368ab Deprecate Kernel#open and IO support for subprocess creation/forking
Deprecate Kernel#open and IO support for subprocess creation and
forking. This deprecates subprocess creation and forking in

- Kernel#open
- URI.open
- IO.binread
- IO.foreach
- IO.readlines
- IO.read
- IO.write

This behavior is slated to be removed in Ruby 4.0

[Feature #19630]
2023-08-10 09:38:11 +09:00
Nobuyoshi Nakada c8d0470bb0 Use File::NULL instead of hard coded null device names 2023-07-10 19:21:47 +09:00
Burdette Lamar 6528cf9fcf [DOC] Fixes for link fragments (#7981) 2023-06-28 09:05:43 -04:00
Nobuyoshi Nakada 46583f7dcf Adjust style [ci skip] 2023-06-07 10:10:08 +09:00
Samuel Williams b7ee51e81d Expose enum rb_io_event flags without _t suffix. (#7887) 2023-06-01 22:54:08 +09:00
Samuel Williams 47a8de6095 Drop _t suffix from struct names. (#7886)
POSIX reserves `_t` suffix in types.
2023-06-01 21:46:10 +09:00
KJ Tsanaktsidis edee9b6a12 Use a real Ruby mutex in rb_io_close_wait_list (#7884)
Because a thread calling IO#close now blocks in a native condvar wait,
it's possible for there to be _no_ threads left to actually handle
incoming signals/ubf calls/etc.

This manifested as failing tests on Solaris 10 (SPARC), because:

* One thread called IO#close, which sent a SIGVTALRM to the other
  thread to interrupt it, and then waited on the condvar to be notified
  that the reading thread was done.
* One thread was calling IO#read, but it hadn't yet reached the actual
  call to select(2) when the SIGVTALRM arrived, so it never unblocked
  itself.

This results in a deadlock.

The fix is to use a real Ruby mutex for the close lock; that way, the
closing thread goes into sigwait-sleep and can keep trying to interrupt
the select(2) thread.

See the discussion in: https://github.com/ruby/ruby/pull/7865/
2023-06-01 17:37:18 +09:00
Samuel Williams a218ed5692 Hide the usage of rb_io_t where possible. (#7880)
This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility.
2023-06-01 14:23:30 +09:00
NARUSE, Yui 85dcc4866d Revert "Hide most of the implementation of struct rb_io. (#6511)"
This reverts commit 18e55fc1e1.

fix [Bug #19704]
https://bugs.ruby-lang.org/issues/19704
This breaks compatibility for extension libraries. Such changes
need a discussion.
2023-06-01 08:43:22 +09:00
Samuel WilliamsandKJ Tsanaktsidis 18e55fc1e1 Hide most of the implementation of struct rb_io. (#6511)
* Add rb_io_path and rb_io_open_descriptor.

* Use rb_io_open_descriptor to create PTY objects

* Rename FMODE_PREP -> FMODE_EXTERNAL and expose it

FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but
FMODE_EXTERNAL is clearer about what the file descriptor represents and
aligns with language in the IO::Buffer module.

* Ensure that rb_io_open_descriptor closes the FD if it fails

If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be
responsible for closing your file, eventually, if you pass it to
rb_io_open_descriptor, even if it raises an exception.

* Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P

* Expose `rb_io_closed_p`.

* Add `rb_io_mode` to get IO mode.

---------

Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
2023-05-30 10:02:40 +09:00
Samuel Williams bf1bc5362e Improve read/write/pread/pwrite consistency. (#7860)
* Documentation consistency.

* Improve consistency of `pread`/`pwrite` implementation when given length.

* Remove HAVE_PREAD / HAVE_PWRITE - it is no longer optional.
2023-05-27 18:48:47 +09:00
KJ Tsanaktsidis 66871c5a06 Fix busy-loop when waiting for file descriptors to close
When one thread is closing a file descriptor whilst another thread is
concurrently reading it, we need to wait for the reading thread to be
done with it to prevent a potential EBADF (or, worse, file descriptor
reuse).

At the moment, that is done by keeping a list of threads still using the
file descriptor in io_close_fptr. It then continually calls
rb_thread_schedule() in fptr_finalize_flush until said list is empty.

That busy-looping seems to behave rather poorly on some OS's,
particulary FreeBSD. It can cause the TestIO#test_race_gets_and_close
test to fail (even with its very long 200 second timeout) because the
closing thread starves out the using thread.

To fix that, I introduce the concept of struct rb_io_close_wait_list; a
list of threads still using a file descriptor that we want to close. We
call `rb_notify_fd_close` to let the thread scheduler know we're closing
a FD, which fills the list with threads. Then, we call
rb_notify_fd_close_wait which will block the thread until all of the
still-using threads are done.

This is implemented with a condition variable sleep, so no busy-looping
is required.
2023-05-26 14:51:23 +09:00
Samuel Williams 0b2613f443 rb_io_puts should not write zero length strings. (#7806) 2023-05-15 11:13:51 +09:00
Nobuyoshi Nakada 814f52a9eb [Bug #19624] Hide internal IO for backquote 2023-05-01 05:10:34 +09:00
Nobuyoshi Nakada 86db7a1cb8 [DOC] Fix typos 2023-04-13 13:28:47 +09:00
Nobuyoshi Nakada e13575bb79 [Bug #19584] Register global variables before assignment 2023-04-07 11:53:36 +09:00
Matt Valentine-House 026321c5b9 [Feature #19474] Refactor NEWOBJ macros
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec
2023-04-06 11:07:16 +01:00
Samuel Williams 648870b5c5 Support IO#pread / IO#pwrite using fiber scheduler. (#7594)
* Skip test if non-blocking file IO is not supported.
2023-03-31 00:48:55 +13:00
Jeremy Evans 6c60006de5 Raise ArgumentError if IO.read is provided negative offset
Fixes [Bug #19380]
2023-03-24 12:29:00 -07:00
Lars Kanis 47f8bf50e1 [DOC] Clarify IO#autoclose impact on #close
Mention that autoclose changes the behavior of explicit close in addition to implicit close at IO finalization.
2023-03-01 16:02:11 +09:00