aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
Commit message (Collapse)AuthorAgeFilesLines
* [DOC] Update ARGF.readlines documentation to match/reference IO.readlines.Ryan Davis2023-12-011-6/+8
|
* IO#read always check the provided buffer is mutableJean Boussier2023-11-091-1/+2
| | | | Otherwise you can have work in some circumstance but not in others.
* Raise TypeError for bad IO::Buffer.map argument (#8728)Charles Oliver Nutter2023-10-211-1/+8
| | | | | | | | | | | | | | | * 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>
* [DOC] Fix typo in docs of IO: `#.` -> `$.`Herwin2023-10-041-1/+1
|
* Move IO#readline to RubyAaron Patterson2023-09-281-15/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* Invoke the command when RUBY_BUGREPORT_PATH starts with `|`Nobuyoshi Nakada2023-09-251-0/+55
|
* [Bug #19624] Clean up backquote IONobuyoshi Nakada2023-09-211-9/+11
| | | | It should not be hidden, since it can be grabbed by a fiber scheduler.
* [DOC] Mention "-" in ARGFNobuyoshi Nakada2023-09-171-2/+7
|
* [DOC] Fix a typo in "Open Options" section of IOHerwin2023-09-101-1/+1
| | | | The word "and" was missing.
* [DOC] Fix layout in documentation of IO#fcntlHerwin2023-09-031-1/+1
|
* Document that Kernel#p is for debugging and may be uninterruptible [ci skip]Jeremy Evans2023-08-301-0/+4
| | | | Fixes [Bug #18810]
* Introduce `at_char_boundary` functionNobuyoshi Nakada2023-08-261-2/+1
|
* Extract GC for fd parts as `TRY_WITH_GC `Nobuyoshi Nakada2023-08-161-35/+22
|
* Extract platform dependent part as `fdopen_internal`Nobuyoshi Nakada2023-08-161-16/+17
|
* [DOC] Don't suppress autolinksBurdetteLamar2023-08-121-11/+11
|
* Deprecate Kernel#open and IO support for subprocess creation/forkingMike Dalessio2023-08-101-141/+12
| | | | | | | | | | | | | | | | | 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]
* Use `File::NULL` instead of hard coded null device namesNobuyoshi Nakada2023-07-101-3/+3
|
* [DOC] Fixes for link fragments (#7981)Burdette Lamar2023-06-281-2/+2
|
* Adjust style [ci skip]Nobuyoshi Nakada2023-06-071-1/+2
|
* Expose `enum rb_io_event` flags without `_t` suffix. (#7887)Samuel Williams2023-06-011-2/+2
|
* Drop `_t` suffix from struct names. (#7886)Samuel Williams2023-06-011-22/+20
| | | POSIX reserves `_t` suffix in types.
* Use a real Ruby mutex in rb_io_close_wait_list (#7884)KJ Tsanaktsidis2023-06-011-9/+1
| | | | | | | | | | | | | | | | | | | | | | 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/
* Hide the usage of `rb_io_t` where possible. (#7880)Samuel Williams2023-06-011-40/+91
| | | This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility.
* Revert "Hide most of the implementation of `struct rb_io`. (#6511)"NARUSE, Yui2023-06-011-97/+45
| | | | | | | | | 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.
* Hide most of the implementation of `struct rb_io`. (#6511)Samuel Williams2023-05-301-45/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Improve `read`/`write`/`pread`/`pwrite` consistency. (#7860)Samuel Williams2023-05-271-15/+0
| | | | | | | * Documentation consistency. * Improve consistency of `pread`/`pwrite` implementation when given length. * Remove HAVE_PREAD / HAVE_PWRITE - it is no longer optional.
* Fix busy-loop when waiting for file descriptors to closeKJ Tsanaktsidis2023-05-261-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* `rb_io_puts` should not write zero length strings. (#7806)Samuel Williams2023-05-151-16/+24
|
* [Bug #19624] Hide internal IO for backquoteNobuyoshi Nakada2023-05-011-0/+1
|
* [DOC] Fix typosNobuyoshi Nakada2023-04-131-3/+3
|
* [Bug #19584] Register global variables before assignmentNobuyoshi Nakada2023-04-071-4/+3
|
* [Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House2023-04-061-1/+1
| | | | NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec
* Support `IO#pread` / `IO#pwrite` using fiber scheduler. (#7594)Samuel Williams2023-03-311-10/+32
| | | * Skip test if non-blocking file IO is not supported.
* Raise ArgumentError if IO.read is provided negative offsetJeremy Evans2023-03-241-0/+4
| | | | Fixes [Bug #19380]
* [DOC] Clarify IO#autoclose impact on #closeLars Kanis2023-03-011-6/+6
| | | Mention that autoclose changes the behavior of explicit close in addition to implicit close at IO finalization.
* Fix spelling (#7405)John Bampton2023-02-281-1/+1
|
* Adjust `else` style to be consistent in each files [ci skip]Nobuyoshi Nakada2023-02-261-4/+8
|
* Remove (newly unneeded) remarks about aliasesBurdetteLamar2023-02-191-13/+0
|
* [DOC] Document IO::Timeoutzverok2023-02-191-1/+5
|
* Make IO#set_encoding with binary external encoding use nil internal encodingJeremy Evans2023-01-011-2/+13
| | | | | | | | | | | | | | 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]
* Docs: path: option for IO.newzverok2022-12-231-0/+2
|
* [DOC] IO#read doesn't always read in binary modeAlan Wu2022-12-221-5/+3
| | | | | | | | | | | | 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.
* Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867)Samuel Williams2022-12-081-2/+41
|
* io.c (read_all): grow the buffer exponentially when size is unknownJean Boussier2022-12-021-2/+16
| | | | | | | | [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.
* Introduce encoding check macroS-H-GAMELINKS2022-12-021-2/+2
|
* Introduce argf_encoding functionS-H-GAMELINKS2022-12-021-8/+13
|
* Reuse NIL_OR_UNDEF_P macroS-H-GAMELINKS2022-12-021-1/+1
|
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-19/+19
|
* [DOC] Enhanced RDoc for IO (#6669)Burdette Lamar2022-11-091-112/+436
|
* [DOC] Enhanced RDOc for IO (#6642)Burdette Lamar2022-10-291-25/+84
| | | | | | | In io.c treats: #close #close_read #close_write #closed