1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
Commit graph

14743 commits

Author SHA1 Message Date
Lars Kanis
6594623f62 Fix Marshal.dump(closed_io) to raise TypeError and allow encoding on closed IO
Mashalling a closed IO object raised "closed stream (IOError)" before instead of TypeError.
This changes IO#(in|ex)ternal_encoding to still return the encoding even if the underlying FD is closed.

Fixes bug 
2021-08-22 10:33:22 +09:00
Jeremy Evans
48c8df9e0e
Allow tracing of optimized methods
This updates the trace instructions to directly dispatch to
opt_send_without_block.  So this should cause no slowdown in
non-trace mode.

To enable the tracing of the optimized methods, RUBY_EVENT_C_CALL
and RUBY_EVENT_C_RETURN are added as events to the specialized
instructions.

Fixes [Bug ]

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2021-08-21 10:15:01 -07:00
Yusuke Endoh
5e9598baea [ruby/error_highlight] Fixed the argument for DidYouMean.formatter=
Looks like this bug was hidden by did_you_mean's rescuing any
exceptions.

https://github.com/ruby/error_highlight/commit/7a8f0b4796
2021-08-20 16:27:07 +09:00
Yusuke Endoh
cad83fa3c4 ast.c: Rename "save_script_lines" to "keep_script_lines"
... as per ko1's preference. He is preparing to extend this feature to
ISeq for his new debugger. He prefers "keep" to "save" for this wording.
This API is internal and not included in any released version, so I
change it in advance.
2021-08-20 16:18:36 +09:00
Shugo Maeda
754adbee91
Module#ancestors should not return superclasses of refinements
[ruby-core:86949] [Bug ]

Reported by Eregon (Benoit Daloze).  Thanks!
2021-08-20 10:42:01 +09:00
Nobuyoshi Nakada
6963f8f743
Remove old warning aged nearly 8 years 2021-08-19 17:44:48 +09:00
Kazuki Tsujimoto
ecb6d6a4ef
Allow omission of parentheses in one line pattern matching [Feature ] 2021-08-19 17:07:58 +09:00
Martin Dürst
fd7f61cf21 Take into account data in emoji-variation-sequences.txt in tests.
The emoji data in emoji-variation-sequences.txt was not used for
in test/ruby/enc/test_emoji_breaks.rb, for unknown reasons.
It turned out that the format of each of the emoji data/test files
is slightly different, and that we didn't take into account that
empty fields after a semicolon, as present in
emoji-variation-sequences.txt, led to less fields than expected
when using split.
This addresses issue .
2021-08-17 16:03:52 +09:00
Nobuyoshi Nakada
2aa6826e81 Extract the wrapped value when yydebug [Bug ] 2021-08-15 11:40:06 +09:00
Kazuki Tsujimoto
4568ba0711
Show verbose error messages when single pattern match fails
[0] => [0, *, a]
    #=> [0] length mismatch (given 1, expected 2+) (NoMatchingPatternError)

Ignore test failures of typeprof caused by this change for now.
2021-08-15 09:38:24 +09:00
aycabta
9f88135f78 [ruby/readline-ext] Give up Editline
https://github.com/ruby/readline-ext/commit/d924cfc1e6
2021-08-14 22:13:56 +09:00
aycabta
2c056816c4 [ruby/reline] Add workspace member for the latest IRB's implementation
https://github.com/ruby/reline/commit/8b55fc8fee
2021-08-14 22:13:31 +09:00
aycabta
a2f649374d [ruby/reline] Remove private visibility
https://github.com/ruby/reline/commit/fa54e521da
2021-08-14 22:13:31 +09:00
Takashi Kokubun
ac4d53bd46
Don't cancel JIT-ed code on TracePoint :class
events get enabled
2021-08-12 23:26:44 -07:00
Takashi Kokubun
b3f8c491ef
Print JIT cancel when all JIT-ed code is cancelled 2021-08-12 23:11:38 -07:00
aycabta
5196b171d9 Revert "Try to run test_interrupt_in_other_thread with Editline"
This reverts commit c66b27efbb.
2021-08-12 19:47:41 +09:00
aycabta
c66b27efbb Try to run test_interrupt_in_other_thread with Editline 2021-08-12 15:35:05 +09:00
aycabta
e5f6cd7045 Outer block is required to rescue Timeout::Error 2021-08-12 07:52:39 +09:00
aycabta
c06b39d1d1 Add TODO comment to #test_interrupt_in_other_thread 2021-08-11 17:45:31 +09:00
aycabta
c59da370a5 Add comments about testing steps 2021-08-11 14:08:45 +09:00
aycabta
4f324514aa Put the result of the process into a variable once
To make the meaning of assertion easier to understand,
2021-08-11 14:08:45 +09:00
aycabta
01e49af81d Stop exiting to show "SUCCESS" 2021-08-11 14:08:45 +09:00
aycabta
2217b82af1 Add logging about Errno::EPIPE 2021-08-11 14:08:45 +09:00
aycabta
7d84251500 Write log to stdout immediately 2021-08-11 14:08:45 +09:00
aycabta
67e06102a3 Stop checking char from "read"
Because it's sometimes nil due to race condition.
2021-08-11 14:08:45 +09:00
aycabta
7b10f55354 Break immediately if assertions finished 2021-08-11 14:08:45 +09:00
aycabta
7319b1fa2c Add "START" log 2021-08-11 14:08:45 +09:00
Nobuyoshi Nakada
c3964a313e
Assert for duplicated ARGF [Bug ] 2021-08-10 23:40:45 +09:00
Nobuyoshi Nakada
7de7e9fdb7
Assert that each contents are read [Bug ] 2021-08-10 23:40:45 +09:00
Koichi Sasada
42b6dc84d3 add some lines to delete unused TracePoint
`TracePoint.stat` returns the "to be deleted" TP numbers, and
http://rubyci.s3.amazonaws.com/graviton2/ruby-master/log/20210810T030003Z.fail.html.gz
shows there is a "to be deleted" TP.

