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

1914 Коммитов

Автор SHA1 Сообщение Дата
Masaki Matsushita 56dd578d7e IO.copy_stream: handle EOPNOTSUP instead of ENOTSUP 2020-08-29 16:10:58 +09:00
Masaki Matsushita 93df301048 IO.copy_stream: handle ENOTSUP on copy_file_range(2)
fallback to other methods on ENOTSUP.
some RedHat kernels may return ENOTSUP on an NFS mount.
[Feature #16965]
2020-08-29 15:38:07 +09:00
Peter Zhu 166cacc505
Fix corruption in ARGF.inplace
Extension string stored in `ARGF.inplace` is created using an api
designed for C string constants to create a Ruby string that
points at another Ruby string. When the original string is swept,
the extension string gets corrupted.

Reproduction script (on MacOS):

```ruby
#!/usr/bin/ruby -pi.bak

BEGIN {
  GC.start(full_mark: true)
  arr = []
  1000000.times do |x|
    arr << "fooo#{x}"
  end
}

puts "hello"
```

Co-Authored-By: Matt Valentine-House <31869+eightbitraptor@users.noreply.github.com>
2020-08-12 17:54:09 +09:00
Nobuyoshi Nakada d2bf6133f6
Remove trailing spaces [ci skip] 2020-07-20 13:34:16 +09:00
Samuel Williams f3462d99a3 Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.
Correctly capture thread before releasing GVL and pass as argument to
`rb_thread_scheduler_if_nonblocking`.
2020-07-20 13:20:58 +12:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 9e92292e30 rb_io_modestr_fmode: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 0e4ee71546 rb_io_each_codepoint: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Nobuyoshi Nakada 6f167da65b
Fixed a variable name [Bug #16903]
Fix up of 0e3b0fcdba

From: fd0 (Daisuke Fujimura)
2020-05-21 10:47:41 +09:00
Samuel Williams 0e3b0fcdba
Thread scheduler for light weight concurrency. 2020-05-14 22:10:55 +12:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada b5132d91c0
Refactored rb_readwrite_syserr_fail
* renamed argument `writable` as `waiting`
* hosited out creating and raising exception
* turned into a `switch`
2020-04-17 14:08:54 +09:00
Nobuyoshi Nakada 155f64e3c4
Raise EPIPE at broken pipe for the backward compatibility
Instead of SignalException for SIGPIPE, raise `Errno::EPIPE` with
instance variable `signo` and re-send that signal at exit.
[Feature #14413]
2020-04-15 21:05:39 +09:00
Nobuyoshi Nakada e6551d835f PAGER without fork&exec too [Feature #16754] 2020-04-12 14:58:13 +09:00
Nobuyoshi Nakada 6f28ebd585
Silence broken pipe error messages on STDOUT [Feature #14413]
Raise `SignalException` for SIGPIPE to abort when EPIPE occurs.
2020-04-11 09:30:19 +09:00
Nobuyoshi Nakada 63a5412db7
Make `#inspect` interruptible in `Kernel#p`
Only writing the inspected result and a newline is
uninterruptible.
2020-04-10 10:52:33 +09:00
Nobuyoshi Nakada 614d816a1f
Constified writev function family 2020-04-10 10:37:15 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Jeremy Evans e1e4ea8fa9 Set external encoding correctly for File.open('f', FILE::BINARY) on Windows
Previously, the external encoding was only set correctly for
File::BINARY if keyword arguments were provided.  This copies
the logic for the keyword arguments case to the no keyword
arguments case.  Possibly it should be refactored into a
separate function.

Fixes [Bug #16737]
2020-03-27 11:31:19 -07:00
Jeremy Evans 54499d7810 Remove support for passing nil to IO#ungetc
Fixes [Bug #13675]
2020-02-27 10:17:54 -08:00
Nobuyoshi Nakada 8a7e0aaaef
Warn non-nil `$/` [Feature #14240] 2020-02-23 13:37:40 +09:00
Nobuyoshi Nakada 6298ec2875
Warn non-nil `$\` [Feature #14240] 2020-02-23 13:37:40 +09:00
Nobuyoshi Nakada 588a86e32c
Warn non-nil `$,` in `IO#print` too 2020-02-23 13:37:40 +09:00
Nobuyoshi Nakada 041c2932e3
Pass keyword arguments to IOs properly [Bug #16639] 2020-02-18 14:35:46 +09:00
Nobuyoshi Nakada 913dc64eb6
Drop executable bit set by 25f2005a63 2020-01-22 08:54:49 +09:00
Nobuyoshi Nakada 5798d35ff6
Also check EWOULDBLOCK as well as EAGAIN 2020-01-21 22:45:10 +09:00
Xia Xionjun 25f2005a63 fix load error with EAGAIN
This is a fix related to the following issue.
rails/rails#33464

Not only in rails apps, some little ruby app with only 2 or 3 ruby
files reproduce the problem during many years.

When I edit linux ruby files by vs code via samba on windows, and
then I execute the ruby files on linux, "require_relative" will
sometimes not work properly.

My solution is to wait a monument if the required relative file is
busy.
2020-01-21 22:41:45 +09:00
Yusuke Endoh c6b26f5ccf io.c, ruby.c: include internal/variable.h for rb_gvar_readonly_setter
Same as 053f78e139.
emscripten requires a prototype declaration of rb_gvar_readonly_setter
if it is refered as a function pointer.
2020-01-09 23:57:46 +09:00
Nobuyoshi Nakada d7bef803ac Separate builtin initialization calls 2019-12-29 12:34:55 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Nobuyoshi Nakada 2b2030f265
Refined the warning message for $, and $;
[Bug #16438]
2019-12-20 15:09:23 +09:00
Nobuyoshi Nakada c6c67254fb
Added rb_warn_deprecated 2019-12-19 09:52:17 +09:00
Nobuyoshi Nakada e8c62836a6
IO#set_encoding_by_bom should err when encoding is already set
Except for ASCII-8BIT.  [Bug #16422]
2019-12-15 23:13:16 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
卜部昌平 c9ffe751d1 delete unused functions
Looking at the list of symbols inside of libruby-static.a, I found
hundreds of functions that are defined, but used from nowhere.

There can be reasons for each of them (e.g. some functions are
specific to some platform, some are useful when debugging, etc).
However it seems the functions deleted here exist for no reason.

This changeset reduces the size of ruby binary from 26,671,456
bytes to 26,592,864 bytes on my machine.
2019-11-14 20:35:48 +09:00
Nobuyoshi Nakada 99b1c19be4
builtin.h must be included *AFTER* vm_core.h 2019-11-08 16:31:57 +09:00
Nobuyoshi Nakada 20971799f2
Renamed `load_*.inc` as `*.rbinc` to utilize a suffix rule 2019-11-08 16:30:28 +09:00
Koichi Sasada 365557f111 Define IO#read/write_nonblock with builtins.
IO#read/write_nonblock methods are defined in prelude.rb with
special private method __read/write_nonblock to reduce keyword
parameters overhead. We can move them into io.rb with builtin
functions.
2019-11-08 10:03:19 +09:00
Yusuke Endoh 90b9900dc1 io.c (rb_update_max_fd): fail with a negative file descripter
Coverity Scan points out that ext/socket/unixsocket.c may pass -1 to
rb_update_max_fd.  I'm unsure whether it can happen actually or not, but
it would be good for the function to reject a negative value.
2019-10-13 00:49:18 +09:00
Yusuke Endoh c866663784 io.c (NUM2IOCTLREQ): Accept a value more than INT_MAX
ioctl accepts int as request arguments on some platforms, but some
requests are more than INT_MAX, e.g., RNDGETENTCNT(0x80045200).
Passing (0x80045200 | (-1 << 32)) may work around the issue, but it may
not work on a platform where ioctl accepts unsigned long.  So this
change uses NUM2LONG and then casts it to int.
2019-10-11 21:43:18 +09:00
Jeremy Evans 80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00
Nobuyoshi Nakada fc3bfd521d
Fixed the function signature to rb_rescue2 2019-09-11 21:36:00 +09:00
卜部昌平 3df37259d8 drop-in type check for rb_define_singleton_method
We can check the function pointer passed to
rb_define_singleton_method like how we do so in rb_define_method.
Doing so revealed many arity mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
卜部昌平 1663d347c9 delete `$` sign from C identifiers
They lack portability. See also
https://travis-ci.org/shyouhei/ruby/jobs/577164015
2019-08-27 15:52:26 +09:00
卜部昌平 ae2dc3f217 rb_define_hooked_variable now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies.  Some of them were literally decades old, going back
to dda5dc00cf.
2019-08-27 15:52:26 +09:00
卜部昌平 703783324c rb_ensure now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_ensure, which also revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 5c7c2d9951 rb_rescue / rb_rescue2 now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
Yusuke Endoh 8df25214de io.c: make ioctl_req_t int in Android
The second argument of ioctl seems to be int in Android.
Android is not a supported platform, but this one-line change allows
ruby to build by Android NDK r20.
2019-08-20 00:17:26 +09:00
Nobuyoshi Nakada c744b62698
io.c: export rb_io_extract_modeenc
* include/ruby/io.h (rb_io_enc_t): add typedef.

* io.c (rb_io_extract_modeenc): export.
2019-08-14 11:20:58 +09:00
Nobuyoshi Nakada 5b1bf8dd2d
UTF LE is fixed at least the first 2 bytes
* io.c (io_strip_bom): if the first 2 bytes are 0xFF0xFE, it
should be a little-endian UTF, 16 or 32.  [Bug #16099]
2019-08-13 23:38:05 +09:00
Nobuyoshi Nakada 314b50d7c0
#include <> for system headers 2019-08-09 23:10:06 +09:00
git a4c09342a2 * expand tabs. 2019-07-31 05:49:04 +09:00
Jeremy Evans ebc99e026d Do not change IO.pipe encodings if encodings explicitly given
This commit makes it so that if the binmode option is given with
any encoding arguments, the reader and writer IO objects are
not set to binary encoding.

Fixes [Bug #12989]
2019-07-30 12:12:59 -07:00
Aaron Patterson d8562ab2a4 Passing `binmode: true` to `IO.pipe` should behave like `binmode`
When passing `binmode: true` to `IO.pipe`, it should behave the same way
as calling `binmode` on each of the file handles.  It should set the
file to binmode *and* set the encoding to binary on the file.

Before this commit, passing `binmode: true` to `IO.pipe` would make
`binmode?` return `true`, but the file's encoding would remain the same
as the default encoding.  Passing `binmode: true` should make `binmode?`
return `true` *and* set the encoding to binary.
2019-07-30 12:03:09 -07:00
Yusuke Endoh 95de69df99 io.c (rb_file_open_internal): initialize all the fields
Just for case.  This will suppress the warning of Coverity Scan.
2019-07-14 16:18:32 +09:00
git 1d46642487 * expand tabs. 2019-07-14 13:57:57 +09:00
Yusuke Endoh 315d3adf0f Avoid io_tell whose return value is not used
In this case, flush_before_seek is enough.
This change will suppress a warning of Coverity Scan.
2019-07-14 13:49:39 +09:00
git 4018eee431 * expand tabs. 2019-07-11 20:14:57 +09:00
Nobuyoshi Nakada 3e7d002118
Check exception flag as a bool [Bug #15987] 2019-07-11 20:04:29 +09:00
Nobuyoshi Nakada ff7f71b288
O_EXCL has no meaning for fdopen
"exclusive access mode is not supported" exception has resulted in
empty "rubyheap-*.json" files after test/objspace/test_objspace.rb.
2019-06-28 12:02:33 +09:00
Nobuyoshi Nakada e717d6faa8
IO#set_encoding_by_bom
* io.c (rb_io_set_encoding_by_bom): IO#set_encoding_by_bom to set
  the encoding by BOM if exists.  [Bug #15210]
2019-06-13 18:13:05 +09:00
Nobuyoshi Nakada 1ca03dc4f7
Suppress warnings by gcc 9.1 2019-06-08 19:46:32 +09:00
Nobuyoshi Nakada 21de4a574f
io.c: fold very very long lines 2019-06-08 18:44:04 +09:00
Nobuyoshi Nakada 374c8f4eba
Fixed about ARGF.lineno
[Bug #15823]
2019-05-05 14:35:35 +09:00
Urabe, Shyouhei 7b7043e5da eliminate use of freed memory
rb_io_fptr_finalize_internal frees the memory region.

=================================================================
==85264==ERROR: AddressSanitizer: heap-use-after-free on address 0x610000000d8c at pc 0x5608e38077f7 bp 0x7ffee12d5440 sp 0x7ffee12d5438
READ of size 4 at 0x610000000d8c thread T0
    #0 0x5608e38077f6 in rb_io_memsize io.c:4749:24
    #1 0x5608e37a0481 in obj_memsize_of gc.c:3547:14
    #2 0x5608e37a4f30 in check_rvalue_consistency gc.c:1107:2
    #3 0x5608e37a2624 in RVALUE_OLD_P gc.c:1218:5
    #4 0x5608e37a5bae in rb_gc_force_recycle gc.c:6652:18
    #5 0x5608e38191f9 in rb_f_backquote io.c:9021:5
    #6 0x5608e3d8aa14 in call_cfunc_1 vm_insnhelper.c:2058:12
    #7 0x5608e3d6e23d in vm_call_cfunc_with_frame vm_insnhelper.c:2211:11
    #8 0x5608e3d54a35 in vm_call_cfunc vm_insnhelper.c:2229:12
    #9 0x5608e3d5253b in vm_call_method_each_type vm_insnhelper.c:2564:9
    #10 0x5608e3d51f50 in vm_call_method vm_insnhelper.c:2701:13
    #11 0x5608e3cf2de4 in vm_call_general vm_insnhelper.c:2734:12
    #12 0x5608e3d79918 in vm_sendish vm_insnhelper.c:3627:11
    #13 0x5608e3d06cf5 in vm_exec_core insns.def:789:11
    #14 0x5608e3d43700 in rb_vm_exec vm.c:1892:22
    #15 0x5608e3d47cbf in rb_iseq_eval_main vm.c:2151:11
    #16 0x5608e37620ca in ruby_exec_internal eval.c:262:2
    #17 0x5608e376198b in ruby_exec_node eval.c:326:12
    #18 0x5608e37617d0 in ruby_run_node eval.c:318:25
    #19 0x5608e35c9486 in main main.c:42:9
    #20 0x7f62e9421b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #21 0x5608e3522289 in _start (miniruby+0x15f289)

0x610000000d8c is located 76 bytes inside of 192-byte region [0x610000000d40,0x610000000e00)
freed by thread T0 here:
    #0 0x5608e359a2ed in free (miniruby+0x1d72ed)
    #1 0x5608e37af421 in objspace_xfree gc.c:9591:5
    #2 0x5608e37af3da in ruby_sized_xfree gc.c:9687:2
    #3 0x5608e3799ac8 in ruby_xfree gc.c:9694:5
    #4 0x5608e380746d in rb_io_fptr_finalize_internal io.c:4728:5
    #5 0x5608e38191ed in rb_f_backquote io.c:9020:5
    #6 0x5608e3d8aa14 in call_cfunc_1 vm_insnhelper.c:2058:12
    #7 0x5608e3d6e23d in vm_call_cfunc_with_frame vm_insnhelper.c:2211:11
    #8 0x5608e3d54a35 in vm_call_cfunc vm_insnhelper.c:2229:12
    #9 0x5608e3d5253b in vm_call_method_each_type vm_insnhelper.c:2564:9
    #10 0x5608e3d51f50 in vm_call_method vm_insnhelper.c:2701:13
    #11 0x5608e3cf2de4 in vm_call_general vm_insnhelper.c:2734:12
    #12 0x5608e3d79918 in vm_sendish vm_insnhelper.c:3627:11
    #13 0x5608e3d06cf5 in vm_exec_core insns.def:789:11
    #14 0x5608e3d43700 in rb_vm_exec vm.c:1892:22
    #15 0x5608e3d47cbf in rb_iseq_eval_main vm.c:2151:11
    #16 0x5608e37620ca in ruby_exec_internal eval.c:262:2
    #17 0x5608e376198b in ruby_exec_node eval.c:326:12
    #18 0x5608e37617d0 in ruby_run_node eval.c:318:25
    #19 0x5608e35c9486 in main main.c:42:9
    #20 0x7f62e9421b96 in __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

previously allocated by thread T0 here:
    #0 0x5608e359a56d in malloc (miniruby+0x1d756d)
    #1 0x5608e37aed12 in objspace_xmalloc0 gc.c:9416:5
    #2 0x5608e37aebe7 in ruby_xmalloc0 gc.c:9600:12
    #3 0x5608e37aea8b in ruby_xmalloc_body gc.c:9609:12
    #4 0x5608e37a6d64 in ruby_xmalloc gc.c:11469:12
    #5 0x5608e380e4b4 in rb_io_fptr_new io.c:8040:19
    #6 0x5608e380e446 in rb_io_make_open_file io.c:8077:10
    #7 0x5608e3850ea0 in pipe_open io.c:6707:5
    #8 0x5608e384edb4 in pipe_open_s io.c:6772:12
    #9 0x5608e381910b in rb_f_backquote io.c:9014:12
    #10 0x5608e3d8aa14 in call_cfunc_1 vm_insnhelper.c:2058:12
    #11 0x5608e3d6e23d in vm_call_cfunc_with_frame vm_insnhelper.c:2211:11
    #12 0x5608e3d54a35 in vm_call_cfunc vm_insnhelper.c:2229:12
    #13 0x5608e3d5253b in vm_call_method_each_type vm_insnhelper.c:2564:9
    #14 0x5608e3d51f50 in vm_call_method vm_insnhelper.c:2701:13
    #15 0x5608e3cf2de4 in vm_call_general vm_insnhelper.c:2734:12
    #16 0x5608e3d79918 in vm_sendish vm_insnhelper.c:3627:11
    #17 0x5608e3d06cf5 in vm_exec_core insns.def:789:11
    #18 0x5608e3d43700 in rb_vm_exec vm.c:1892:22
    #19 0x5608e3d47cbf in rb_iseq_eval_main vm.c:2151:11
    #20 0x5608e37620ca in ruby_exec_internal eval.c:262:2
    #21 0x5608e376198b in ruby_exec_node eval.c:326:12
    #22 0x5608e37617d0 in ruby_run_node eval.c:318:25
    #23 0x5608e35c9486 in main main.c:42:9
    #24 0x7f62e9421b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: heap-use-after-free io.c:4749:24 in
rb_io_memsize
Shadow bytes around the buggy address:
  0x0c207fff8160: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c207fff8170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c207fff8180: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c207fff8190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c207fff81a0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
=>0x0c207fff81b0: fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c207fff81c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c207fff81d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c207fff81e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c207fff81f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c207fff8200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==85264==ABORTING
2019-04-26 15:59:40 +09:00
nobu 3ee0648dc7 io.c: warn non-nil $,
* array.c (rb_ary_join_m): warn use of non-nil $,.

* io.c (rb_output_fs_setter): warn when set to non-nil value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-18 21:56:55 +00:00
nobu b9e52ef8b6 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 12:43:33 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
nobu 5ae753dfa3 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 06:44:41 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
nobu 23488589b3 io.c: chomp CR at the end of read buffer
* io.c (rb_io_getline_fast): chomp CR followed by LF but separated
  by the read buffer boundary.  [ruby-core:91707] [Bug #15642]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-07 05:11:46 +00:00
kazu f2d3b3623f Fix document and return value of `IO#autoclose=`
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20 07:19:39 +00:00
glass 43a45b3fed io.c: remove unused variable and fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-11 03:06:10 +00:00
glass 2d2a509612 io.c: check HAVE_FCOPYFILE
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-11 02:12:54 +00:00
glass cc1dbb61e0 io.c: get src_size from stp. Fix r66995.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-03 23:30:56 +00:00
glass e3fd9fa403 io.c: reuse results of fstat(2) in copy functions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-03 21:04:04 +00:00
glass 2210709b79 io.c: use fcopyfile(3) in IO.copy_stream if available
fixed r66930.

* io.c (nogvl_copy_stream_func): use fcopyfile(3) in IO.copy_stream if available

* configure.ac: check copyfile.h and fcopyfile(3)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-28 05:04:17 +00:00
glass 774c60955a Revert "io.c: use fcopyfile(3) in IO.copy_stream if available"
This reverts commit bd670062c4.
It fails on rubyspec.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-27 21:46:06 +00:00
svn f1a3be3565 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-27 20:55:38 +00:00
glass bd670062c4 io.c: use fcopyfile(3) in IO.copy_stream if available
* io.c (nogvl_copy_stream_func): use fcopyfile(3) in IO.copy_stream if available

* configure.ac: check copyfile.h and fcopyfile(3)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-27 20:55:26 +00:00
glass 12afc11fcd * io.c: use copy_file_range() if defined
* configure.ac: check copy_file_range()

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-21 10:11:04 +00:00
shyouhei d154bec0d5 setbyte / ungetbyte allow out-of-range integers
* string.c: String#setbyte to accept arbitrary integers [Bug #15460]

* io.c: ditto for IO#ungetbyte

* ext/strringio/stringio.c: ditto for StringIO#ungetbyte



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-15 06:41:58 +00:00
normal 0d4ba7b58d io.c (io_fflush): eliminate redundant rb_io_check_closed
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-06 10:41:07 +00:00
normal 48324dd4db io.c (io_write_nonblock): add RB_GC_GUARD, io_fflush may switch threads
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-06 10:09:30 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
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-12-06 07:49:24 +00:00
normal d7e4e50bdb io.c: fix clang -Werror,-Wshorten-64-to-32 on Linux sendfile
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29 23:30:28 +00:00
normal 1372c092a0 io.c: fix clang -Werror,-Wshorten-64-to-32 errors
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29 23:28:15 +00:00
svn 6ccc2379b2 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-29 22:37:35 +00:00
normal f47b38b016 io.c: favor comparisons against zero rather than -1
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-29 22:37:29 +00:00
normal 9d74d402e1 disable non-blocking pipes and sockets by default
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-29 20:00:00 +00:00
normal db7338fd75 io.c (rb_update_max_fd): use F_GETFL if possible
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 01:10:40 +00:00
svn b75a4591c8 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-28 00:35:27 +00:00
normal e432c52626 io.c: reduce IO.copy_stream stack usage on Linux
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-28 00:35:22 +00:00
normal a607c866dc io.c (struct copy_stream_struct): packing
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-27 22:20:45 +00:00
normal 608b9c2913 io.c: disable nonblocking-by-default on win32 pipes
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-24 19:59:51 +00:00
normal c0e20037f3 io.c: wait on FD readability w/o GVL reacquisition
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-24 08:23:26 +00:00
normal a6a7d988b4 io.c (io_fd_check_closed): prioritize cross-thread "stream closed"
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-23 21:38:41 +00:00
normal f9fcffedf6 io.c (fptr_finalize_flush): close race leading to EBADF
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-23 18:19:07 +00:00
normal 8a233ea67b io.c: revalidate fptr->fd after rb_io_wait_readable
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-22 22:44:06 +00:00
normal 6a65f2b1e4 io + socket: make pipes and sockets nonblocking by default
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-22 08:46:51 +00:00
kazu aa515c8d8c Remove unnecessary space
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20 03:03:01 +00:00
shyouhei 412b6b5b02 io.c: ungetbyte silently ignores upper bits
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-19 08:10:48 +00:00
normal eb95929206 io.c: include vm_core.h for VM_UNREACHABLE
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-18 03:37:04 +00:00
normal b5bb5ed0db io.c (novl_wait_for_single_fd): VM_UNREACHABLE instead of assert
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-11-18 01:37:46 +00:00
nobu fa8b08b424 Prefer `rb_fstring_lit` over `rb_fstring_cstr`
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-10-13 09:59:22 +00:00
kazu 842b735979 add 'x' mode character for O_EXCL
[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-09 08:49:09 +00:00
nobu 14ad644d84 io.c: fix non-ascii filename inplace edit
* 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-08-09 08:29:38 +00:00
normal 894628ac02 io.c: fix compilation when IOV_MAX is not defined
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-06-05 20:46:56 +00:00
normal 4e09f414fc thread.c: enable ppoll for FreeBSD 11.0 and later
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-15 03:49:21 +00:00
normal cda10c6d0b io.c: cleanup copy_stream wait-for-single-fd cases
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-14 23:40:55 +00:00
nobu 23666ac1c1 io.c: fix typo and phrase [ci skip]
[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-12 01:26:39 +00:00
shyouhei b121cfde5f nobody is using the return value of rb_io_fptr_finalize
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-04 15:03:37 +00:00
normal 45255c4233 use list_head_init instead of open-coding it
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-01 08:35:19 +00:00
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
nobu 9b6e1a9f38 io.c: update argf lineno
* io.c (argf_block_call_line): update line number in non-global
  ARGF instance.  [ruby-core:78728] [Bug #13051]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20 08:25:02 +00:00
nobu a2144bd72a chomp option
* io.c (extract_getline_opts): extract chomp option.
  [Feature #12553]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 07:28:09 +00:00
nobu 4e44f6ef86 [DOC] replace Fixnum with Integer [ci skip]
* numeric.c: [DOC] update document for Integer class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-26 06:11:23 +00:00
nobu ccc9841a82 prefer rb_syserr_fail
* dir.c (dir_initialize, dir_read): prefer rb_syserr_fail over
  rb_sys_fail.

* io.c (ruby_dup, rb_sysopen): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-21 07:40:47 +00:00
nobu 34d420acc4 io.c: copy_stream to duplex IO
* io.c (copy_stream_body): use IO to write to copy to duplex IO.
  http://twitter.com/knu/status/786505317974585344

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-13 10:41:34 +00:00
nobu 446924cbb7 io.c: fix typo
* io.c (prep_io): fix typo of struct member name.
  [ruby-core:77550] [Bug #12829]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-11 13:08:27 +00:00
nobu 047604ad9b io.c: reduce isatty on Cygwin [ci skip]
* io.c (prep_io): reduce isatty call (and its system call) on
  Cygwin.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-10 03:37:09 +00:00
nobu 941621946f io.c: use RB_INTEGER_TYPE_P
* io.c (fptr_finalize): use dedicated macro RB_INTEGER_TYPE_P.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-06 00:19:23 +00:00
hsbt 9fff0f9459 * io.c: Fixed equivalent ruby code with core implemention.
[fix GH-1429][ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-05 02:47:25 +00:00
nobu e7209358b9 io.c: check if Integer
* io.c (rb_file_initialize): check if fd is an Integer but not a
  Fixnum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 08:59:00 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
usa 0df79477bd * io.c (nogvl_fsync, nogvl_fdatasync): on Windows, just ignore if the
fd is associated to non-disk device.  if call fsync and/or fdatasync
  with such fds, it causes Errno::EBADF exception and the behavior is
  incomatible with ruby 2.1 and earlier unintendedly introduced.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-30 05:59:17 +00:00
nobu c463366dfd rb_funcallv
* *.c: rename rb_funcall2 to rb_funcallv, except for extensions
  which are/will be/may be gems.  [Fix GH-1406]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-29 11:57:14 +00:00
shugo ceca045485 * io.c (rb_io_s_read): add description of pipes to the documentation
of IO.read.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-07 23:46:51 +00:00
nobu 415059abf1 io.c: convert arguments just once
* io.c (rb_io_s_foreach, rb_io_s_readlines): convert arguments
  just once before reading, instead of conversions for each lines.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-07 07:31:09 +00:00
hsbt 2bd2001d16 * addr2line.c: drop to support ATARI ST platform. It was discontinued
more than two decades ago. [fix GH-1350] Patch by @cremno
* include/ruby/ruby.h: ditto.
* io.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-28 01:46:27 +00:00
nobu b3901a20a4 Restore documentation of ARGF
* io.c (Init_IO): [DOC] define dummy ARGF instead of ARGF.class to
  re-enable the generation of ARGF documentation.  [Fix GH-1358]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-21 02:12:55 +00:00
nobu aa107497cd fix build on no-fork-spawnv platforms
* process.c (rb_execarg_commandline): build command line string
  from argument vector in rb_execarg.
  [ruby-core:75611] [Bug #12398]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 15:36:34 +00:00
nobu cbde995b2f io.c: conditionally used functions
* io.c (pipe_atexit): only used on Windows

* io.c (rb_execarg_fixup_v): wrapper only used fork or spawnv is
  available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 15:30:29 +00:00
nobu 7803106c1b io.c: use PRI_OFFT_PREFIX for off_t
* io.c (do_io_advise): use configured PRI_OFFT_PREFIX instead of
  PRI_OFF_T_PREFIX to format off_t properly on Cygwin.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-15 13:54:57 +00:00
nobu bf5d6f0723 io.c: remove extra declarations
* io.c (rb_io_set_encoding): remove extra declarations,
  rb_std{in,out,err} are defined in this file.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-07 01:05:36 +00:00
nobu 38e5dd1be6 io.c: fix output of Array [ci skip]
* io.c (rb_obj_display): [DOC] fix output of Array, as Array#to_s
  is same as Array#inspect since 1.9.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-06 13:43:42 +00:00
nobu d4819da611 parse without $.
* io.c (rb_io_gets_internal): read one line from an IO without
  setting ARGF.lineno.

* parse.y (lex_io_gets): use rb_io_gets_internal not to affect
  $. global variable.

* ruby.c (load_file): no longer reset $.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-24 08:21:04 +00:00
nobu 610e39e949 io.c: rb_io_open_generic
* io.c (rb_io_open_generic): split from rb_io_open without
  argument conversions.

* io.c (rb_io_s_binread): get rid of unnecessary object creation
  and conversion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-31 03:11:14 +00:00
nobu e7cf203103 io.c: constify
* io.c (rb_file_open_generic, pipe_open, pipe_open_s): constify
  convconfig parameter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-31 02:58:33 +00:00
nobu 8a78e0f6c0 io.c: suppress warning
* io.c (rb_update_max_fd): get rid of unused-value warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-19 08:36:02 +00:00
normal 2b26565ebb io.c: remove obsolete rb_deferr global variable
This was made obsolete by r4190 back in July 2003.  Furthermore,
this existed less than 3 months as it was only introduced in
r3782.

So with absolutely no references to rb_deferr, I doubt any vim
plugin would care anymore.

ChangeLog: fixup indent of my previous commit, oops :X

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-10 04:44:08 +00:00
normal edea151a4b IO#readpartial rejects bad args
Sometimes a sleepy developer will want to swap read_nonblock
for readpartial forget to remove "exception: false"

* io.c (io_getpartial): remove unused kwarg from template
* test/ruby/test_io.rb (test_readpartial_bad_args): new
  [Bug #11885]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-27 06:15:06 +00:00
nobu f9adadc5e6 rb_readwrite_syserr_fail
* io.c (rb_readwrite_syserr_fail): works with the given errno than
  thread local errno.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 14:58:47 +00:00
nobu f4166e2dd7 prefer rb_syserr_fail
* file.c, io.c, util.c: prefer rb_syserr_fail with saved errno
  over setting errno then call rb_sys_fail, not to be clobbered
  potentially and to reduce thread local errno accesses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 08:57:48 +00:00
hsbt 52cd994814 * enum.c: fix a typo in documentation.
[ci skip][fix GH-1140] Patch by @jutaz
* io.c: ditto.
* iseq.c: ditto.
* numeric.c: ditto.
* process.c: ditto.
* string.c: ditto.
* vm_trace.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-14 02:52:14 +00:00
hsbt 6851be0f0c * compile.c: fix typos.
[ci skip][fix GH-1140] Patch by @jutaz
* dir.c: ditto.
* gc.c: ditto.
* io.c: ditto.
* node.h: ditto.
* thread_pthread.c: ditto.
* vm_insnhelper.c: ditto.
* vsnprintf.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-14 02:51:13 +00:00
nobu add73a8713 io.c: encoding in warnings
* io.c (parse_mode_enc): preserve encoding of mode string in
  warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-13 09:49:25 +00:00
nobu b861d5473c io.c: BOM with non-UTF
* io.c (io_encname_bom_p): check BOM prefix only, not including
  UTF prefix.
* io.c (parse_mode_enc): warn BOM with non-UTF encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-13 09:48:27 +00:00