summaryrefslogtreecommitdiff
path: root/io.c
AgeCommit message (Collapse)Author
14 daysMake ARGF not pin references during markingPeter Zhu
ARGF supports compaction, but it pins all of its references, which means that none of it can move. This commit changes it to actually support compaction.
2025-07-12[Bug #21509] [DOC] Correct `IO#wait` descriptionNobuyoshi Nakada
2025-07-01[DOC] Fix ARGF exampleKevin Saison
2025-06-27[DOC] Remove a garbage in an exampleNobuyoshi Nakada
2025-06-27[DOC] Fix backquote exit status docsKenyon Ralph
It is `exitstatus`, not `status`, per https://github.com/ruby/ruby/blob/3d5619c8b1a76626e0991d758b71afc549829c38/process.c#L581
2025-05-16Don't enumerate `io->blocking_operations` if fork generation is different. ↵Samuel Williams
(#13359) Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-05-15Ensure that forked process do not see invalid blocking operations. (#13343)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-05-13Make `waiting_fd` behaviour per-IO. (#13127)Samuel Williams
- `rb_thread_fd_close` is deprecated and now a no-op. - IO operations (including close) no longer take a vm-wide lock. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-04-19Fix style [ci skip]Nobuyoshi Nakada
2025-04-19Tidy up `rb_io_fptr_finalize`. (#13136)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-04-19Ensure `struct rb_io` is passed through to `thread.c`. (#13134)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-04-18Update usage of `enum rb_io_mode`. (#13128)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-04-16Introduce `enum rb_io_mode`. (#7894)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-04-15`IO.select` accepts +Float::INFINITY+ as a timeout argument.Tanaka Akira
matz accepted at the developper meeting 2024-07-11.
2025-03-31Provide compaction support for argf_typeMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/13021
2025-03-27Freeze $/ and make it ractor safeÉtienne Barrié
[Feature #21109] By always freezing when setting the global rb_rs variable, we can ensure it is not modified and can be accessed from a ractor. We're also making sure it's an instance of String and does not have any instance variables. Of course, if $/ is changed at runtime, it may cause surprising behavior but doing so is deprecated already anyway. Co-authored-by: Jean Boussier <jean.boussier@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/12975
2025-03-23Fix handling of `error`/`errno` in `io_internal_wait`. (#12961)Samuel Williams
[Bug #21195] Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2025-02-18Ensure IO.copy_stream buffer is an independent stringJeremy Evans
Otherwise, changes to the buffer by the destination write method could result in data changing for supposedly independent strings. Fixes [Bug #21131] Notes: Merged: https://github.com/ruby/ruby/pull/12771
2025-01-02[Bug #20995] Protect `IO.popen` block from exiting by exceptionNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12497
2025-01-02[DOC] Exclude 'Class' and 'Module' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2025-01-02[DOC] Exclude 'Process' from RDoc's autolinkingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12496
2024-12-11Use `rb_str_conv_enc` for simplicityNobuyoshi Nakada
2024-12-10[Bug #20924] Fix reading with delimiter in wide character encodingsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12304
2024-11-07[Bug #20869] Discard read buffer and encoding converters at seekingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12023
2024-11-07[Bug #20802] Copy encodings at reopen as wellNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12022
2024-10-07[Bug #20787] Check the separator in `IO#readline` as well as 3.2Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11811
2024-10-05Introduce `rb_io_blocking_region` which takes `struct rb_io` argument. (#11795)Samuel Williams
This does not change any actual behaviour, but provides a choke point for blocking IO operations. * Update `IO::Buffer` to use `rb_io_blocking_region`. * Update `File` to use `rb_io_blocking_region`. * Update `IO` to use `rb_io_blocking_region`. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2024-10-04Better handling of timeout in `rb_io_maybe_wait_*`. (#9531)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2024-09-26Import patches for old macOS from MacPortsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11690
2024-09-04[Bug #20708] Retry `open` on EINTRNobuyoshi Nakada
Co-Authored-By: Martin Dorey <martin.dorey@hds.com> Notes: Merged: https://github.com/ruby/ruby/pull/11537
2024-06-19[DOC] IO#close on closed IO is not an error.Tanaka Akira
2024-06-02IO.select accepts a numeric value as timeout.Tanaka Akira
[DOC] IO.select accepts a numeric value as timeout, not only an integer.
2024-05-25[Bug #20510] Do not count optional hash argument for `IO.new`Nobuyoshi Nakada
Since `IO.new` accepts one or two positional arguments except for the optional hash argument, exclude the optional hash argument from the check for delegation to `IO.new`.
2024-04-04Update `ARGF.write` interfaceNobuyoshi Nakada
2024-03-06Refactor VM root modulesJean Boussier
This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
2024-03-06Move FL_SINGLETON to FL_USER1Jean Boussier
This frees FL_USER0 on both T_MODULE and T_CLASS. Note: prior to this, FL_SINGLETON was never set on T_MODULE, so checking for `FL_SINGLETON` without first checking that `FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-03-01Turn `rb_sys_fail_on_write` into a functionNobuyoshi Nakada
2024-02-23Remove unneeded RUBY_FUNC_EXPORTEDPeter Zhu
2024-02-20[DOC] Fix links in doc (#9970)Burdette Lamar
2024-02-15Remove used str field in struct binwrite_argPeter Zhu
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-09More on IO doc (#9842)Burdette Lamar
2024-02-05Make io_fwrite safe for compactionPeter Zhu
[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-02-01Don't wait in `io_binwrite_string` if not necessary. (#9792)Samuel Williams
2024-01-24Define `IO_WITHOUT_GVL` macroNobuyoshi Nakada
2024-01-18[DOC] RDoc for ARGF (#9558)Burdette Lamar
2024-01-12s/SafeStringValue/StringValue/Xavier Noria
The macro SafeStringValue() became just StringValue() in c5c05460ac2, and it is deprecated nowadays. This patch replaces remaining macro usage. Some occurrences are left in ext/stringio and ext/win32ole, they should be fixed upstream. The macro itself is not deleted, because it may be used in extensions.
2024-01-10Remove unnecessary semicolons (#9469)S.H
2024-01-10Fix CRLF -> LF conversion on read for rb_io_fdopen & rb_file_openKJ Tsanaktsidis
When opening a file with `File.open`, and then setting the encoding with `IO#set_encoding`, it still correctly performs CRLF -> LF conversion on Windows when reading files with a CRLF line ending in them (in text mode). However, the file is opened instead with either the `rb_io_fdopen` or `rb_file_open` APIs from C, the CRLF conversion is _NOT_ set up correctly; it works if the encoding is not specified, but if `IO#set_encoding` is called, the conversion stops happening. This seems to be because the encflags never get ECONV_DEFAULT_NEWLINE_DECORATOR set in these codepaths. Concretely, this means that the conversion doesn't happen in the following circumstances: * When loading ruby files with require (that calls rb_io_fdopen) * When parsing ruuby files with RubyVM::AbstractSyntaxTree (that calls rb_file_open). This then causes the ErrorHighlight tests to fail on windows if git has checked them out with CRLF line endings - the error messages it's testing wind up with literal \r\n sequences in them because the iseq text from the parser contains un-newline-converted strings. This commit fixes the problem by copy-pasting the relevant snippet which sets this up in `rb_io_extract_modeenc` (for the File.open path) into the relevant codepaths for `rb_io_fdopen` and `rb_file_open`. [Bug #20101]
2024-01-05Do not `poll` firstKoichi Sasada
Before this patch, the MN scheduler waits for the IO with the following steps: 1. `poll(fd, timeout=0)` to check fd is ready or not. 2. if fd is not ready, waits with MN thread scheduler 3. call `func` to issue the blocking I/O call The advantage of advanced `poll()` is we can wait for the IO ready for any fds. However `poll()` becomes overhead for already ready fds. This patch changes the steps like: 1. call `func` to issue the blocking I/O call 2. if the `func` returns `EWOULDBLOCK` the fd is `O_NONBLOCK` and we need to wait for fd is ready so that waits with MN thread scheduler. In this case, we can wait only for `O_NONBLOCK` fds. Otherwise it waits with blocking operations such as `read()` system call. However we don't need to call `poll()` to check fd is ready in advance. With this patch we can observe performance improvement on microbenchmark which repeats blocking I/O (not `O_NONBLOCK` fd) with and without MN thread scheduler. ```ruby require 'benchmark' f = open('/dev/null', 'w') f.sync = true TN = 1 N = 1_000_000 / TN Benchmark.bm{|x| x.report{ TN.times.map{ Thread.new{ N.times{f.print '.'} } }.each(&:join) } } __END__ TN = 1 user system total real ruby32 0.393966 0.101122 0.495088 ( 0.495235) ruby33 0.493963 0.089521 0.583484 ( 0.584091) ruby33+MN 0.639333 0.200843 0.840176 ( 0.840291) <- Slow this+MN 0.512231 0.099091 0.611322 ( 0.611074) <- Good ```