Граф коммитов

1908 Коммитов

Автор SHA1 Сообщение Дата
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 Williams 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
John Bampton c43fbe4ebd
Fix spelling (#7405) 2023-02-28 10:05:30 -08:00
Nobuyoshi Nakada ef00c6da88
Adjust `else` style to be consistent in each files [ci skip] 2023-02-26 13:20:43 +09:00
BurdetteLamar 3b239d2480 Remove (newly unneeded) remarks about aliases 2023-02-19 14:26:34 -08:00
zverok 4f049e915d [DOC] Document IO::Timeout 2023-02-19 22:32:52 +02:00
Jeremy Evans 0903a25179 Make IO#set_encoding with binary external encoding use nil internal encoding
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]
2023-01-01 09:00:24 -08:00
zverok d61a4cec61 Docs: path: option for IO.new 2022-12-23 18:09:49 +02:00
Alan Wu 98675ac09c
[DOC] IO#read doesn't always read in binary mode
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.
2022-12-22 13:15:04 -05:00
Samuel Williams 6fd5d2dc00
Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867) 2022-12-08 18:19:53 +13:00
Jean Boussier 7390eb43fe io.c (read_all): grow the buffer exponentially when size is unknown
[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.
2022-12-02 09:53:57 +01:00
S-H-GAMELINKS 1a64d45c67 Introduce encoding check macro 2022-12-02 01:31:27 +09:00
S-H-GAMELINKS 7bc63d6f43 Introduce argf_encoding function 2022-12-02 01:30:01 +09:00
S-H-GAMELINKS 040e0c8d67 Reuse NIL_OR_UNDEF_P macro 2022-12-02 01:19:55 +09:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Burdette Lamar 0e1e1b1980
[DOC] Enhanced RDoc for IO (#6669) 2022-11-09 10:15:39 -06:00
Burdette Lamar 91c28ab2ee
[DOC] Enhanced RDOc for IO (#6642)
In io.c treats:
    #close
    #close_read
    #close_write
    #closed
2022-10-29 14:47:16 -05:00
Samuel Williams 7fcad1fa03
Update `Fiber::Scheduler` documentation. (#6562) 2022-10-15 21:43:45 +13:00
Samuel Williams 8a420670a2
Introduce `Fiber::Scheduler#io_select` hook for non-blocking `IO.select`. (#6559) 2022-10-15 19:59:04 +13:00
Samuel Williams d416205341
Copy `IO#timeout` on `IO#dup`. (#6546) 2022-10-15 01:45:51 +13:00
Samuel Williams 1bafa4a59b
Ignore failure to set nonblock mode. (#6524) 2022-10-11 10:18:20 +13:00
Samuel Williams 844a9dff88
Try `nil` as default for 'default timeout'. (#6509) 2022-10-08 14:02:34 +13:00
Samuel Williams e4f91bbdba
Add IO#timeout attribute and use it for blocking IO operations. (#5653) 2022-10-07 21:48:38 +13:00
Burdette Lamar bbbdb574c5
[DOC] Integrate io_streams.rdoc into io.c (#6491)
Integrate io_streams.rdoc into io.c
2022-10-06 09:30:12 -05:00
Burdette Lamar ded895baa9
[DOC] RDoc changes for IO (#6458)
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.
2022-10-02 08:24:08 -05:00
Peter Zhu 64200990c4 [ci skip] Fix typos in documentation in io.c 2022-09-16 09:47:32 -04:00
Jeremy Bopp 684353fc03
[Win32] Negative length `IO#sysread`
Raise `ArgumentError` in `IO#sysread` on Windows when given a negative
length.

Fixes [Bug #18880]
2022-09-11 23:08:14 +09:00
Nobuyoshi Nakada e2ccb316b4 [Bug #5317] Use `rb_off_t` instead of `off_t`
Get rid of the conflict with system-provided small `off_t`.
2022-09-08 23:01:07 +09:00
Jeremy Evans 21cac42385 Raise ArgumentError for IO.foreach with limit of 0
Makes behavior consistent with IO.readlines.

Fixes [Bug #18767]
2022-08-25 13:36:17 -07:00
Alan Wu ca8daf70fa [DOC] Mention Windows text mode EOF marker interpretation
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>
2022-08-05 14:34:08 -04:00
Alan Wu f1057393da [DOC] Clarify that `IO.read` uses text mode
See: https://bugs.ruby-lang.org/issues/18882#note-13

[Bug #18882]
2022-08-05 14:34:08 -04:00
Nobuyoshi Nakada 431fdc9200
[DOC] Cross references for `ARGF` 2022-07-28 09:02:23 +09:00
Jeremy Evans 4ad69899b7 Fix documentation for ARGF.inplace_mode{,=}
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-27 15:29:00 -07:00