Commit graph

18546 commits

Author SHA1 Message Date
KJ Tsanaktsidis
31371b2e24 Fix CRLF -> LF conversion on read for rb_io_fdopen & rb_file_open
When opening a file with `File.open`, and then setting the encoding with
`IO#set_encoding`, it still correctly performs CRLF -> LF conversion on
Windows when reading files with a CRLF line ending in them (in text
mode).

However, the file is opened instead with either the `rb_io_fdopen` or
`rb_file_open` APIs from C, the CRLF conversion is _NOT_ set up
correctly; it works if the encoding is not specified, but if
`IO#set_encoding` is called, the conversion stops happening. This seems
to be because the encflags never get ECONV_DEFAULT_NEWLINE_DECORATOR
set in these codepaths.

Concretely, this means that the conversion doesn't happen in the
following circumstances:
  * When loading ruby files with require (that calls rb_io_fdopen)
  * When parsing ruuby files with RubyVM::AbstractSyntaxTree (that calls
    rb_file_open).
This then causes the ErrorHighlight tests to fail on windows if git has
checked them out with CRLF line endings - the error messages it's
testing wind up with literal \r\n sequences in them because the iseq
text from the parser contains un-newline-converted strings.

This commit fixes the problem by copy-pasting the relevant snippet which
sets this up in `rb_io_extract_modeenc` (for the File.open path) into
the relevant codepaths for `rb_io_fdopen` and `rb_file_open`.