This patch uses only :line event and add some lines to allow MRI
deletes "to be deleted" TPs.
2021-08-10 15:47:52 +09:00
Csaba Henk
8df1ace64a Fix ARGF.read(length) short read [Bug ] 2021-08-10 11:32:45 +09:00
aycabta
cc1d88daba Add comment about I/O that is not tty 2021-08-10 02:52:56 +09:00
aycabta
5e633fb99e Omit on Readline 7.0 because it's wrong behaviour for not TTY env 2021-08-09 18:17:07 +09:00
Samuel Williams
6f6a84f2f3 Extended logging for debugging readline failures. 2021-08-09 17:03:33 +12:00
Samuel Williams
48c43f7783 Rework the readline test to be more robust.
- Capture that the child is started by initial log line.
- More robust handling of child status reaping.
- Direct exit without sucess mesage if `#readline` receives input.
2021-08-09 11:40:56 +12:00
aycabta
ca2dd6d35a Use #full_message instead of #backtrace_locations 2021-08-08 15:43:03 +09:00
aycabta
40ccb87a49 Show backtrace locations when I/O timed out 2021-08-08 09:25:12 +09:00
aycabta
1fe73128cd Use TERM=xterm for tests on Solaris 2021-08-07 22:58:59 +09:00
aycabta
f092a9606e Set TERM env for some CI environments 2021-08-07 21:16:49 +09:00
Jeremy Evans
d16b68cb22 Use Rational for Float#round with ndigits > 14
ndigits higher than 14 can result in values that are slightly too
large due to floating point limitations.  Converting to rational
for the calculation and then back to float fixes these issues.

Fixes [Bug ]
Fixes [Bug ]

Co-authored by: Yusuke Endoh <mame@ruby-lang.org>
2021-08-06 15:03:51 -07:00
Jeremy Evans
1a05dc03f9 Make backtrace generation work outward from current frame
This fixes multiple bugs found in the partial backtrace
optimization added in 3b24b7914c.
These bugs occurs when passing a start argument to caller where
the start argument lands on a iseq frame without a pc.

Before this commit, the following code results in the same
line being printed twice, both for the #each method.

```ruby
def a; [1].group_by { b } end
def b; puts(caller(2, 1).first, caller(3, 1).first) end
a
```

After this commit and in Ruby 2.7, the lines are different,
with the first line being for each and the second for group_by.

Before this commit, the following code can either segfault or
result in an infinite loop:

```ruby
def foo
  caller_locations(2, 1).inspect # segfault
  caller_locations(2, 1)[0].path # infinite loop
end

1.times.map { 1.times.map { foo } }
```

After this commit, this code works correctly.

This commit completely refactors the backtrace handling.
Instead of processing the backtrace from the outermost
frame working in, process it from the innermost frame
working out.  This is much faster for partial backtraces,
since you only access the control frames you need to in
order to construct the backtrace.

To handle cfunc frames in the new design, they start
out with no location information.  We increment a counter
for each cfunc frame added.  When an iseq frame with pc
is accessed, after adding the iseq backtrace location,
we use the location for the iseq backtrace location for
all of the directly preceding cfunc backtrace locations.

If the last backtrace line is a cfunc frame, we continue
scanning for iseq frames until the end control frame, and
use the location information from the first one for the
trailing cfunc frames in the backtrace.

As only rb_ec_partial_backtrace_object uses the new
backtrace implementation, remove all of the function
pointers and inline the functions.  This makes the
process easier to understand.

Restore the Ruby 2.7 implementation of backtrace_each and
use it for all the other functions that called
backtrace_each other than rb_ec_partial_backtrace_object.
All other cases requested the entire backtrace, so there
is no advantage of using the new algorithm for those.
Additionally, there are implicit assumptions in the other
code that the backtrace processing works inward instead
of outward.

Remove the cfunc/iseq union in rb_backtrace_location_t,
and remove the prev_loc member for cfunc.  Both cfunc and
iseq types can now have iseq and pc entries, so the
location information can be accessed the same way for each.
This avoids the need for a extra backtrace location entry
to store an iseq backtrace location if the final entry in
the backtrace is a cfunc. This is also what fixes the
segfault and infinite loop issues in the above bugs.

