summaryrefslogtreecommitdiff
path: root/io.c
AgeCommit message (Collapse)Author
2023-06-07Adjust style [ci skip]Nobuyoshi Nakada
2023-06-01Expose `enum rb_io_event` flags without `_t` suffix. (#7887)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-06-01Drop `_t` suffix from struct names. (#7886)Samuel Williams
POSIX reserves `_t` suffix in types. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-06-01Use a real Ruby mutex in rb_io_close_wait_list (#7884)KJ Tsanaktsidis
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/ Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-06-01Hide the usage of `rb_io_t` where possible. (#7880)Samuel Williams
This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-06-01Revert "Hide most of the implementation of `struct rb_io`. (#6511)"NARUSE, Yui
This reverts commit 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2. fix [Bug #19704] https://bugs.ruby-lang.org/issues/19704 This breaks compatibility for extension libraries. Such changes need a discussion.
2023-05-30Hide most of the implementation of `struct rb_io`. (#6511)Samuel Williams
* 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> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-05-27Improve `read`/`write`/`pread`/`pwrite` consistency. (#7860)Samuel Williams
* Documentation consistency. * Improve consistency of `pread`/`pwrite` implementation when given length. * Remove HAVE_PREAD / HAVE_PWRITE - it is no longer optional. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-05-26Fix busy-loop when waiting for file descriptors to closeKJ Tsanaktsidis
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. Notes: Merged: https://github.com/ruby/ruby/pull/7865
2023-05-15`rb_io_puts` should not write zero length strings. (#7806)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-05-01[Bug #19624] Hide internal IO for backquoteNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7776
2023-04-13[DOC] Fix typosNobuyoshi Nakada
2023-04-07[Bug #19584] Register global variables before assignmentNobuyoshi Nakada
2023-04-06[Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House
NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec Notes: Merged: https://github.com/ruby/ruby/pull/7393
2023-03-31Support `IO#pread` / `IO#pwrite` using fiber scheduler. (#7594)Samuel Williams
* Skip test if non-blocking file IO is not supported. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-03-24Raise ArgumentError if IO.read is provided negative offsetJeremy Evans
Fixes [Bug #19380] Notes: Merged: https://github.com/ruby/ruby/pull/7289
2023-03-01[DOC] Clarify IO#autoclose impact on #closeLars Kanis
Mention that autoclose changes the behavior of explicit close in addition to implicit close at IO finalization. Notes: Merged: https://github.com/ruby/ruby/pull/5647
2023-02-28Fix spelling (#7405)John Bampton
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2023-02-26Adjust `else` style to be consistent in each files [ci skip]Nobuyoshi Nakada
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-19[DOC] Document IO::Timeoutzverok
Notes: Merged: https://github.com/ruby/ruby/pull/7316
2023-01-01Make IO#set_encoding with binary external encoding use nil internal encodingJeremy Evans
This was already the behavior when a single `'external:internal'` encoding specifier string was passed. This makes the behavior consistent for the case where separate external and internal encoding specifiers are provided. While here, fix the IO#set_encoding method documentation to state that either the first or second argument can be a string with an encoding name, and describe the behavior when the external encoding is binary. Fixes [Bug #18899] Notes: Merged: https://github.com/ruby/ruby/pull/6280
2022-12-23Docs: path: option for IO.newzverok
Notes: Merged: https://github.com/ruby/ruby/pull/6985
2022-12-22[DOC] IO#read doesn't always read in binary modeAlan Wu
When `maxlen` is `nil`, it uses the data mode of the stream. For example in the following: ```ruby File.binwrite("a.txt", "\r\n\r") p File.open("a.txt", "rt").read # "\n\n" p File.open("a.txt", "rt").read(3) # "\r\n\r" ``` Note, this newline translation is _not_ specific to Windows. Notes: Merged: https://github.com/ruby/ruby/pull/6982 Merged-By: XrXr
2022-12-08Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-12-02io.c (read_all): grow the buffer exponentially when size is unknownJean Boussier
[Feature #6047] Currently it's grown by `BUFSIZ` (1024) on every iteration which is bit wasteful. Instead we can double the capacity whenever there is less than `BUFSIZ` capacity left. Notes: Merged: https://github.com/ruby/ruby/pull/6829
2022-12-02Introduce encoding check macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6700
2022-12-02Introduce argf_encoding functionS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6672
2022-12-02Reuse NIL_OR_UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6787
2022-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-11-09[DOC] Enhanced RDoc for IO (#6669)Burdette Lamar
Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-10-29[DOC] Enhanced RDOc for IO (#6642)Burdette Lamar
In io.c treats: #close #close_read #close_write #closed Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-10-15Update `Fiber::Scheduler` documentation. (#6562)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-15Introduce `Fiber::Scheduler#io_select` hook for non-blocking `IO.select`. ↵Samuel Williams
(#6559) Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-15Copy `IO#timeout` on `IO#dup`. (#6546)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-11Ignore failure to set nonblock mode. (#6524)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-08Try `nil` as default for 'default timeout'. (#6509)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-07Add IO#timeout attribute and use it for blocking IO operations. (#5653)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-06[DOC] Integrate io_streams.rdoc into io.c (#6491)Burdette Lamar
Integrate io_streams.rdoc into io.c Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-10-02[DOC] RDoc changes for IO (#6458)Burdette Lamar
Moves Expect library doc into io.c. Changes certain links to local sections, now pointing to sections in doc/io_streams.rdoc. Removes local sections now superseded by sections in doc/io_streams.rdoc. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2022-09-16[ci skip] Fix typos in documentation in io.cPeter Zhu
2022-09-11[Win32] Negative length `IO#sysread`Jeremy Bopp
Raise `ArgumentError` in `IO#sysread` on Windows when given a negative length. Fixes [Bug #18880] Notes: Merged: https://github.com/ruby/ruby/pull/6354 Merged-By: nobu <nobu@ruby-lang.org>
2022-09-08[Bug #5317] Use `rb_off_t` instead of `off_t`Nobuyoshi Nakada
Get rid of the conflict with system-provided small `off_t`. Notes: Merged: https://github.com/ruby/ruby/pull/6329
2022-08-25Raise ArgumentError for IO.foreach with limit of 0Jeremy Evans
Makes behavior consistent with IO.readlines. Fixes [Bug #18767] Notes: Merged: https://github.com/ruby/ruby/pull/5954
2022-08-05[DOC] Mention Windows text mode EOF marker interpretationAlan Wu
I don't think this is super well known so it's worth mentioning as it can be a pitfall. See: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-170 Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/6212
2022-08-05[DOC] Clarify that `IO.read` uses text modeAlan Wu
See: https://bugs.ruby-lang.org/issues/18882#note-13 [Bug #18882] Notes: Merged: https://github.com/ruby/ruby/pull/6212
2022-07-28[DOC] Cross references for `ARGF`Nobuyoshi Nakada
2022-07-27Fix documentation for ARGF.inplace_mode{,=}Jeremy Evans
The value affects the name of the backup file created, not the name of the file modified (as the file is modified in place). Fixes [Bug #18920]
2022-07-27Adjust styles [ci skip]Nobuyoshi Nakada
2022-07-23[DOC] IO#eofKaíque Kandy Koga
Use IO#eof? instead of I#eof? Notes: Merged: https://github.com/ruby/ruby/pull/6172