summaryrefslogtreecommitdiff
path: root/io.c
AgeCommit message (Collapse)Author
2018-12-06io.c (io_fflush): eliminate redundant rb_io_check_closednormal
There is no need to call this function twice in a row since thread switching won't happen in-between calls to it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06io.c (io_write_nonblock): add RB_GC_GUARD, io_fflush may switch threadsnormal
Since io_fflush may block on mutex or rb_io_wait_readable and switch threads, we need to ensure the `str' VALUE returned by `rb_obj_as_string` is visible to GC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Prefer rb_check_arity when 0 or 1 argumentsnobu
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29io.c: fix clang -Werror,-Wshorten-64-to-32 on Linux sendfilenormal
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29io.c: fix clang -Werror,-Wshorten-64-to-32 errorsnormal
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29io.c: favor comparisons against zero rather than -1normal
On my 32-bit x86 userspace, I get the following .text savings: text data bss dec hex filename 152971 56 252 153279 256bf io.o.before 152863 56 252 153171 25653 io.o.after git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29disable non-blocking pipes and sockets by defaultnormal
There seems to be a compatibility problems with Rails + Rack::Deflater; so we revert this incompatibility. This effectively reverts r65922; but keeps the bugfixes to better support non-blocking sockets and pipes for future use. [Bug #15356] [Bug #14968] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-28io.c (rb_update_max_fd): use F_GETFL if possiblenormal
On 64-bit Linux, fstat() needs to fill out a 144 byte struct while F_GETFL only needs to return 8 bytes. Fwiw, F_GETFD requires an additional rcu_read_lock and bitmap check; so it's obviously more expensive than F_GETFL on Linux. Reduce stack usage of rb_update_max_fd from 184 to 24 bytes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-28* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-28io.c: reduce IO.copy_stream stack usage on Linuxnormal
nogvl_copy_file_range and nogvl_copy_stream_sendfile each used 344 bytes of stack before this change. Now, they are inlined into nogvl_copy_stream_func which only uses 200 bytes of stack. "struct stat" is 144 bytes on my 64-bit Linux. Note: this doesn't affect GC (yet) since GVL is released; but increases safety if called from deep machine stacks. It will affect GC if Thread::Light is merged. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27io.c (struct copy_stream_struct): packingnormal
Reduce the struct to 80 bytes (from 88) on amd64 to reduce stack use. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-24io.c: disable nonblocking-by-default on win32 pipesnormal
Lets admit Windows will always be too different from POSIX-like platforms and non-blocking may never work as well or consistently. [ruby-core:90042] [ruby-core:90044] [Bug #14968] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-24io.c: wait on FD readability w/o GVL reacquisitionnormal
Since non-blocking I/O is the default after [Bug #14968], we will hit it more often and cause more acquisition/release of GVL to wait on single FD. This also lets us avoid touching the temporal string locking as much and lets us clean up some test changes made for [Bug #14968] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-23io.c (io_fd_check_closed): prioritize cross-thread "stream closed"normal
This may fix failures from TestIO#test_recycled_fd_close because interrupts may be missed due to TOCTOU in other places. cf. http://ci.rvm.jp/results/trunk-nopara@silicon-docker/1475034 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-23io.c (fptr_finalize_flush): close race leading to EBADFnormal
The previous ordering was: a) notify waiting_fd threads of impending close b) waiting on busy list from a) c) invalidate fptr->fd d) calling close() However, it was possible for a new thread to enter the waiting_fd list while scheduling on b), leading to EBADF from those threads when we hit d). Instead, we now avoid triggering EBADF in other threads by reordering b) and c) a) notify waiting_fd threads of impending close c) invalidate fptr->fd b) waiting on busy list from a) d) calling close() cf. http://ci.rvm.jp/results/trunk-nopara@silicon-docker/1474526 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22io.c: revalidate fptr->fd after rb_io_wait_readablenormal
fptr->fd may become -1 while GVL is released in rb_wait_for_single_fd, so we must check it after reacquiring GVL. This should avoid EBADF errors exposed by making pipes non-blocking by default: http://ci.rvm.jp/results/trunk-test@ruby-sky3/1473710 [Bug #14968] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22io + socket: make pipes and sockets nonblocking by defaultnormal
All normal Ruby IO methods (IO#read, IO#gets, IO#write, ...) are all capable of appearing to be "blocking" when presented with a file description with the O_NONBLOCK flag set; so there is little risk of incompatibility within Ruby-using programs. The biggest compatibility risk is when spawning external programs. As a result, stdin, stdout, and stderr are now always made blocking before exec-family calls. This change will make an event-oriented MJIT usable if it is waiting on pipes on POSIX_like platforms. It is ALSO necessary to take advantage of (proposed lightweight concurrency (aka "auto-Fiber") or any similar proposal for network concurrency: https://bugs.ruby-lang.org/issues/13618 Named-pipe (FIFO) are NOT yet non-blocking by default since they are rarely-used and may introduce compatibility problems and extra syscall overhead for a common path. Please revert this commit if there are problems and if I am afk since I am afk a lot, lately. [ruby-core:89950] [Bug #14968] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20Remove unnecessary spacekazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-19io.c: ungetbyte silently ignores upper bitsshyouhei
The behaviour of IO#ungetbyte has been depending on the width of Fixnums. Fixnums should be invisible nowadays. It must be a bug. Fix [Bug #14359] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65802 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18io.c: include vm_core.h for VM_UNREACHABLEnormal
Thanks to Greg L <greg.mpls@gmail.com> for the report git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-18io.c (novl_wait_for_single_fd): VM_UNREACHABLE instead of assertnormal
This respects VM_CHECK_MODE and is more consistent with the rest of our code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13Prefer `rb_fstring_lit` over `rb_fstring_cstr`nobu
The former states explicitly that the argument must be a literal, and can optimize away `strlen` on all compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09add 'x' mode character for O_EXCLkazu
[Feature #11258] Patch by cremno (cremno phobia) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09io.c: fix non-ascii filename inplace editnobu
* io.c (argf_next_argv): convert filename to the OS encoding to be dealt with by system calls. [ruby-dev:50607] [Bug #14970] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-05io.c: fix compilation when IOV_MAX is not definednormal
GNU/Hurd has writev(2) but does not define IOV_MAX [ruby-core:87417] [Bug #14827] Reported-by: Paul Sonnenschein git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-15thread.c: enable ppoll for FreeBSD 11.0 and laternormal
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
2018-05-14io.c: cleanup copy_stream wait-for-single-fd casesnormal
Avoid paying unnecessary setup and teardown cost for rb_fdset_t on platforms (Linux) with good poll() support. This simplifies code makes future changes (perhaps for sleepy GC) easier. * io.c (struct copy_stream_struct): remove rb_fdset_t fds (nogvl_wait_for_single_fd): implement with select for non-poll case (maygvl_copy_stream_wait_read): remove duplicate definition (nogvl_copy_stream_wait_write): remove #ifdef (copy_stream_body): remove rb_fd_set calls (copy_stream_finalize): remove rb_fd_term call (rb_io_s_copy_stream): remove rb_fd_init git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-12io.c: fix typo and phrase [ci skip]nobu
[Fix GH-1872] From: Leon M. George <leon@georgemail.eu> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-04nobody is using the return value of rb_io_fptr_finalizeshyouhei
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
2018-05-01use list_head_init instead of open-coding itnormal
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
2018-05-01LIST_HEAD as a local variable is a C99ism.shyouhei
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
2018-04-30io.c: workaround for EPROTOTYPEnobu
* 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
2018-04-30io.c: reuse internal_write_funcnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-21io.c: do not use rb_notify_fd_close close on recycled FDnormal
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
2018-03-28io.c: IO#write without args returns 0normal
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
2018-03-20io.c: Methods of File should not invoke external commandsshugo
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
2018-03-18Remove duplicated `,` [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-17Add doc for `opt` parameter of IO#reopen [ci skip]k0kubun
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
2018-02-23[DOC] missing docs at toplevelnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08Fix compile error when USE_COPY_FILE_RANGE is defined but not USE_SENDFILEnobu
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
2018-02-02io.c: unused assignmentsnobu
* 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
2018-02-02io.c: hoisted out io_fd_check_closednobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31io.c: fix comparison subjectnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31io.c: fix fptr_copy_finalizernobu
* 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
2018-01-31io.c: fptr_copy_finalizernobu
* 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
2018-01-31io.c: pipe_register_fptrnobu
* 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
2018-01-31io.c: simplified pipe_del_fptrnobu
* 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
2018-01-24process.c: add :exception option to Kernel.#systemk0kubun
to raise error when it fails. [Feature 14386] [GH-1795] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22use predefined IDskazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e