aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
Commit message (Collapse)AuthorAgeFilesLines
* Prefer `rb_fstring_lit` over `rb_fstring_cstr`nobu2018-10-131-1/+1
| | | | | | | 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
* add 'x' mode character for O_EXCLkazu2018-08-091-4/+28
| | | | | | | [Feature #11258] Patch by cremno (cremno phobia) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: fix non-ascii filename inplace editnobu2018-08-091-0/+2
| | | | | | | * 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
* io.c: fix compilation when IOV_MAX is not definednormal2018-06-051-1/+11
| | | | | | | | | 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
* thread.c: enable ppoll for FreeBSD 11.0 and laternormal2018-05-151-5/+12
| | | | | | | | | | | | | | | | | 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
* io.c: cleanup copy_stream wait-for-single-fd casesnormal2018-05-141-42/+28
| | | | | | | | | | | | | | | | 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
* io.c: fix typo and phrase [ci skip]nobu2018-05-121-2/+2
| | | | | | | | [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
* nobody is using the return value of rb_io_fptr_finalizeshyouhei2018-05-041-5/+20
| | | | | | | | 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
* use list_head_init instead of open-coding itnormal2018-05-011-1/+1
| | | | | | | 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
* LIST_HEAD as a local variable is a C99ism.shyouhei2018-05-011-1/+2
| | | | | | | | | | | | | | | | | 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: workaround for EPROTOTYPEnobu2018-04-301-2/+11
| | | | | | | | | | * 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
* io.c: reuse internal_write_funcnobu2018-04-301-2/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: do not use rb_notify_fd_close close on recycled FDnormal2018-04-211-9/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* io.c: IO#write without args returns 0normal2018-03-281-1/+1
| | | | | | | | | | 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
* io.c: Methods of File should not invoke external commandsshugo2018-03-201-6/+1
| | | | | | | | | 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
* Remove duplicated `,` [ci skip]kazu2018-03-181-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add doc for `opt` parameter of IO#reopen [ci skip]k0kubun2018-03-171-2/+3
| | | | | | | | | | 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
* [DOC] missing docs at toplevelnobu2018-02-231-0/+8
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix compile error when USE_COPY_FILE_RANGE is defined but not USE_SENDFILEnobu2018-02-081-2/+2
| | | | | | | | 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: unused assignmentsnobu2018-02-021-4/+3
| | | | | | | * 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: hoisted out io_fd_check_closednobu2018-02-021-9/+11
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: fix comparison subjectnobu2018-01-311-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: fix fptr_copy_finalizernobu2018-01-311-1/+3
| | | | | | | * 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_finalizernobu2018-01-311-16/+19
| | | | | | | | * 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_fptrnobu2018-01-311-4/+16
| | | | | | | * 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: simplified pipe_del_fptrnobu2018-01-311-12/+5
| | | | | | | * 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
* process.c: add :exception option to Kernel.#systemk0kubun2018-01-241-3/+3
| | | | | | | | 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
* use predefined IDskazu2018-01-221-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: remove dependecy on ruby/encoding.hnobu2018-01-091-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: rb_stderr_to_original_pnobu2018-01-071-3/+9
| | | | | | | * 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
* io.c: clear Strings we create for IO.copy_streamnormal2018-01-051-2/+5
| | | | | | | | | | | | | 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
* [DOC] Improve example of IO#pread [ci skip]kazu2017-12-241-4/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] Use File.open with block instead of File.new without close [ci skip]kazu2017-12-241-3/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: ignore EPERMglass2017-12-221-0/+2
| | | | | | | | | * 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
* io.c: IO#pwrite uses tmp buffer to avoid parallel modificationnormal2017-12-211-4/+6
| | | | | | | | | | | 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: opening external commandnobu2017-12-181-11/+5
| | | | | | | | | | * 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: open generic in binreadnobu2017-12-181-1/+1
| | | | | | | | * io.c (rb_io_s_binread): fix r61317, unintentional change. From: Nobuyoshi Nakada <nobu@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: opening external commandnobu2017-12-181-15/+26
| | | | | | | | | | * 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 by rb_io_opennobu2017-12-181-29/+9
| | | | | | | | | * 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
* [DOC] `IO.new` accepts `external_encoding`kazu2017-12-151-0/+3
| | | | | | | Revert part of r61278 [Bug #13655] [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* IO.new doesn't recive "-" as external_encoding [Bug #13655]naruse2017-12-151-4/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix a documentation error of IO#putc.shugo2017-12-031-4/+4
| | | | | | | 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
* bold/underscore support in traceback before Windows10usa2017-12-011-0/+5
| | | | | | | | * 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: read BOM only for readingnobu2017-11-231-0/+3
| | | | | | | * 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: improve docs for the chomp optionstomar2017-11-021-6/+12
| | | | | | | * 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: improve docsstomar2017-10-291-7/+7
| | | | | | * io.c: [DOC] fix rdoc for some cross references; fix grammar. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: docs for IO#writestomar2017-10-291-2/+2
| | | | | | * io.c: [DOC] fix example and language in IO#write docs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* io.c: honor buffered modenobu2017-10-291-5/+9
| | | | | | | | * 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: convert to string at writevnobu2017-10-291-1/+1
| | | | | | | | * 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
* Add note to close_{read,write} tookazu2017-10-281-0/+4
| | | | | | | when call on closed stream [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e