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

1648 Коммитов

Автор SHA1 Сообщение Дата
shyouhei 496ddbc275 LIST_HEAD as a local variable is a C99ism.
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-05-01 04:41:10 +00:00
nobu 7727b22eb1 io.c: workaround for EPROTOTYPE
* 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-30 02:17:03 +00:00
nobu 6073edd636 io.c: reuse internal_write_func
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-30 00:28:30 +00:00
normal 645f7fbd4e io.c: do not use rb_notify_fd_close close on recycled FD
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-04-21 03:12:36 +00:00
normal 7292569d3f io.c: IO#write without args returns 0
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-28 08:38:21 +00:00
shugo 798316eac2 io.c: Methods of File should not invoke external commands
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-20 09:09:49 +00:00
kazu 01e9d9ac7e Remove duplicated `,` [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-18 06:54:21 +00:00
k0kubun 38abd83529 Add doc for `opt` parameter of IO#reopen [ci skip]
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-03-17 06:39:18 +00:00
nobu 96db72ce38 [DOC] missing docs at toplevel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:18:52 +00:00
nobu 472d910a26 Fix compile error when USE_COPY_FILE_RANGE is defined but not USE_SENDFILE
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-08 15:22:54 +00:00
nobu 49e801c1c7 io.c: unused assignments
* 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-02 08:30:57 +00:00
nobu cc410b2a5c io.c: hoisted out io_fd_check_closed
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-02 05:44:13 +00:00
nobu 00716bee78 io.c: fix comparison subject
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31 17:35:27 +00:00
nobu 4139024e15 io.c: fix fptr_copy_finalizer
* 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-31 17:26:20 +00:00
nobu 4057ee5e8e io.c: fptr_copy_finalizer
* 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-31 08:17:16 +00:00
nobu 1d5847d1af io.c: pipe_register_fptr
* 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-31 04:24:57 +00:00
nobu 80d74ea732 io.c: simplified pipe_del_fptr
* 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-31 04:02:18 +00:00
k0kubun fb29cffab0 process.c: add :exception option to Kernel.#system
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-24 14:11:25 +00:00
kazu b8cc476ce9 use predefined IDs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-22 13:09:37 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
nobu f39ea3d189 io.c: rb_stderr_to_original_p
* 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
2018-01-07 04:10:06 +00:00
normal 6776e0bc99 io.c: clear Strings we create for IO.copy_stream
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
2018-01-05 21:14:19 +00:00
kazu 9f68d0f591 [DOC] Improve example of IO#pread [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-24 02:41:00 +00:00
kazu 13247fa417 [DOC] Use File.open with block instead of File.new without close [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-24 01:26:46 +00:00
glass 072ed558d5 io.c: ignore EPERM
* 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
2017-12-22 08:47:39 +00:00
normal 3b174fb7d6 io.c: IO#pwrite uses tmp buffer to avoid parallel modification
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
2017-12-21 00:26:24 +00:00
nobu d2f685eed7 io.c: opening external command
* 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
2017-12-18 07:15:07 +00:00
nobu 6b718de1d6 io.c: open generic in binread
* 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
2017-12-18 07:10:15 +00:00
nobu 2ad35b31bb io.c: opening external command
* 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
2017-12-18 04:32:54 +00:00
nobu 7d24c27d21 io.c: open_key_args by rb_io_open
* 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
2017-12-18 03:38:20 +00:00
kazu a9419fbd4f [DOC] `IO.new` accepts `external_encoding`
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
2017-12-15 11:52:41 +00:00
naruse 9fa7722bbc IO.new doesn't recive "-" as external_encoding [Bug #13655]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-15 08:26:33 +00:00
shugo 3616b07c9a Fix a documentation error of IO#putc.
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
2017-12-03 08:10:42 +00:00
usa c88c7d911f bold/underscore support in traceback before Windows10
* 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
2017-12-01 05:32:29 +00:00
nobu 1046eae781 io.c: read BOM only for reading
* 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
2017-11-23 07:10:56 +00:00
stomar e36ccef549 io.c: improve docs for the chomp option
* 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
2017-11-02 20:38:04 +00:00
stomar b1e77e85b6 io.c: improve docs
* 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
2017-10-29 20:58:36 +00:00
stomar bf9ffeed31 io.c: docs for IO#write
* 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
2017-10-29 20:57:29 +00:00
nobu 8354b6d2cd io.c: honor buffered mode
* 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
2017-10-29 05:46:23 +00:00
nobu 85195203f4 io.c: convert to string at writev
* 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
2017-10-29 00:43:34 +00:00
kazu f0c3df3113 Add note to close_{read,write} too
when call on closed stream
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28 16:34:30 +00:00
normal 524e660877 io.c: fix IO.copy_stream on O_APPEND destination on Linux
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
2017-10-27 18:37:23 +00:00
nobu 6b818dd961 common conversion functions
* 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
2017-10-26 07:23:23 +00:00
nobu 1b27af8d56 io.c: let rb_p use writev
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 12:33:42 +00:00
nobu 237901a41b io.c: warn old write
* io.c (rb_io_puts): warn if write method accepts just one
  argument.  [ruby-core:83529] [Feature #14042]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 12:04:53 +00:00
nobu 635d0822cd io.c: write a newline together
* io.c (rb_io_puts): write a newline together at once for each
  argument.  based on the patch by rohitpaulk (Rohit Kuruvilla) at
  [ruby-core:83508].  [Feature #14042]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25 05:44:38 +00:00
kazu 9885c1c79f Update call-seq of ARGF.read_nonblock
ARGF.read_nonblock supports `exception: false' like IO#read_nonblock
since 2.3.0.
[Feature #11358]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 12:10:32 +00:00
hsbt 0e2d2e6a79 Drop to support NaCl platform.
Because NaCl and PNaCl are already sunset status.
  see https://bugs.chromium.org/p/chromium/issues/detail?id=239656#c160

  configure.ac: Patch for this file was provided by @nobu.

  [Feature #14041][ruby-core:83497][fix GH-1726]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:56:25 +00:00
nobu 08524bc594 io.c: fix infinite retry
* io.c (io_binwritev): fix infinite retry when flushing buffered
  data.  [Feature #9323]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:28:12 +00:00
nobu 71a7ef31d7 io.c: fix buffered output
* io.c (io_binwritev): append to buffered data, not overwriting.
  [Feature #9323]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:09:35 +00:00
nobu 92023a8f60 io.c: fix total
* io.c (io_writev): total may be a bignum.  [Feature #9323]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:09:34 +00:00
nobu c0f40369b6 io.c: no restriction
* io.c (io_write_m): remove argc restriction upto IOV_MAX-1.
  [Feature #9323]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 02:25:58 +00:00
kazu d9cfbb3cad Fix indent and comment [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 06:30:47 +00:00
nobu 6e3ff2ecd9 io.c: fix local variables
* io.c (io_writev): fix local variable declarations, when
  writev(2) is not available.  [Feature #9323]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 06:22:50 +00:00
glass 3efa7126e5 Make IO#write accept multiple arguments
io.c: make IO#write accept multiple arguments.
it uses writev(2) if possible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 02:11:07 +00:00
hsbt 2c27e52f8e Add documentation for `chomp` option.
https://github.com/ruby/ruby/pull/1717

  Patch by @ksss [fix GH-1717]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:11:58 +00:00
hsbt 2476bf2bb1 Clarify the behavior of IO.write without offset in write mode.
https://github.com/ruby/ruby/pull/1571

  Patch by @takanabe [fix GH-1571]
  [Bug #11638][ruby-core:71277]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 15:16:54 +00:00
glass 0686d5f4eb io.c: introduce copy offload to IO.copy_stream
io.c (rb_io_s_copy_stream): add copy offload feature (by using
copy_file_range(2) if available) to IO.copy_stream

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 14:25:46 +00:00
akr ae2578f6bc [DOC] describe methods used for src and dst argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 06:45:41 +00:00
nobu 20685cdc85 Get rid of shadowing local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 04:35:25 +00:00
nobu 5e52f06529 io.c: encoding of ARGF.inplace_mode
* io.c (argf_next_argv): encode inplace mode suffix to the path
  encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-10 12:30:42 +00:00
nobu 4ed65f1242 io.c: path name conversion at ARGF
* io.c (argf_next_argv): the standard conversion to path name
  should take place.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-10 10:42:52 +00:00
nobu 09e60b5af5 io.c: [DOC] about buffering [ci skip]
* io.c (rb_file_initialize): [DOC] stated that non-tty file is
  buffered by the default, and added links to related methods.
  [ruby-core:83081] [Bug #13965]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-05 02:35:58 +00:00
nobu 8148b7013c io.c: check null char
* io.c (ruby_set_inplace_mode): check if null is contained.  based
  on the patch by tommy (Masahiro Tomita) in [ruby-dev:50272].
  [Bug #13960]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02 06:46:42 +00:00
shirosaki fd50c2ee44 io.c: fix segfault with closing socket on Windows
* io.c (fptr_finalize_flush): add an argument to keep GVL.
* io.c (fptr_finalize): adjust for above change.
* io.c (io_close_fptr): closing without GVL causes another
  exception while raising exception in another thread. This causes
  segfault on Windows. Keep GVL while closing when another thread
  raises.
  [Bug #13856] [ruby-core:82602]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-28 13:43:21 +00:00
sorah 75cda5e22f File#path: Raise IOError when a file is O_TMPFILE
File#path for a file opened with O_TMPFILE has no meaning.

A filepath returned by this method isn't guarranteed about its accuracy,
but files opened with O_TMPFILE are known its recorded path has no
meaning. So let them not to return any pathname.

After a discussion in ruby-core, just returning Qnil makes guessing the
root cause difficult. Instead, this patch makes the method to raise an
error.

Other consideration is calling fnctl(2) on rb_file_path, but it adds a
overhead, and it's difficult to determine O_TMPFILE status  after fd has
been closed.

[Feature #13568]

* io.c(rb_file_open_generic): Set Qnil to fptr->pathv when opening a
  file using O_TMPFILE

* file.c(rb_file_path): Raise IOError when fptr->pathv is Qnil

* file.c(rb_file_path): [DOC] Update for the new behavior

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31 11:14:36 +00:00
nobu 9f1994ed5c io.c: shrink read buffer
* io.c (io_setstrbuf): return true if the buffer is newly created.

* io.c (io_set_read_length): shrink the read buffer if it is a new
  object and is too large.  [ruby-core:81370] [Bug #13597]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31 08:21:46 +00:00
nobu 57464618ab io.c: textmode if newline decorator
* io.c (validate_enc_binmode): newline decorator implies text mode
  now.  [ruby-core:80270] [Bug #13350]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-14 10:53:35 +00:00
glass 2fd3a2e2f7 Revert "Allow IO#reopen to take a block"
This reverts r59142.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23 04:19:53 +00:00
glass f1b7003f35 Allow IO#reopen to take a block
* io.c (rb_io_reopen): take a block and ensure the IO closed
  [Feature #2631]

* test/ruby/test_io.rb: add a test

* NEWS: add an entry for this change

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-22 06:50:32 +00:00
watson1978 d0015e4ac6 Improve performance of implicit type conversion
To convert the object implicitly, it has had two parts in convert_type() which are
  1. lookink up the method's id
  2. calling the method

Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up
the method's id for type conversion.

This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id)
to call the method without looking up the method's id when convert the object.

Array#flatten -> 19 % up
Array#+       ->  3 % up

[ruby-dev:50024] [Bug #13341] [Fix GH-1537]

### Before
       Array#flatten    104.119k (± 1.1%) i/s -    525.690k in   5.049517s
             Array#+      1.993M (± 1.8%) i/s -     10.010M in   5.024258s

### After
       Array#flatten    124.005k (± 1.0%) i/s -    624.240k in   5.034477s
             Array#+      2.058M (± 4.8%) i/s -     10.302M in   5.019328s

### Test Code
require 'benchmark/ips'

class Foo
  def to_ary
    [1,2,3]
  end
end

Benchmark.ips do |x|

  ary = []
  100.times { |i| ary << i }
  array = [ary]

  x.report "Array#flatten" do |i|
    i.times { array.flatten }
  end

  x.report "Array#+" do |i|
    obj = Foo.new
    i.times { array + obj }
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31 12:30:57 +00:00
nobu 6924066a65 adjust styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-10 00:39:26 +00:00
normal b1bb2520c8 io.c (do_fcntl): update max FD for F_DUPFD_CLOEXEC, too
Somebody may pass 1030 (the value of F_DUPFD_CLOEXEC) to IO#fcntl
because they copied code from somewhere else.  Ensure we know
about FDs created that way.

* io.c (do_fcntl): update max FD for F_DUPFD_CLOEXEC, too

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 07:38:30 +00:00
kosaki ca8f454f09 nogvl_wait_for_single_fd must wait as its name
poll(fds, n, 0) mean no timeout and immediately return. If you want to
wait something, you need to use -1 instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-02 02:19:32 +00:00
kazu dabaaafd9f Fix typo in documentation [ci skip]
[Fix GH-1599]
Author:    Liam Sean Brady <liamseanbrady@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-01 02:42:34 +00:00
kazu 434c353e71 io.c: ARGF.file returns $stdin instead of STDIN [ci skip]
For example:
`ruby -e '$stdin=open(IO::NULL);p [STDIN,$stdin,ARGF.file]'`
prints `[#<IO:<STDIN>>, #<File:/dev/null>, #<File:/dev/null>]`

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-09 11:53:53 +00:00
kazu b16f9112ed Fix arguments order of IO#pwrite
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03 12:30:04 +00:00
nobu 8109114b18 Add IO#pread and IO#pwrite methods
These methods are useful for safe/concurrent file I/O in
multi-thread/process environments and also fairly standard
nowadays especially in systems supporting pthreads.

Based on patches by Avseyev <sergey.avseyev@gmail.com> at
[ruby-core:79290].  [Feature #4532]

* configure.in: check for pwrite(2).  pread() is already used
  internally for IO.copy_stream.

* io.c: implement wrappers for pread(2) and pwrite(2) and expose
  them in IO.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03 00:10:50 +00:00
stomar 5f5f648c9b io.c: [DOC] expand docs for IO#puts
[ruby-core:80081] [Bug #13306]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-22 20:23:42 +00:00
stomar fbaee79ec0 io.c: improve docs
* io.c: [DOC] improve and harmonize docs for IO#read and ARGF#read;
  fix invalid example code for IO#read to make it syntax highlighted.

* io.c: [DOC] various improvements for docs of IO, ARGF, and Kernel:
  fix indent to ensure correct code block detection; sync "outbuf"
  paragraph for {IO,ARGF}#read, {IO,ARGF}#readpartial, and IO#sysread;
  fix formatting of call-seq's; improve Kernel#open example to use nil?;
  fix RDoc markup and typos.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17 20:48:51 +00:00
normal 05404cba6e deduplicate "/", ":" and "\n" strings
"/" and ":" are always statically registered in symbol.c (Init_op_tbl),
and "\n" is a commonly seen in source code.

* file.c (Init_File): fstring on File::SEPARATOR and File::PATH_SEPARATOR
* io.c (Init_IO): fstring on rb_default_rs ("\n")

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17 00:55:45 +00:00
kazu 8bc0729857 io.c: [DOC] add missing `$`
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-15 00:59:32 +00:00
naruse 70474e9bfc io.c: [DOC] IO#puts uses IO#write
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-12 18:40:07 +00:00
stomar 8188fb9a6f io.c: [DOC] open mode can be an integer; fix rdoc syntax
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 19:42:36 +00:00
stomar 5dfde64609 docs for IO.{write,read}
* io.c: [DOC] improve docs for IO
  * IO.{write,read}: fix errors (:open_args is not an array of
    strings, it might include a perm or options hash argument;
    IO.write has no length argument, drop corresponding statement),
    improve formatting, call-seq, grammar.
  * IO#sync=: remove unnecessary "produces no output".
  * other improvements.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-05 19:43:10 +00:00
stomar 6af78021d4 docs for IO#print
* io.c: [DOC] split documentation for IO#print into smaller paragraphs,
  delete duplicate sentence, fix call-seq.
  Based on a patch by Dario Daic. [ruby-core:78291] [Bug #12975]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-05 12:36:09 +00:00
stomar d4e1b7fcec io.c: documentation for puts
* io.c: [DOC] clarify that the 'record separator' between
  arguments passed to 'puts' is always a newline.
  Based on a patch by Mark Amery. [ruby-core:65801] [Misc #10403]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-03 19:39:35 +00:00
nobu 5318154fe1 eval_error.c: backstrace in reverse order
* eval_error.c (rb_threadptr_error_print): print backtrace and
  error message in reverse order if STDERR is unchanged and a tty.
  [Feature #8661]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 08:50:25 +00:00
normal 0db6b623a6 io.c: remove rb_ensure usage for rb_str_tmp_frozen_* calls
Using rb_ensure pessimizes the common case and makes the code
more difficult to read and follow.  If we hit an exceptions
during write, just let the GC handle cleanup as the exception
is already bad for garbage.

* io.c (io_fwrite): call rb_str_tmp_frozen{acquire,release} directly
  (rb_io_syswrite): ditto
  (fwrite_do, fwrite_end, swrite_do, swrite_end): remove

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-02 18:59:40 +00:00
normal 4b9a21cdd6 io.c (rb_io_syswrite): avoid leaving garbage after write
As with IO#write, IO#syswrite also generates garbage which can
be harmful in hand-coded read-write loops.

* io.c (swrite_arg, swrite_do, swrite_end): new
  (rb_io_syswrite): use new functions to cleanup garbage
  [ruby-core:78898] [Bug #13085]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-30 22:03:57 +00:00
normal 9c4ba969a5 io.c: recycle garbage on write
* string.c (STR_IS_SHARED_M): new flag to mark shared mulitple times
  (STR_SET_SHARED): set STR_IS_SHARED_M
  (rb_str_tmp_frozen_acquire, rb_str_tmp_frozen_release): new functions
  (str_new_frozen): set/unset STR_IS_SHARED_M as appropriate
* internal.h: declare new functions
* io.c (fwrite_arg, fwrite_do, fwrite_end): new
  (io_fwrite): use new functions

Introduce rb_str_tmp_frozen_acquire and rb_str_tmp_frozen_release
to manage a hidden, frozen string.  Reuse one bit of the embed
length for shared strings as STR_IS_SHARED_M to indicate a string
has been shared multiple times.  In the common case, the string
is only shared once so the object slot can be reclaimed immediately.

minimum results in each 3 measurements. (time and size)

Execution time (sec)
name                            trunk   built
io_copy_stream_write            0.682   0.254
io_copy_stream_write_socket     1.225   0.751

Speedup ratio: compare with the result of `trunk' (greater is better)
name    built
io_copy_stream_write            2.680
io_copy_stream_write_socket     1.630

Memory usage (last size) (B)
name                            trunk           built
io_copy_stream_write            95436800.000    6512640.000
io_copy_stream_write_socket     117628928.000   7127040.000

Memory consuming ratio (size) with the result of `trunk' (greater is better)
name    built
io_copy_stream_write            14.654
io_copy_stream_write_socket     16.505

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-30 20:40:18 +00:00
nobu 61701ae167 io.c: close before wait
* io.c (io_close_fptr): notify then close, and wait for other
  threads before free fptr.  [ruby-core:79262] [Bug #13158]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-25 14:34:07 +00:00
nobu 50db992a6a Change Kernel#warn to call Warning.warn
This allows Warning.warn to filter/process warning messages
generated by Kernel#warn.  Currently, Warning.warn can only handle
messages generated by the rb_warn/rb_warning C functions.

The Kernel#warn API is different than the Warning.warn API, this
tries to get similar behavior, but there are probably corner cases
where the behavior is different.

This makes str_end_with_asciichar in io.c no longer static so it
can be called from error.c.

[Feature #12944]
Author:    Jeremy Evans <code@jeremyevans.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-19 06:25:06 +00:00
nobu 09ae127bad io.c: fix race between read and close
* io.c (io_fillbuf): fix race between read and close and bail out
  in the case the IO gets closed before the reading thread achieve
  the lock.  [ruby-core:78845] [Bug #13076]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-27 11:43:34 +00:00
usa f2502cec8a revert a part of r57199
* io.c (io_fillbuf): revert a part of r57199 because it broke IO#getch.
  see also [Bug #13076]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-27 09:07:02 +00:00
nobu a757aa142b io.c: use io_close to close ARGF
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-27 07:39:29 +00:00
nobu 2fbc63b8a8 io.c: ARGF fd leak
* io.c (argf_next_argv): fix leak of fd after breaking in #each
  method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-27 07:18:27 +00:00
nobu 08ca33e98c io.c: fix race between read and close
* io.c (io_fillbuf): fix race between read and close, in the case
  the IO gets closed before the reading thread achieve the lock.
  [ruby-core:78845] [Bug #13076]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-26 14:14:18 +00:00
rhe ac8f9a0af7 io.c: [DOC] update outdated documentation of ARGF.close
As of Ruby 2.3, IO#close no longer raises IOError if the file is already
closed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-22 04:40:28 +00:00
nobu 1cc9c93ff9 io.c: update argf lineno
* io.c (argf_rewind): rewind line number in non-global ARGF
  instance.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20 08:25:03 +00:00