Commit graph

20692 commits

Author SHA1 Message Date
Hiroshi SHIBATA
535f0746ed
Fix indent rule by rubygems/bundler cops 2024-12-17 09:32:38 +09:00
Stan Lo
a6fd6cb72f [ruby/rdoc] Print warnings for rdoc-ref links that can't be resolved
(https://github.com/ruby/rdoc/pull/1241)

4a5206ae56
2024-12-16 19:35:00 +00:00
David Rodríguez
d0968b1b4c [rubygems/rubygems] Fix gem info tagging some non default gems as default
7585825c57
2024-12-16 18:09:54 +00:00
David Rodríguez
c4d35040f4 [rubygems/rubygems] Improve indentation of a gem info test
b0a092dac3
2024-12-16 18:09:54 +00:00
Peter Zhu
516a6cd1ad Check whether object is valid in allocation_info_tracer_compact
When reference updating ObjectSpace.trace_object_allocations, we need to
check whether the object is valid or not because it does not mark the
object so the object may be dead. This can cause a segmentation fault
if the object is on a free heap page.

For example, the following script crashes:

    require "objspace"

    objs = []
    ObjectSpace.trace_object_allocations do
      1_000_000.times do
        objs << Object.new
      end
    end

    objs = nil

    # Free pages that the objs were on
    GC.start

    # Run compaction and check that it doesn't crash
    GC.compact
2024-12-16 12:24:24 -05:00
ydah
f6e0a037aa [ruby/prism] [Bug #20785] Allow , and and , or after patterns
Partially: https://bugs.ruby-lang.org/issues/20785

71c9102d02
2024-12-16 10:51:22 -05:00
Haldun Bayhantopcu
0dc35f0d30 [ruby/prism] Ignore newlines in labelled lambda arguments
4ce6bcf182
2024-12-16 10:51:22 -05:00
eileencodes
a21237571e [ruby/prism] Fix 3112 - disallow commas after block arg
Prism was already disallowing arguments after block args, but in
parse.y, any comma after a block arg is a syntax error. This moves the
error handling into `PM_TOKEN_UAMPERSAND` where we can check if the
current type is `PM_TOKEN_COMMA`then raise an error. I've also updated
the tests to include the examplesfrom ruby/prism#3112.

Fixes: ruby/prism#3112

754cf8eddc
2024-12-16 10:51:22 -05:00
Kevin Newton
8eaa976cbe [ruby/prism] Fix up regression in ruby parser translation
b283a72c88
2024-12-16 10:51:22 -05:00
Peter Zhu
15765eac0a Fix ObjectSpace.trace_object_allocations for compaction
We need to reinsert into the ST table when an object moves because it is
a numtable that hashes on the object address, so when an object moves we
need to reinsert it rather than just updating the key.
2024-12-16 10:12:54 -05:00
Matt Valentine-House
39d0ebb6e8 [ruby/prism] Blocks & kwargs are not valid in index assignments
Ruby feature: https://bugs.ruby-lang.org/issues/20952

e612df5f36
2024-12-16 15:00:27 +00:00
Nobuyoshi Nakada
a46fe5c807 [ruby/rdoc] Fix to parse rb_define_global_const
https://github.com/ruby/ruby/pull/12357

458ecbb7f7
2024-12-16 14:55:39 +00:00
tomoya ishida
4428c51f01 [ruby/reline] Change quoted_insert and bracketed_paste to a single
key input
(https://github.com/ruby/reline/pull/792)

8f331edb07
2024-12-16 13:53:34 +00:00
Nobuyoshi Nakada
946c823ddb Freeze Random::Formatter::ALPHANUMERIC and its elements 2024-12-16 20:54:40 +09:00
tomoya ishida
784bd9c42e [ruby/rdoc] Add attribute :force to RDoc::RubygemsHook just like
RDoc::RubyGemsHook
(https://github.com/ruby/rdoc/pull/1244)

Rubygems creates an instance of RDoc::RubygemsHook, sets `doc.force = overwrite`, then calls `doc.generate` the document.
RDoc::RubygemsHook needs attribute `:force` just like RDoc::RubyGemsHook.

01bdbcdd4d
2024-12-16 11:32:43 +00:00
Nobuyoshi Nakada
bf0f323907 [ruby/tmpdir] Fix for path-like objects
Fix https://github.com/ruby/tmpdir/pull/37

a8ceafae7d
2024-12-16 09:40:01 +00:00
Hiroshi SHIBATA
3a4433dddd [ruby/securerandom] Restore SecureRandom.alphanumeric same as Random::Formatter.alphanumeric of Ruby 3.3/3.4
Fixes https://github.com/ruby/securerandom/pull/35

fbb36e36cc
2024-12-16 05:35:47 +00:00
Dani Smith
7c260bd424
[ruby/fiddle] ffi_backend: convert numeric function args to pointers
(https://github.com/ruby/fiddle/pull/162)

This allows for passing integers as pointer arguments to functions when
using the FFI backend. This is a workaround until we can get JRuby's FFI
implementation to allow for it directly (see also
https://github.com/jruby/jruby/pull/8423)

---------

e2f0952e9b

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2024-12-16 10:22:30 +09:00
tomoya ishida
2c57b87cc3 [ruby/reline] Refactor Reline::Unicode ed_ vi_ em_ methods
(https://github.com/ruby/reline/pull/720)

* Refactor Reline::Unicode vi_ ed_ em_ methods

* Make Reline::Unicode's vi_ ed_ em_ method encoding safe

cdd7288978
2024-12-15 11:50:43 +00:00
tompng
e06b3b5ad1 [Bug #20927] Fix compile_shareable_literal_constant for hash with keyword splat
Compilation of NODE_HASH in compile_shareable_literal_constant does not support hash that contains keyword splat.
If there is a keyword splat, fallback to default case.
2024-12-15 16:55:30 +09:00
Misaki Shioi
9f924e2f13
Improve APIs for Globally Enabling/Disabling fast_fallback in Socket (#12257)
This change includes the following updates:
- Added an environment variable `RUBY_TCP_NO_FAST_FALLBACK` to control enabling/disabling fast_fallback
- Updated documentation and man pages
- Revised the implementation of Socket.tcp_fast_fallback= and Socket.tcp_fast_fallback, which previously performed dynamic name resolution of constants and variables. As a result, the following performance improvements were achieved:

(Case of 1000 executions of `TCPSocket.new` to the local host)

Rehearsal -----------------------------------------
before   0.031462   0.147946   0.179408 (  0.249279)
after    0.031164   0.146839   0.178003 (  0.346935)
-------------------------------- total: 0.178003sec

            user     system      total        real
before   0.027584   0.138712   0.166296 (  0.233356)
after    0.025953   0.127608   0.153561 (  0.237971)
2024-12-14 15:51:19 +09:00
Matt Valentine-House
b37777c36f [PRISM] Blocks are also a syntax error in array assignment
Actually close [Bug #20952]
2024-12-13 22:02:06 +00:00
Matt Valentine-House
e194665720 [PRISM] using []= to set kwargs is a syntax error
Fixes [Bug #20952]
2024-12-13 21:22:35 +00:00
Peter Zhu
92dd9734a9 Fix use-after-free in ep in Proc#dup for ifunc procs
[Bug #20950]

ifunc proc has the ep allocated in the cfunc_proc_t which is the data of
the TypedData object. If an ifunc proc is duplicated, the ep points to
the ep of the source object. If the source object is freed, then the ep
of the duplicated object now points to a freed memory region. If we try
to use the ep we could crash.

For example, the following script crashes:

    p = { a: 1 }.to_proc
    100.times do
      p = p.dup
      GC.start
      p.call
    rescue ArgumentError
    end

This commit changes ifunc proc to also duplicate the ep when it is duplicated.
2024-12-13 10:10:03 -05:00
Hiroshi SHIBATA
e91b25ec8d Fixed compatibility error with setup command and rdoc plugin on rubygems 2024-12-13 15:39:41 +09:00
mterada1228
7e3c29250e Make it loose coupling between RubyGems and RDoc (#1171)
* Make it loose coupling between RubyGems and RDoc

\### Problems

There are following problems because of tight coupling between RubyGems and RDoc.

1. If there are braking changes in RDoc, RubyGems is also broken.
2. When we maintain RDoc, we have to change RubyGems.

The reason why they are happened is that RubyGems creates documents about a gem with installing it.

Note that RubyGems uses functions of RDoc to create documents.
Specifically,

- Creating documents is executed by `rubygems/lib/rubygems/rdoc.rb`.
- `::RDoc::RubygemsHook` which is defined by RDoc is called by the file.

\### Solution

RubyGems has the plugin system.

If a gem includes `rubygems_plugin.rb`, RubyGems loads it.
RubyGems executes a process defined in it while installing gems, uninstalling gems or other events.

We can use the system to solve the problems.

The root cause is RubyGems directly references the class of RDoc.

We can remove the root cause by making RDoc RubyGems plugin.

Alternatively `rubygems_plugin.rb` creates documents about gems.

\### FAQ

Q1. Do we need to change codes of RubyGems?

A.

No, we don't.

This change keeps compatibility of API used from RubyGems.

Q2. Is it better to delete existing codes related to RDoc in RubyGems?

No, it isn't.

If we change codes of RubyGems,
we can't keep a compatibility.

Example:

If we delete codes that uses `RDoc::RubygemsHook` in `rubygems/lib/rubygems/rdoc.rb`,
documentations are not created with old RDoc.

Q3. When can we delete `rubygems/lib/rubygems/rdoc.rb`?

A.

We can delete it when all users use RDoc including `rubygems_plugin`.

Next ruby version is 3.4.
If it includes the RDoc including `rubygems_plugin`,
we can delete `rubygems/lib/rubygems/rdoc.rb` after ruby 3.3 is EOL.

Q4. Is it a breaking change that Rubygems creates documents with
rubygems_plugin not RDoc::RubygemsHook?

A.

No, it isn't.

If we simply implement this approach,
we move the implementation from `rdoc/lib/rdoc/rubygems_hook.rb` to
`rubygems_plugin.rb`.

This way can be breaking change.

It seems to be fine that we just need to delete `rdoc/rubygems_hook.rb` but it doesn't work.
It generates multiple documents.

`rubygems/lib/rubygems/rdoc.rb` has the following code.

```
begin
  require "rdoc/rubygems_hook"
  # ...
rescue LoadError
end
```

This code ignores RDoc related processes when `rdoc/rubygems_hook` can't be required.
But, this 'require' is not failed.

This is because Ruby installs Rdoc as a default gem.

So, Rdoc installed as a default gem generates documents and one installed as a normal gem does it too.

If you think that this behavior is accectable,
we can just delete `rdoc/rubygems_hook.rb`.

What do you think about this approach?

In this change, we take another approach to solve the problem that creates multiple documents.

If `Gem.done_installing(&Gem::RDoc.method(:generation_hook))` in `rubygems/rdoc.rb` doesn't create documents,
we can solve the problem.

We have some options.

* We change `rubygems/rdoc.rb` and then don't execute `Gem.done_installing`.
  (This is a change for RubyGems.)
* We change `rdoc/rubygems_hook.rb` and then make `generation_hook` a no-op method.
  (This is a change for RDoc.)

We choose the latter to avoid changing for RubyGems.

\### Test

\#### Preparation

Install Rdoc which including our changes by executing `rake install`.

❯ rake install

We confirmed that Rdoc which including our changes was installed.

❯ gem list | grep rdoc
rdoc (6.6.0, default: 6.4.0)

\#### Check point

We tested to check compatibility.

How to chack the compatibility?

We tested creating same documents by our RDoc and old RDoc with latest RubyGems.

We used following versions to test.

```
❯ ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin22]

❯ gem list | grep rdoc
rdoc (default: 6.4.0)

❯ ruby -I rubygems/lib rubygems/exe/gem --version
3.5.14
```

Here is a result of test with old RDoc.
We can see that the document is created correctlly with `Parsing...` and `Done installing...`.

```
❯ ruby -I rubygems/lib rubygems/exe/gem install pkg-config
Successfully installed pkg-config-1.5.6
Parsing documentation for pkg-config-1.5.6
Done installing documentation for pkg-config after 0 seconds
1 gem installed
```

Here is a result of test with our RDoc.
We can see that the document is created correctlly with `Parsing...` and `Done installing...`.

```
❯ ruby -I rubygems/lib rubygems/exe/gem install pkg-config
Successfully installed pkg-config-1.5.6
Parsing documentation for pkg-config-1.5.6
Done installing documentation for pkg-config after 0 seconds
1 gem installed
```

As you can see we got the same results, our RDoc keeps compatibility.

* rename a test file

* Revert "rename a test file"

This reverts commit 70a144bf3fb8f2cc653972e858b5fed3747765d7.

* revert a test class name

* exclude `TestRDocRubyGemsHook` at job of ruby-core

* When `rubygems_plugin.rb` is not found, `test_rdoc_rubygems_hook.rb` is skipped.

* remove unnecessary whitespace

* add comment

* Add support for the case that RDoc is installed as a default gem

* Fix problems

Co-authored-by: mterada1228 <49284339+mterada1228@users.noreply.github.com>

* Simplify

* removed unused blank lines and revert test

* for rerun tests

* add comment for rubygems_plugin.rb

---------

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
2024-12-13 05:35:00 +00:00
James Reid-Smith
c0caf1cc1a [ruby/irb] Load history when starting a direct debug session
(https://github.com/ruby/irb/pull/1046)

* Load history when starting a direct debug session

When starting a debug session directly with RUBY_DEBUG_IRB_CONSOLE=1 and
`require 'debug'; debugger`, IRB's history wasn't loaded. This commit ensures
history is loaded in this case by calling `load_history` when configuring IRB
for the debugger.

Fixes ruby/irb#975

* Update test/irb/test_history.rb

* Update lib/irb/debug.rb

---------

7f851b5353

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-12-12 17:26:06 +00:00
tomoya ishida
300be2b192 [ruby/reline] Undo and redo should restore indentation
(https://github.com/ruby/reline/pull/793)

* Undo and redo should restore indentation

Undo and redo should not perform auto indentation. It should not change the indentation. Instead, it should restore previous indentation.

* Rename ivar undoing(undoing or redoing) to restoring

6355a6e0b2
2024-12-12 16:40:08 +00:00
Nobuyoshi Nakada
776ec52148 [ruby/win32ole] Deprecate old constants in toplevel
eaa1507262
2024-12-12 14:39:20 +00:00
Nobuyoshi Nakada
4d86f3bf6d [Feature #20884] Reserve "Ruby" toplevel name 2024-12-12 17:45:06 +09:00
Aaron Patterson
9181e8bc87 [ruby/prism] Decode %r like % strings
%r regular expressions need to be decoded like strings.  This commit
fixes %r decoding so it works like strings.

85bfd9c0cd
2024-12-12 00:42:44 +00:00
Aaron Patterson
0a1fa99482 [ruby/prism] Same numbered param cannot be used in child blocks
Raise an exception when the same numbered param is used inside a child
block.  For example, the following code should be a syntax error:

```ruby
-> { _1 + -> { _1 } }
```

Fixes https://github.com/ruby/prism/pull/3291

d4fc441838
2024-12-12 00:42:27 +00:00
eileencodes
9fe6fd8693 [ruby/prism] Fix percent delimiter strings with crlfs
parse.y treats CRLF as a LF and basically "normalizes" them before
parsing.  That means a string like `%\nfoo\r\n` is actually treated as
`%\nfoo\n` for the purposes of parsing.  This happens on both the
opening side of the percent string as well as on the closing side.  So
for example `%\r\nfoo\n` must be treated as `%\nfoo\n`.

To handle this in Prism, when we start a % string, we check if it starts
with `\r\n`, and then consider the terminator to actually be `\n`.  Then
we check if there are `\r\n` as we lex the string and treat those as
`\n`, but only in the case the start was a `\n`.

Fixes: #3230

[Bug #20938]

e573ceaad6

Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: eileencodes <eileencodes@gmail.com>
Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-12-11 23:06:32 +00:00
Josef Haider
13530af05a [rubygems/rubygems] Avoid UTF-32 and UTF-16 strings with trailing bytes in truffleruby
5f8249471f
2024-12-11 17:06:13 +00:00
Sutou Kouhei
4a49089278 [ruby/fiddle] dlopen: add support for INPUT(-lXXX)
GitHub: fix https://github.com/ruby/fiddle/pull/166

Arch Linux's libncurses.so uses this style.

77d3dc934f
2024-12-11 14:48:16 +09:00
Lars Kanis
473fb6385e [ruby/fiddle] Implement Fiddle::Pointer.read and .write on the
FFI backend
(https://github.com/ruby/fiddle/pull/165)

0bd963d3b8
2024-12-11 14:48:16 +09:00
Nobuyoshi Nakada
0c7fe4b092 [ruby/fiddle] Fix the glob pattern to include /usr/lib
(https://github.com/ruby/fiddle/pull/164)

Fix up #161.

481651e836
2024-12-11 14:48:15 +09:00
Nobuyoshi Nakada
e90b447655
[Bug #20924] Fix reading with delimiter in wide character encodings 2024-12-10 23:57:57 +09:00
Kouhei Yanagita
3422bfcab6 [Bug #20936] Fix #size for Range#reverse_each 2024-12-10 23:12:27 +09:00
tomoya ishida
3568e7aef7 [ruby/reline] Fix line wrapped cursor position
(https://github.com/ruby/reline/pull/791)

Cursor position calculation was wrong when the input line contains "\1" or CSI escape sequence.

a1943daaf4
2024-12-10 10:28:22 +00:00
Dani Smith
b5ed7aae3b
[ruby/fiddle] Fix test_dlopen_linker_script_input_linux being
omitted on Fedora 40 aarch64
(https://github.com/ruby/fiddle/pull/161)

I found working on Fedora 40 on aarch64 that
`test_dlopen_linker_script_input_linux` was omitted due to not finding
libncurses.so, since it is in /usr/lib64. This PR makes the glob a
little more portable.

444774c0c4
2024-12-10 11:30:19 +09:00
Stan Lo
93f8de777f [ruby/rdoc] Expand rdoc-ref targets at the end of ri output
(https://github.com/ruby/rdoc/pull/1141)

There have been several document refactors in ruby/ruby that extract
individual methods/classes' documentation into separate files, like
ruby/ruby#6567

Because RI is not capable of rendering those references, RI users
are left with dramatically fewer documentation on those methods/classes.

This commit adds a new option `--expand-ref` (default: true) to expand
all the rdoc-ref targets at the end of the output.

9e2b28c6e3
2024-12-09 17:21:01 +00:00
nicholas a. evans
dd43af3be7 [ruby/rdoc] Use distinct styles for note lists and label lists
(https://github.com/ruby/rdoc/pull/1209)

* Use the original `label` description list style

As a default for all description lists, the original "label" style is
more readable.

This is slightly different from the original `label` dl though:
* slightly increased left margin for `dd` (to 1em)
* removed right margin on `dd`
* removed `dt` bottom margin and `dd` top margin, to reduce the gap
  between the term and its description (to only the standard line-height
  gap).

* Add closing tags for description list terms

Without the closing tags, the dt elements contain whitespace after the
text.  This normally isn't a big deal, but does mess some things up,
e.g: using `::after` with `content: ", "` in stylesheets.

* Restore float:left style for note lists

Unlike the original note list styles, this version sets the line-height
for all `dt` elements to be the same as the `p` elements contained
inside the `dd`, so that the second line has the same indentation as all
subsequent lines.

* Add commas between note list terms

9e69ea6d75
2024-12-08 10:43:47 +00:00
Kazuki Yamaguchi
c9bbf7e3eb [ruby/openssl] ssl: do not clear existing SSL options in SSLContext#set_params
Apply SSL options set in DEFAULT_PARAMS without clearing existing
options.

It currently clears options in order to avoid setting one of the
options included in OpenSSL::SSL::OP_ALL unless explicitly specified,
namely OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS. Now that
OpenSSL::SSL::OP_ALL has been removed from SSLContext#initialize, it is
no longer necessary.

77c3db2d65
2024-12-07 08:15:08 +00:00
Kazuki Yamaguchi
510c190739 [ruby/openssl] ssl: do not enable OpenSSL::SSL::OP_ALL by default
Respect the SSL options set by default by SSL_CTX() and by the
system-wide OpenSSL configuration file.

OpenSSL::SSL::SSLContext#initialize currently adds OpenSSL::SSL::OP_ALL
on top of the default SSL options. Let's stop doing it.

OpenSSL::SSL::OP_ALL is a set of options that changes OpenSSL's behavior
to workaround various TLS implementation bugs. Using it is considered
usually safe, but is not completely harmless.

00bec0d905
2024-12-07 08:15:08 +00:00
HoneyryderChuck
5444885726 [ruby/openssl] make configs shareable when frozen
654cb22e21
2024-12-07 07:52:02 +00:00
HoneyryderChuck
2a006fe54b [ruby/openssl] make config frozen on initialize
50599513cf
2024-12-07 07:52:01 +00:00
Kazuki Yamaguchi
06fc13a15c [ruby/openssl] ssl: handle callback exceptions in SSLSocket#sysread and #syswrite
Check the ID_callback_state ivar after SSL_read() or SSL_write()
returns, similar to what ossl_start_ssl() does.

Previously, callbacks that can raise a Ruby exception were only called
from ossl_start_ssl(). This has changed in OpenSSL 1.1.1. Particularly,
the session_new_cb will be called whenever a client receives a
NewSessionTicket message, which can happen at any time during a TLS 1.3
connection.

aac9ce1304
2024-12-07 07:37:32 +00:00
David Rodríguez
48443c0204 [rubygems/rubygems] Skip unresolved deps warning on Gem::Specification.reset on benign cases
If `Gem::Specification.reset` is used, but there are still unresolved
dependencies, RubyGems prints a warning. There are though, certain cases
where the situation will not cause any issues.

One such case is when the unresolved dependency does not restrict any
versions (>= 0) and there's a default gem matching it.

In this situation, it doesn't matter if Gem paths change, because
default gems are still activatable, so the dependency will be properly
activated if ever needed.

e5f8a3068e
2024-12-06 15:19:19 +00:00
David Rodríguez
ba91ff5f78 [rubygems/rubygems] Make sure unresolved deps are properly cleared by Gem::Specification.reset
3976326a7b
2024-12-06 15:19:19 +00:00