Commit graph

20692 commits

Author SHA1 Message Date
ydah
0643f08187 Implement IF NODE locations
The following Location information has been added This is the information required for parse.y to be a universal parser:

```
❯ ruby --parser=prism --dump=parsetree -y -e "if a; elsif b; else end"
@ ProgramNode (location: (1,0)-(1,23))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,23))
    +-- body: (length: 1)
        +-- @ IfNode (location: (1,0)-(1,23))
            +-- if_keyword_loc: (1,0)-(1,2) = "if"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- predicate:
            |   @ CallNode (location: (1,3)-(1,4))
            |   +-- CallNodeFlags: variable_call, ignore_visibility
            |   +-- receiver: nil
            |   +-- call_operator_loc: nil
            |   +-- name: :a
            |   +-- message_loc: (1,3)-(1,4) = "a"
            |   +-- opening_loc: nil
            |   +-- arguments: nil
            |   +-- closing_loc: nil
            |   +-- block: nil
            +-- then_keyword_loc: nil
            ^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- statements: nil
            +-- subsequent:
            |   @ IfNode (location: (1,6)-(1,23))
            |   +-- if_keyword_loc: (1,6)-(1,11) = "elsif"
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            |   +-- predicate:
            |   |   @ CallNode (location: (1,12)-(1,13))
            |   |   +-- CallNodeFlags: variable_call, ignore_visibility
            |   |   +-- receiver: nil
            |   |   +-- call_operator_loc: nil
            |   |   +-- name: :b
            |   |   +-- message_loc: (1,12)-(1,13) = "b"
            |   |   +-- opening_loc: nil
            |   |   +-- arguments: nil
            |   |   +-- closing_loc: nil
            |   |   +-- block: nil
            |   +-- then_keyword_loc: nil
                ^^^^^^^^^^^^^^^^^^^^^^^^^
            |   +-- statements: nil
            |   +-- subsequent:
            |   |   @ ElseNode (location: (1,15)-(1,23))
            |   |   +-- else_keyword_loc: (1,15)-(1,19) = "else"
            |   |   +-- statements: nil
            |   |   +-- end_keyword_loc: (1,20)-(1,23) = "end"
            |   +-- end_keyword_loc: (1,20)-(1,23) = "end"
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- end_keyword_loc: (1,20)-(1,23) = "end"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2025-01-03 20:34:19 +09:00
tomoya ishida
23018c2fb4 [ruby/rdoc] Fix prism_ruby superclass resolve order
(https://github.com/ruby/rdoc/pull/1267)

RDoc::Parser::PrismRuby wrongly resolves superclass of `class Cipher < Cipher; end` that exist in openssl.
Superclass resolve should be done before adding class.

57a4615a92
2025-01-03 11:13:57 +00:00
Nobuyoshi Nakada
6bbb470dc7
[Bug #20504] Move dynamic regexp concatenation to iseq compiler 2025-01-03 10:25:15 +09:00
Nobuyoshi Nakada
77fe82286b
Try all assertions in TestM17N#test_regexp_usascii 2025-01-03 10:10:54 +09:00
dependabot[bot]
0be06552a8 [rubygems/rubygems] Bump the rb-sys group across 2 directories with 1 update
Bumps the rb-sys group with 1 update in the /test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib directory: [rb-sys](https://github.com/oxidize-rb/rb-sys).
Bumps the rb-sys group with 1 update in the /test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example directory: [rb-sys](https://github.com/oxidize-rb/rb-sys).

Updates `rb-sys` from 0.9.104 to 0.9.105
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.104...v0.9.105)

Updates `rb-sys` from 0.9.104 to 0.9.105
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.104...v0.9.105)

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

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

3bbf6b1306
2025-01-02 19:21:27 +00:00
Nobuyoshi Nakada
8034e9c3d0
[Bug #20995] Protect IO.popen block from exiting by exception 2025-01-02 15:50:20 +09:00
tomoya ishida
3e8f0e5589 [ruby/reline] Support inserting C-c C-z C-\ with quoted_insert
(https://github.com/ruby/reline/pull/798)

e6eb5d2d3c
2025-01-01 14:41:58 +00:00
Stan Lo
c0e2623966 [ruby/rdoc] Add autolink_excluded_words option to ignore
cross-references
(https://github.com/ruby/rdoc/pull/1259)

This config will be handy when the project name is the same as a class or
module name, which is often the case for most of the projects.

ce77f51f63
2024-12-31 12:17:07 +00:00
Charles Oliver Nutter
89c9a9fd03 [ruby/net-http] Don't double-interrupt the test HTTP server
The shutdown process here attempted to terminate the test server
by interrupting it with Thread#kill, and then proceeded to close
the server and join the thread. The kill does indeed interrupt
the accept call, but the close call could also interrupt the
thread as part of notifying blocked threads waiting on that
socket call.

In JRuby, where all of this can happen at the same time, it leads
to the following scenario:

* The server thread enters TCPServer#accept and blocks.
* The main thread calls Thread#kill to interrupt the accept call.
* The server thread wakes up and starts to propagate the kill.
  There is a slight delay between this wakeup and removing the
  server thread from the TCPServer's blocked threads list.
* The main thread calls TCPServer#close, which sees that the server
  thread is still in the blocked list, so it initiates a second
  interrupt to raise IOError "closed in another thread" on the
  server thread.
* As the kill is bubbling out, another check for interrupts occurs,
  causing it to see the new raise interrupt and propagate that
  instead of the active kill.
* Because the server is now closed and the rescue here is empty,
  the server loop will endlessly attempt and fail to call accept.

I was unable to determine how CRuby avoids this race. There may be
code that prevents an active kill interrupt from triggering
further interrupts.

In order to get these tests running on JRuby, I've made the
following changes:

* Only kill the thread; one interrupt is sufficient to break it
  out of the accept call.
* Ensure outside the server loop that the server gets closed. This
  happens within the server thread, so triggers no new interrupts.
* Minor cleanup for the pattern of using @ssl_server or @server.

This change avoids the race in JRuby (and possibly other parallel-
threaded implementations) and does not impact the behavior of the
tests.

54025b3870
2024-12-31 10:00:41 +00:00
Nobuyoshi Nakada
5fec930832
[Bug #20992] Test for local variable name encodings 2024-12-30 17:04:09 +09:00
sanfrecce-osaka
3650f2460f [ruby/irb] Fix broken history command with -g
(https://github.com/ruby/irb/pull/1057)

Local variable `grep` was always nil because the regular expression parsing options contained an unnecessary `\n`. `test_history_grep` did not detect this because it only asserted what was included in the output.

a282bbc0cf
2024-12-29 11:00:11 +00:00
Nobuyoshi Nakada
a33c944ba8
[Bug #20988] [prism] Fix escaped octal character literals 2024-12-29 10:32:33 +09:00
Stan Lo
609a555ee0 [ruby/irb] Add ri an alias to the show_doc command
(https://github.com/ruby/irb/pull/1054)

52e77dd113
2024-12-28 15:55:27 +00:00
Nobuyoshi Nakada
e4ec2128ae
[Bug #20990] Reject escaped multibyte char with control/meta prefix 2024-12-28 18:40:37 +09:00
Nobuyoshi Nakada
0ccc7657f3
Ripper: Fix duplicate regexp errors 2024-12-28 11:35:00 +09:00
Nobuyoshi Nakada
fb18bb183c
[Bug #20989] Ripper: Pass compile_error
For the universal parser, `rb_parser_reg_fragment_check` function is
shared between the parser and ripper.  However `parser_params` struct
is partially different, and `compile_error` function depends on that
part indirectly.
2024-12-28 11:25:57 +09:00
Kevin Newton
4cf4cad4ab [ruby/prism] Turn off unescape tests for Ruby >= 3.4.0
f982769314
2024-12-27 01:26:54 +00:00
Kevin Newton
4d8c9c1310 [ruby/prism] Handle escaped characters after controls
Fixes [Bug #20986]

fd0c563e9e
2024-12-26 22:35:28 +00:00
Kevin Newton
c859e15875 Handle defined? with call chains with blocks
Ensures we can handle expressions like `defined?(a {}.b)`.
2024-12-26 17:34:58 -05:00
Nobuyoshi Nakada
d78ff6a767 [Bug #20984] Fix test with locale encoding 2024-12-27 00:21:41 +09:00
Nobuyoshi Nakada
c6dbb10b74
[Bug #20982] Put spaces in ENV.inspect results as well as Hash 2024-12-26 15:01:48 +09:00
Nobuyoshi Nakada
19c39e4cfa
[Bug #20984] ENV.inspect should be encoding aware 2024-12-26 13:42:56 +09:00
Nobuyoshi Nakada
037bffec07
Refine ENV tests 2024-12-26 13:02:29 +09:00
Nobuyoshi Nakada
16665c3623
"test" environment variable is unset in setup 2024-12-26 12:31:56 +09:00
dependabot[bot]
6e73dcff05 [rubygems/rubygems] Bump the rb-sys group across 2 directories with 1 update
Bumps the rb-sys group with 1 update in the /test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib directory: [rb-sys](https://github.com/oxidize-rb/rb-sys).
Bumps the rb-sys group with 1 update in the /test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example directory: [rb-sys](https://github.com/oxidize-rb/rb-sys).

Updates `rb-sys` from 0.9.103 to 0.9.104
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.103...v0.9.104)

Updates `rb-sys` from 0.9.103 to 0.9.104
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.103...v0.9.104)

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

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

5f20e800c6
2024-12-26 10:27:24 +09:00
Sorah Fukumori
ece332a44d [ruby/reline] test_tty_ambiguous_width: Use Reline.test_rubybin
Same as https://github.com/ruby/reline/pull/510, 'ruby' command is not
always available so don't rely on that specific name.

f60199fed7
2024-12-25 19:46:34 +00:00
Nobuyoshi Nakada
67d8a97d07 [ruby/rdoc] Separate patterns by --exclude option from defaults
(https://github.com/ruby/rdoc/pull/1251)

a7fdc730f3
2024-12-25 16:53:24 +00:00
Hiroshi SHIBATA
9967eccc54 Removed Process::Status#& and Process::Status#>> 2024-12-25 20:10:18 +09:00
Nobuyoshi Nakada
e5e4db1748 [Feature #20884] Define toplevel "Ruby" module with constants 2024-12-25 19:12:31 +09:00
Nobuyoshi Nakada
fb82f3a632 Win32: Defer change of timezone name encoding after 3.4
This change will be merged into 3.5 along with other encoding, command
line, environment variables, etc.

Revert following commits:

- bd831bcca5
  [Bug #20929] Win32: Use `wcsftime`

- 1c15f641cc
  [Bug #20929] Win32: Encode timezone name in UTF-8

- 78762b5218
  [Bug #20929] Fix `assert_zone_encoding`
2024-12-24 13:25:55 +09:00
lukeg
0d81177c20 Fix calls to require_internal in multi-ractor mode
After a ractor is started (multi-ractor mode), any calls to
require_internal will hang the process due to deadlock. For example,
loading a new encoding will deadlock after a ractor starts.

Fixes [Bug #19562]
2024-12-24 11:40:00 +09:00
David Rodríguez
9e0eb9778d Merge RubyGems-3.6.2 and Bundler-2.6.2 2024-12-24 07:21:10 +09:00
Nobuyoshi Nakada
adad97a031
[Bug #20978] Stringize Fiber storage keys 2024-12-23 18:16:28 +09:00
yui-knk
18580bc4e0 Add a test case for nested block it 2024-12-23 14:53:51 +09:00
Takashi Kokubun
667a0f9f92
Revert "[Bug #20965] Define it like an ordinary argument" (#12418)
Revert "[Bug #20965] Define `it` like an ordinary argument (#12398)"

Reverts ruby/ruby#12398 as per https://bugs.ruby-lang.org/issues/20970#note-6 and https://bugs.ruby-lang.org/issues/20965#note-7.
We need more time to design the intended behavior, and it's too late for Ruby 3.4.
2024-12-23 04:46:50 +00:00
Hiroshi SHIBATA
60c814607d
Omit TestEval#test_outer_local_variable_under_gc_compact_stress with s390x 2024-12-23 09:39:08 +09:00
Kazuki Yamaguchi
2a3f2412b7 [ruby/openssl] ssl: fix flaky test case test_ctx_client_session_cb_tls13_exception
In the test case, the client raises an exception in the session_new_cb
and may not cleanly close the connection. Let's ignore exceptions raised
at the server side.

Fixes: https://github.com/ruby/openssl/issues/828

210ba0334a
2024-12-22 03:33:03 +09:00
Kazuki Yamaguchi
637f019f1f [ruby/openssl] cipher: make output buffer String independent
OpenSSL::Cipher#update accepts a String as the second argument to be
used as the output buffer. The buffer must be directly writable, in
other words, it must not be frozen and not a shared string.

rb_str_resize() does not make the String independent if the String
already has the intended length. Use the rb_str_modify() family instead
to check it.

Fixes: https://bugs.ruby-lang.org/issues/20937

1de3b80a46
2024-12-22 03:33:03 +09:00
Kazuki Yamaguchi
c79b435407 [ruby/openssl] pkcs12: add PKCS12#set_mac
Add a binding for PKCS12_set_mac() to set MAC parameters and
(re-)calculate MAC for the content.

This allows generating PKCS #12 with consistent MAC parameters with
different OpenSSL versions. OpenSSL 3.0 changed the default hash
function used for HMAC and the KDF from SHA-1 to SHA-256.

Fixes: https://github.com/ruby/openssl/issues/772

f5ed2a74b6
2024-12-22 03:33:03 +09:00
Kevin Newton
391b6746cd Provide Ractor support for **
Fixes [Bug #20916]
2024-12-20 16:45:28 -05:00
Peter Zhu
e23a60b929 Fix GC compaction crash when using local variables in eval
If we have local variables outside of the eval, the local variables names
are IDs. We convert these IDs to char * using rb_id2name. However, these
char * are actually Ruby strings, which may be embedded. This means that
it is not safe to rb_id2name and call any potential GC entrypoints because
if a GC compaction runs, the embedded string may move and the pointer will
change.

For example, if you compile with `-DRGENGC_CHECK_MODE=1`, then the following
script will crash:

    GC.auto_compact = :empty
    GC.stress = true

    o = Object.new

    eval("def o.m(k: 0) k end")

The crash message is:

    test.rb:6: [BUG] Local with constant_id 1 does not exist
    ruby 3.4.0dev (2024-12-17T18:34:57Z prism-local-compac.. 434346726c) +PRISM [arm64-darwin24]

    -- C level backtrace information -------------------------------------------
    miniruby(rb_print_backtrace+0x24) [0x10312fec4] vm_dump.c:823
    miniruby(rb_print_backtrace) (null):0
    miniruby(rb_vm_bugreport+0x2d4) [0x1031301b8] vm_dump.c:1155
    miniruby(rb_bug_without_die_internal+0xa8) [0x102dd6a94] error.c:1097
    miniruby(rb_bug+0x28) [0x102dd6b00] error.c:1115
    miniruby(pm_lookup_local_index+0xec) [0x102d61e4c] prism_compile.c:1237
    miniruby(pm_compile_node+0x45d0) [0x102d252f4] prism_compile.c:9334
    miniruby(pm_compile_node+0x1864) [0x102d22588] prism_compile.c:8650
    miniruby(pm_compile_node+0x65ec) [0x102d27310] prism_compile.c:9897
    miniruby(pm_compile_scope_node+0x3008) [0x102d77bcc] prism_compile.c:6584
    miniruby(pm_compile_node+0x5ec4) [0x102d26be8] prism_compile.c:9768
    miniruby(pm_iseq_compile_node+0xac) [0x102d20bf0] prism_compile.c:10069
    miniruby(pm_iseq_new_with_opt_try+0x2c) [0x102e7d088] iseq.c:1029
    miniruby(rb_protect+0x108) [0x102dea9bc] eval.c:1033
    miniruby(pm_iseq_new_with_opt+0x264) [0x102e7c444] iseq.c:1082
    miniruby(pm_iseq_new_eval+0xec) [0x102e7c8e0] iseq.c:961
    miniruby(pm_eval_make_iseq+0x594) [0x1031209cc] vm_eval.c:1770
    miniruby(eval_make_iseq+0x54) [0x103120068] vm_eval.c:1799
2024-12-20 08:24:54 -05:00
Matt Valentine-House
e8d393c8ae [PRISM] Treat it as a local when compiling patterns
Fixes [Bug #20973]
2024-12-20 08:19:57 -05:00
Kazuki Yamaguchi
0397bfa2c8 [PRISM] Fix compiling popped opt_str_uminus and opt_str_freeze
Put a pop as needed. This example currently causes [BUG]:

	$ ruby --parser=prism -e'1.times{"".freeze;nil}'
	-e:1: [BUG] Stack consistency error (sp: 15, bp: 14)
	ruby 3.4.0dev (2024-12-20T00:48:01Z master 978df259ca) +PRISM [x86_64-linux]
2024-12-20 08:19:09 -05:00
Misaki Shioi
b53a75230f
Fix tests for fast_fallback (#12406)
* TCPSocket.new: Close resources in ensure

* TCPSocket.new: Remove unnecessary comments

* Socket.tcp: Make assert_separately in TestSocket more readable

* Socket.tcp: Returning instead of exiting

* Socket.tcp: Close resources in ensure

* Socket.tcp: Avoid test failures on hosts that only support IPv4
2024-12-20 18:55:26 +09:00
Alan Wu
ce849d565b
ruby2_keywords warnings: Quote non-UTF8 method names fully
It used to quote only part of the method name because NUL byte in
the method terminates the C string:

```
(irb)> "abcdef".encode("UTF-16LE").bytes
=> [97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0]
```

```
expected: /abcdef/
actual: warning: Skipping set of ruby2_keywords flag for a (method not defined in Ruby)\n".
```
2024-12-19 10:32:14 -05:00
Nobuyoshi Nakada
7b2ae8df90
[Bug #20969] Pass assignable from ripper
For the universal parser, `rb_reg_named_capture_assign_iter_impl`
function is shared between the parser and ripper.  However
`parser_params` struct is partially different, and `assignable`
function depends on that part indirectly.
2024-12-19 23:20:09 +09:00
Nobuyoshi Nakada
46fec0f62a
[Bug #20965] Define it like an ordinary argument (#12398)
Also fixes [Bug #20955]
2024-12-18 23:12:16 -08:00
Nobuyoshi Nakada
fef8ecc708 [ruby/rdoc] Enable cross reference in code
(https://github.com/ruby/rdoc/pull/1240)

Some people like to mark up method names in MarkDown style block
quotes, like this: ruby/ruby#12333.
Currently, no links are created in the code in the RDoc, but such
words most likely refer to methods.
This PR makes a word a code cross-reference if the whole word can be
resolved as a reference.

7d7efb0709
2024-12-17 21:48:31 +00:00
Stan Lo
1254850a61 [ruby/rdoc] Update tests for ruby/rdoc#1247
(https://github.com/ruby/rdoc/pull/1248)

94b9858000
2024-12-17 21:23:56 +00:00
Matt Valentine-House
86cf18e01e [PRISM] Recurse use_deconstructed_cache in Alternation Nodes
This fixes the behavioural difference between Prism and parse.y when
evaluating the following code

```ruby
1 in [1 | [1]]
```

Fixes [Bug #20956]
2024-12-17 15:13:53 +00:00