FreeBSD 11.0+ supports ppoll, so we may use it after accounting
for portability differences in how it treats POLLOUT vs POLLHUP
events as mutually exclusive (as documented in the FreeBSD
poll(2) manpage).
For waiting on high-numbered single FDs, this should put
FreeBSD on equal footing with Linux and should allow cheaper
FD readiness checking with sleepy GC in the future.
* thread.c (USE_POLL, POLLERR_SET): define for FreeBSD 11.0+
(rb_wait_for_single_fd): return all requested events on POLLERR_SET
io.c (USE_POLL): define for FreeBSD 11.0+
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
However this function is listed in ruby/io.h. We cannot but
define a new, void-returning variant to use instead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
While we cannot use LIST_HEAD since r63312, we can at
least use list_head_init to make our code more readable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Address of a variable whose storage duration is `auto` is _not_ a
compile time constant, according to ISO 9899 section 6.4.
LIST_HEAD takes such thing. You can't use it to declare local
variables.
Interestingly, address of a static variable _is_ a compile time
constant. So a declaration like `static LIST_HEAD..` is
completely legal even in C90.
In C99 and newer, this is not a constraint violation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (internal_write_func, internal_writev_func): retry at
unexpected EPROTOTYPE on macOS, to get rid of a kernel bug.
[ruby-core:86690] [Bug #14713]
* ext/socket/init.c (rsock_{sendto,send,write}_blocking): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It is unsafe to release GVL and call rb_notify_fd_close after
close(2) on any given FD. FDs (file descriptor) may be recycled
in other threads immediately after close() to point to a different
file description. Note the distinction between "file description"
and "file descriptor".
th-1 | th-2
-------------------------------+---------------------------------------
io_close_fptr |
rb_notify_fd_close(fd) |
fptr_finalize_flush |
close(fd) |
rb_thread_schedule |
| fd reused (via pipe/open/socket/etc)
rb_notify_fd_close(fd) |
| sees "stream closed" exception
| for DIFFERENT file description
* thread.c (rb_thread_io_blocking_region): adjust comment for list_del
* thread.c (rb_notify_fd_close): give busy list to caller
* thread.c (rb_thread_fd_close): loop on busy list
* io.c (io_close_fptr): do not call rb_thread_fd_close on invalid FD
* io.c (io_reopen): use rb_thread_fd_close
Fixes: r57422 ("io.c: close before wait")
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This is consistent with other implementations of .write
in openssl and stringio.
* io.c (io_write_m): return 0 on argc == 0
[ruby-core:86285] [Bug #14338]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
For security reasons, File.read, File.binread, File.write, File.binwrite,
File.foreach, and File.readlines should not invoke external commands even
if the path starts with the pipe character |.
[ruby-core:84495] [Feature #14245]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It can be specified from 2.0. Ref: https://bugs.ruby-lang.org/issues/7103
[Fix GH-1841]
From: yuuji.yaginuma <yuuji.yaginuma@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
io.c: Variable and label definition are necessary in both cases.
From: Lars Kanis <lars@greiz-reinsdorf.de>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (fptr_finalize_flush): removed unused assignments. if
noraise, err is never used after set.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (fptr_copy_finalizer): fix inverted condition. if
finalizer does not change, pipe_list should not change too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62145 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (fptr_copy_finalizer): remove fptr from pipe_list when pipe
became ordinary file, to fix access after free. to be finalized
by pipe_finalize and being in pipe_list must match.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (pipe_register_fptr): get rid of double registration which
causes access after free and segfault.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (pipe_del_fptr): merged code for the case fptr is first to
the loop for the rest.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (rb_stderr_to_original_p): hoist out the condition to write
messages to the stderr FD directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
While we can't recycle strings after giving them rb_funcall*,
we can reduce their malloc overhead by resizing them to zero.
This only affects cases where either `src' or `dst' is a non-IO
object and either `copy_length' is passed or there is
pre-existing data in the read buffer.
* io.c (copy_stream_fallback_body): clear when done with `copy_length'
(copy_stream_body): clear when done with pre-existing read buffer
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (nogvl_copy_file_range): ignore EPERM and fallback to
sendfile(2) or read/write. copy_file_range(2) may not exist
even if __NR_copy_file_range is defined in the build environment.
[Bug #14207]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Since we release GVL, we must freeze and duplicate the string buffer
to prevent other threads from modifying our buffer while we are
waiting on pwrite(2).
* io.c (rb_io_pwrite): use_rb_str_tmp_frozen_{acquire/release}
[Bug #14195]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (rb_io_open_generic): try to open the named file as usual,
if klass is not IO nor File, so that Errno::ENOENT will be
raised probably. calling on File will be same in the future.
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (rb_io_open_generic): when external command will be invoked
as other than IO singleton method, probably unintentionally,
warn if it is File or raise ArgumentError.
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (open_key_args): open by rb_io_open always also when
open_args: option is given.
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
IO#putc is multi-byte character safe when a String is given as its argument.
[ruby-core:82019] [Bug #13741]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (rb_write_error2): call `rb_w32_write_console()` when the device is tty,
like `rb_write_error_str()`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (io_strip_bom): just abandon detecting UTF encoding by BOM
unless opened for reading.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: [DOC] improve the description for the chomp option and
add examples to IO.readlines and IO#readlines; other small fixes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (io_writev): honor buffered mode to get rid of broken pipe
error when stdout is redirected to a pipeline.
[ruby-core:83578] [Feature #14042]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c (io_fwritev): needs conversion to string before accessing
the content, as well as single argument case, not to segfault.
[Feature #9323]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Linux copy_file_range(2) fails with EBADF if the destination FD
has O_APPEND set. Preserve existing (Ruby <= 2.4) behavior by
falling back to alternative copy mechanisms if this is the case
(instead of raising Errno::EBADF).
* io.c (nogvl_copy_file_range): do not raise on O_APPEND dst
* test/ruby/test_io.rb (test_copy_stream_append): new test
[Feature #13867]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_to_array_type): make public to share common code
internally.
* hash.c (rb_to_hash_type): make public to share common code
internally.
* symbol.c (rb_to_symbol_type): make public to share common code
internally.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e