Here's Ruby pseudocode for the new algorithm, where start
and length are the arguments to caller or caller_locations:

```ruby
end_cf = VM.end_control_frame.next
cf = VM.start_control_frame
size = VM.num_control_frames - 2
bt = []
cfunc_counter = 0

if length.nil? || length > size
  length = size
end

while cf != end_cf && bt.size != length
  if cf.iseq?
    if cf.instruction_pointer?
      if start > 0
        start -= 1
      else
        bt << cf.iseq_backtrace_entry
        cf_counter.times do |i|
          bt[-1 - i].loc = cf.loc
        end
        cfunc_counter = 0
      end
    end
  elsif cf.cfunc?
    if start > 0
      start -= 1
    else
      bt << cf.cfunc_backtrace_entry
      cfunc_counter += 1
    end
  end

  cf = cf.prev
end

if cfunc_counter > 0
  while cf != end_cf
    if (cf.iseq? && cf.instruction_pointer?)
      cf_counter.times do |i|
        bt[-i].loc = cf.loc
      end
    end
    cf = cf.prev
  end
end
```

With the following benchmark, which uses a call depth of
around 100 (common in many Ruby applications):

```ruby
class T
  def test(depth, &block)
    if depth == 0
      yield self
    else
      test(depth - 1, &block)
    end
  end
  def array
    Array.new
  end
  def first
    caller_locations(1, 1)
  end
  def full
    caller_locations
  end
end

t = T.new
t.test((ARGV.first || 100).to_i) do
  Benchmark.ips do |x|
    x.report ('caller_loc(1, 1)') {t.first}
    x.report ('caller_loc') {t.full}
    x.report ('Array.new') {t.array}
    x.compare!
  end
end
```

Results before commit:

```
Calculating -------------------------------------
    caller_loc(1, 1)    281.159k (_ 0.7%) i/s -      1.426M in   5.073055s
          caller_loc     15.836k (_ 2.1%) i/s -     79.450k in   5.019426s
           Array.new      1.852M (_ 2.5%) i/s -      9.296M in   5.022511s

Comparison:
           Array.new:  1852297.5 i/s
    caller_loc(1, 1):   281159.1 i/s - 6.59x  (_ 0.00) slower
          caller_loc:    15835.9 i/s - 116.97x  (_ 0.00) slower
```

Results after commit:

```
Calculating -------------------------------------
    caller_loc(1, 1)    562.286k (_ 0.8%) i/s -      2.858M in   5.083249s
          caller_loc     16.402k (_ 1.0%) i/s -     83.200k in   5.072963s
           Array.new      1.853M (_ 0.1%) i/s -      9.278M in   5.007523s

Comparison:
           Array.new:  1852776.5 i/s
    caller_loc(1, 1):   562285.6 i/s - 3.30x  (_ 0.00) slower
          caller_loc:    16402.3 i/s - 112.96x  (_ 0.00) slower
```

This shows that the speed of caller_locations(1, 1) has roughly
doubled, and the speed of caller_locations with no arguments
has improved slightly.  So this new algorithm is significant faster,
much simpler, and fixes bugs in the previous algorithm.

Fixes [Bug ]
2021-08-06 10:15:01 -07:00
Nobuyoshi Nakada
3e7fb4b91d
Check the result of tigetstr 2021-08-06 13:34:25 +09:00
Yusuke Endoh
7af21a78fa test/reline/test_terminfo.rb: skip when setupterm fails
http://rubyci.s3.amazonaws.com/solaris11-gcc/ruby-master/log/20210806T000008Z.fail.html.gz
```
  1) Error:
Reline::Terminfo::Test#test_tigetstr:
Reline::Terminfo::TerminfoError: The terminfo database could not be found.
    /export/home/chkbuild/chkbuild-gcc/tmp/build/20210806T000008Z/ruby/lib/reline/terminfo.rb:84:in `setupterm'
    /export/home/chkbuild/chkbuild-gcc/tmp/build/20210806T000008Z/ruby/test/reline/test_terminfo.rb:6:in `setup'
```
2021-08-06 10:39:25 +09:00
aycabta
e687b6f4da Show Readline::VERSION for debugging 2021-08-06 03:55:58 +09:00
aycabta
9b56668bf8 Omit test_interrupt_in_other_thread with Editline 2021-08-06 03:50:02 +09:00
aycabta
6414334d3c Fix reversal of assertion result 2021-08-06 03:17:51 +09:00
aycabta
cd57b39f79 Fix control structure to preperly catch Timeout::Error 2021-08-06 03:15:58 +09:00
aycabta
1cb5a669d3 Show log when timed out 2021-08-05 19:39:22 +09:00
aycabta
042d4c8133 Remove an unused variable 2021-08-04 23:35:08 +09:00
Nobuyoshi Nakada
594c3df9a9
Tests for Windows can run only on Windows
Should not directly require "reline/windows.rb" which should be
loaded by "reline.rb".
2021-08-05 13:58:07 +09:00