[Bug #20101]
2024-01-10 21:02:23 +11:00
Hiroshi SHIBATA
d16f992e1b Extract mutex_m as bundled gems 2024-01-10 17:28:16 +09:00
Hiroya Fujinami
8b65d15ff0
Fix test case for test_match_cache_with_peek_optimization (#9466) 2024-01-10 13:40:20 +09:00
Hiroya Fujinami
597955aae8
Fix to work match cache with peek next optimization (#9459) 2024-01-10 11:22:23 +09:00
Peter Zhu
55b7121358 [PRISM] Frozen string literals should be fstrings
Frozen string literals should not just be frozen, but deduplicated as an
fstring so that two string literals with the same contents are the exact
same object.

Fixes ruby/prism#2095.
2024-01-09 12:24:18 -05:00
Kevin Newton
88d7838445 [ruby/prism] Fix assertion on spanning heredocs
e190308845
2024-01-09 15:15:52 +00:00
yui-knk
db476cc71c Introduce NODE_SYM to manage symbol literal
`:sym` was managed by `NODE_LIT` with `Symbol` object.
This commit introduces `NODE_SYM` so that

1. Symbol literal is detectable from AST Node
2. Reduce dependency on ruby object
2024-01-09 16:07:19 +09:00
dependabot[bot]
94a98ce632 [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.85 to 0.9.86.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.85...v0.9.86)

---
updated-dependencies:
- dependency-name: rb-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

6ec9f14b61
2024-01-08 19:40:44 +00:00
dependabot[bot]
4c3c5b645f [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.85 to 0.9.86.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.85...v0.9.86)

---
updated-dependencies:
- dependency-name: rb-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

070a6d9398
2024-01-08 19:40:28 +00:00
Kevin Newton
d1d50a0505 [ruby/prism] Handle parsing a line break in a receiver of a method
4d5f43ecbc
2024-01-08 14:34:59 +00:00
Peter Zhu
b3d6128049 Fix memory leak in grapheme clusters
[Bug #20150]

String#grapheme_cluters and String#each_grapheme_cluster leaks memory
because if the string is not UTF-8, then the created regex will not
be freed.

For example:

    str = "hello world".encode(Encoding::UTF_32LE)

    10.times do
      1_000.times do
        str.grapheme_clusters
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    26000
    42256
    59008
    75792
    92528
    109232
    125936
    142672
    159392
    176160

After:

    9264
    9504
    9808
    10000
    10128
    10224
    10352
    10544
    10704
    10896
2024-01-08 09:14:04 -05:00
Stan Lo
8f4eda5092 [ruby/irb] Make SourceFinder ignore binary sources
(https://github.com/ruby/irb/pull/836)

73b35bb7f4
2024-01-08 12:42:39 +00:00
Peter Zhu
189c8077aa Label memory leak test 2024-01-07 10:05:20 -05:00
Nobuyoshi Nakada
7fcc6f04ac [ruby/rdoc] Visibility should begin from public for each scope
Even for singleton class definition such as `class << self` that
shares the same container with the outer scope, its visibility is
separated and set to `public` by default.

baf26363b9
2024-01-07 11:39:46 +00:00
Nobuyoshi Nakada
2325b72cf3 [ruby/rdoc] Singleton method visibility should be isolated
Each singleton method definition of the form `def recv.method` has
visibility separate from the outer scope and is set to `public` by
default.

810913a7ea
2024-01-07 11:39:45 +00:00
yui-knk
9d3dcb86d1 Check hash key duplication for __LINE__ and __FILE__ 2024-01-07 14:32:10 +09:00
S-H-GAMELINKS
1b8d01136c Introduce Numeric Node's 2024-01-07 09:24:34 +09:00
Nobuyoshi Nakada
d1de2a34c1 [ruby/rdoc] Rename and move the tests for --locale option [ci skip]
b2a35ee39d
2024-01-06 10:23:41 +00:00
Nobuyoshi Nakada
f6847e9456 [ruby/rdoc] Ignore locale at write_options
`@locale` is set from `@locale_name` and loaded from `@locale_dir`
after `write_options`, and `RDoc::I18n::Locale` does not seem to
expected to be loaded.

fd610f7023
2024-01-06 10:17:49 +00:00
Rian McGuire
913b26d0fd Add test case for GC.measure_total_time 2024-01-06 17:36:35 +11:00
Takashi Kokubun
7f9c174102
YJIT: Let RubyVM::YJIT.enable respect --yjit-stats (#9415) 2024-01-05 14:08:57 -05:00
Jeremy Evans
4d03140009 [ruby/net-http] Don't invoke response block more than once due to retry
If a socket error occurs while performing a streaming download via
the response block provided to transport_request, avoid calling
the response block again as this would result in duplicate data
received by the client.

Fixes https://github.com/ruby/net-http/pull/86
Fixes https://github.com/ruby/net-http/pull/87

Fixes [Bug #11526]

114d01b092

Co-authored-by: Jeremy Stanley <jeremy@instructure.com>
2024-01-05 16:51:37 +00:00
Jeremy Evans
37657c79b6 [ruby/uri] Make URI#to_s prepend relative path with / if there is a host or port
Otherwise, the path could be considered part of the host or port.

This is better than modifying the path to make it absolute when
a host or port is set.  We could also raise for invalid paths
when a host or port is set using check_path, but that results
in weird errors, and won't catch issues (such as ftp allowing a
relative path).

Fixes [Bug #19916]

ac32aa005b
2024-01-05 16:07:55 +00:00
yui-knk
6d67dfc9ea Add test cases for duplicated `when\' clause warnings
Add test cases for `__LINE__` and `__FILE__` because
they were managed by NODE_LIT and NODE_STR but changed to
be managed by dedicated NODE now.
2024-01-05 12:14:13 +09:00
Peter Zhu
6c252912af Memory leak when duplicating identhash
[Bug #20145]

Before this commit, both copy_compare_by_id and hash_copy will create a
copy of the ST table, so the ST table created in copy_compare_by_id will
be leaked.

    h = { 1 => 2 }.compare_by_identity

    10.times do
      1_000_000.times do
        h.select { false }
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    110736
    204352
    300272
    395520
    460704
    476736
    542000
    604704
    682624
    770528

After:

    15504
    16048
    16144
    16256
    16320
    16320
    16752
    16752
    16752
    16752
2024-01-04 11:25:31 -05:00
tomoya ishida
542011ff68 [ruby/reline] Fix pasting tab-indented code crash
(https://github.com/ruby/reline/pull/630)

90155fd0d9
2024-01-04 11:53:06 +00:00
TSUYUSATO Kitsune
a25329e0da [ruby/prism] Fix parsing pinned local variable pattern for numbered parameter
Fix https://github.com/ruby/prism/pull/2094

The part of `parse_variable_call` for variables was split into a new
function `parse_variable` and used it.

4c5fd1a746
2024-01-03 17:20:33 +00:00
Kevin Newton
3a3fcf56d0 [ruby/prism] Fix rational when parsing non decimal integer
75d4331f7f
2024-01-03 17:18:02 +00:00
Kevin Newton
0215965df4 [ruby/prism] Better error recovery for content after unterminated heredoc
c2d325a886
2024-01-03 16:46:08 +00:00
dependabot[bot]
fc48a67906 [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.84 to 0.9.85.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.84...v0.9.85)

---
updated-dependencies:
- dependency-name: rb-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

8a3a85404a
2024-01-03 14:15:06 +00:00
Stan Lo
66e0d92de5 [ruby/irb] Avoid completing empty input
(https://github.com/ruby/irb/pull/832)

The candidate list for empty input is all methods + all variables +
all constants + all keywords. It's a long list that is not useful.

812dc2df7b
2024-01-03 13:47:51 +00:00
Kevin Newton
adbfbd822f [ruby/prism] Ignore visibility flag
55b049ddac
2024-01-02 20:59:19 +00:00
TSUYUSATO Kitsune
0ee625ceae [ruby/prism] Fix to check multiple block arguments for forwarding arg
Fix https://github.com/ruby/prism/pull/2111

21ca243d0a
2024-01-02 19:08:15 +00:00
Kevin Newton
23beceedb7 [ruby/prism] IndexTargetNode should always have ATTRIBUTE_WRITE
Because this is a user-facing change, we also need to deal with the
fact that CRuby 3.3.0 was just released.

In order to support workflows that want to parse exactly as CRuby
parses in a specific version, this PR introduces a new option to
the options struct that is "version". This allows you to specify
that you want "3.3.0" parsing.

I'm not sure if this is the correct solution. Another solution is
to just fork and keep around the old branch for security patches.
Or we could keep around a copy of the source files within this
repository as another directory and only update when necessary.
There are a lot of potential solutions here.

Because this change is so small and the check for it is so minimal,
I've decided to go with this enum. If this ends up entirely
cluttering the codebase with version checks, we'll come up with
another solution. But for now this works, so we're going to go in
this direction for a bit until we determine it's no longer working.

d8c7e6bd10
2024-01-02 18:51:18 +00:00
Peter Zhu
b959263b58 Fix Exception#detailed_message for GC compaction
Before this commit, the test fails with RGENGC_CHECK_MODE enabled:

    TestException#test_detailed_message_under_gc_compact_stress [test/ruby/test_exception.rb:1466]:
    <"\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" +
    "\e[1mbar\e[m\n" +
    "\e[1mbaz\e[m"> expected but was
    <"\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" +
    "\e[1m\x00\x00\x00\x00\x00\x00\x00\e[m">.
2024-01-02 12:03:31 -05:00
yui-knk
7a050638b1 Introduce NODE_FILE
`__FILE__` was managed by `NODE_STR` with `String` object.
This commit introduces `NODE_FILE` and `struct rb_parser_string` so that

1. `__FILE__` is detectable from AST Node
2. Reduce dependency ruby object
2024-01-02 14:19:42 +09:00
dependabot[bot]
91a0d1c437 [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.84 to 0.9.85.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.84...v0.9.85)

---
updated-dependencies:
- dependency-name: rb-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

d296738398
2024-01-02 02:20:25 +00:00
yui-knk
5993d0f5f2 Add a test case for __LINE__ assignment in condition warning 2024-01-02 09:50:32 +09:00
yui-knk
6ec4d203f7 Warn "literal in condition" for __LINE__
Print warning for a code like

```ruby
if __LINE__
end

# => warning: literal in condition
```
2024-01-02 09:50:32 +09:00
Luke Gruber
e12d4c654e Don't create T_MATCH object if /regexp/.match(string) doesn't match
Fixes [Bug #20104]
2024-01-01 13:28:26 -08:00
Stan Lo
676748abca [ruby/irb] Make show_source resolve top-level constant names
(https://github.com/ruby/irb/pull/831)

5843616c78
2024-01-01 17:40:38 +00:00
tomoya ishida
c0e3c3b6fe [ruby/irb] Fix display_document params in noautocomplete mode
(https://github.com/ruby/irb/pull/826)

* Fix display_document params in noautocomplete mode

* Fix wrong preposing and target order in display_document

The fixed wrong-ordered value is not used in RegexpCompletor, so this change does not affect the test.

08208adb5e
2024-01-01 13:57:15 +00:00
Sorah Fukumori
d3933fc753 [ruby/net-http] Renew test certificates
The private key is replaced with a public known test key published at
[RFC 9500].

Also lifetime has been extended to 10 years from 4 years.

[RFC 9500]: https://www.rfc-editor.org/rfc/rfc9500.html

4ab6c4a500
2024-01-01 11:51:15 +00:00
Sorah Fukumori
cd41177815 [ruby/irb] test_recovery_sigint: Ensure precondition is met
(https://github.com/ruby/irb/pull/829)

* test_recovery_sigint: Ensure precondition is met

test_recovery_sigint depends on its process has SIG_DEF sigaction for
SIGINT. When its parent process set SIG_IGN which inherits to children,
then this test fails. This patch ensures this precondition met
regardless of inherited sigaction from its parent.

* Add test for restoration of other SIGINT handlers

Add another variant of test_recovery_sigint to ensure IRB to preserve
existing SIGINT handler other than SIG_DEF.

77ee59d026
2024-01-01 10:58:35 +00:00
Stan Lo
5c81fd6886 [ruby/irb] Remove redundant env cleanup in rendering test
(https://github.com/ruby/irb/pull/827)

99b0017d75
2024-01-01 10:57:17 +00:00
Nobuyoshi Nakada
569a06aa2f [ruby/rdoc] Allow empty name rdoc-ref as a local link
914a6af137
2023-12-31 15:19:50 +00:00
Peter Zhu
8e32c01742 Change test_warmup_frees_pages to check each size pool
This should help in debugging the intermittent test failures on CI:

    TestProcess#test_warmup_frees_pages [test/ruby/test_process.rb:2779]:
    <201> expected but was
    <202>.
2023-12-29 22:14:38 -05:00
Hiroya Fujinami
bb59696614
Fix [Bug #20098]: set counter value for {n,m} repetition correctly (#9391) 2023-12-29 19:30:24 +09:00
Dylan Thacker-Smith
2b96737636 Fix use of the rb_profile_frames start parameter
Previously, it was decrementing the start argument until it reached
zero without actually changing the control frame pointer.

[Bug #14607]
2023-12-28 08:58:21 -08:00
Hiroya Fujinami
d8702ddbfb
Fix [Bug #20083]: correct a cache point size for atomic groups (#9367) 2023-12-28 23:20:03 +09:00