Issue #18948 has been updated by okuramasafumi (Masafumi OKURA).
I'm convinced by Jeremy's argument. Please someone close this issue.
----------------------------------------
Feature #18948: Add `with_private_method` option to `private_constant`
https://bugs.ruby-lang.org/issues/18948#change-106123
* Author: okuramasafumi (Masafumi OKURA)
* Status: Open
* Priority: Normal
----------------------------------------
## Problem
I have the following code:
```ruby
module M1
CONST = 'CONST'.freeze
end
module M2
def self.included(base)
base.include M1
base.include InstanceMethods
end
module InstanceMethods
def const?(value)
M1::CONST == value
end
end
end
class C
include M2
end
C.new.const?('CONST') # => true
```
`M2` module "inherits" `M1` module using `included` hook. This code works, but I prefer making constants private. However, when I add `private_constant :CONST` to `M1` then the code doesn't work anymore since we cannot refer `M1::CONST`.
## Workaround
One way to solve this is to define method that just returns the private constant.
```ruby
# Refined version of M1 with `const` method
module M1
CONST = 'CONST'.freeze
private_constant :CONST
private
def const
CONST
end
end
# Refined version of M2, using `const` method inherited from M1
module M2
def self.included(base)
base.include M1
base.include InstanceMethods
end
module InstanceMethods
def const?(value)
const == value
end
end
end
```
This works anyway, but defining private method for every private constant could be cumbersome.
## Solution
So my suggestion here is to add `with_private_method` option to `private_constant` method. The auto-generated private method has the same name as the given constant and just returns it. So we can do the following:
```ruby
module M1
CONST = 'CONST'.freeze
private_constant :CONST, with_private_method: true
end
```
Now we can access `CONST` with `const` method. This makes is possible to refer private constants through private methods more easily, that helps some code like my example.
--
https://bugs.ruby-lang.org/
Hello Ruby-Shadow owners and Ruby Dev Team,
On Linux, using Ruby 3.2.2, getting shadow.so: undefined symbol:
rb_tainted_str_new2 with ruby-shadow-ruby32-2.5.1.gem.
The following code in this gem uses rb_tainted_str_new2:
pwd/shadow.c:59: rb_tainted_str_new2(entry->pw_name), /* sp_namp */
pwd/shadow.c:60: rb_tainted_str_new2(entry->pw_passwd), /* sp_pwdp,
encryped password */
pwd/shadow.c:69: rb_tainted_str_new2(entry->pw_class), /*
sp_loginclass, user access class */
shadow/shadow.c:37: rb_tainted_str_new2(entry->sp_namp),
shadow/shadow.c:38: rb_tainted_str_new2(entry->sp_pwdp),
It needs to be fixed similar to ruby-odbc's:
https://github.com/vhermecz/ruby-odbc/commit/c38d182863b907f9ce55d2dfeb9bd8…
Can we get the ruby-shadow-ruby32 patched to resolve this issue?
Thanks.
Issue #20167 has been reported by shia (Sangyong Sim).
----------------------------------------
Bug #20167: Code execution isn't recorded in Ractor
https://bugs.ruby-lang.org/issues/20167
* Author: shia (Sangyong Sim)
* Status: Open
* Priority: Normal
* ruby -v: 3.3.0
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
## reproduction code
```ruby
# frozen-string-literal: true
require "coverage"
Coverage.start
require_relative "./some_lib"
# # some_lib.rb
# class C
# def hoge(i)
# i
# end
# end
r = Ractor.new do
loop do
v = Ractor.receive
ret_v = C.new.hoge(v)
Ractor.yield ret_v
end
end
2.times do |i|
r << i
r.take
end
Coverage.result.each do |file, lines|
if file.include?("some_ractor_lib")
if lines == [1, 1, 2, nil, nil]
puts "OK"
else
puts "expected: [1, 1, 2, nil, nil]"
puts "actual: #{lines.inspect}"
end
end
end
```
## Target ruby version
3.2.0+ affected
--
https://bugs.ruby-lang.org/
Issue #16137 has been updated by okuramasafumi (Masafumi OKURA).
Now that we have had pattern match for a while, I agree with Eregon, we can utilize it more rather than adding new methods.
I cannot change its status so I hope someone will do so instead of me.
----------------------------------------
Feature #16137: Add === to UnboundMethod
https://bugs.ruby-lang.org/issues/16137#change-106100
* Author: okuramasafumi (Masafumi OKURA)
* Status: Open
* Priority: Normal
----------------------------------------
# Abstract
`UnboundMethod` class should have `=== ` so that it can be used in case statement.
# Background
`Method` class has `===` method so that we can do something like:
``` ruby
require 'prime'
case 11
when Prime.method(:prime?) then :prime
end
```
However, we cannot do something like this:
```ruby
positive = Integer.instance_method(:positive?)
case 11
when positive then :positive
end
```
# Proposal
Add `===` method to `UnboundMethod` class.
# Implementation
Minimal implementation in Ruby could be:
```ruby
class UnboundMethod
def ===(other)
bind(other).call
end
end
```
# Summary
`===` for `UnboundMethod` can improve readability in case statement.
--
https://bugs.ruby-lang.org/
Issue #19908 has been reported by nobu (Nobuyoshi Nakada).
----------------------------------------
Feature #19908: Update to Unicode 15.1
https://bugs.ruby-lang.org/issues/19908
* Author: nobu (Nobuyoshi Nakada)
* Status: Assigned
* Priority: Normal
* Assignee: duerst (Martin Dürst)
* Target version: 3.3
----------------------------------------
The Unicode 15.1 is released.
The current enc-unicode.rb seems to fail because of `Indic_Conjunct_break` properties with values.
I'm not sure how these properties should be handled well.
`/\p{InCB_Liner}/` or `/\p{InCB=Liner}/` as the comments in that file?
https://github.com/nobu/ruby/tree/unicode-15.1 is the former.
--
https://bugs.ruby-lang.org/
Issue #20156 has been reported by kddnewton (Kevin Newton).
----------------------------------------
Misc #20156: C99 updates
https://bugs.ruby-lang.org/issues/20156
* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
Now that we require Visual Studio 2015 and Oracle Developer Studio 12.5, we can do a couple of things to clean up:
* We should be able to remove our custom `stdbool.h` (added in VS2015 and Oracle SS 12.3)
* Remove our usage of `__restrict` for Windows (added in VS2015)
* Remove our custom `va_copy` (added in VS2015)
Just notating, a couple of things that we _can_ use now:
* snprintf
* size_t printf format specifier (%z)
I'm happy to do this work, but I wanted to open this ticket in case there is something besides Visual Studio or Oracle Solaris Studio that I would have missed for one of our compilation targets. Are there any other targets that do not fully implement C99?
--
https://bugs.ruby-lang.org/
Issue #18285 has been updated by headius (Charles Nutter).
Also fixes my issue from 2014: https://bugs.ruby-lang.org/issues/9725
I'm glad we finally have dealt with this one.
----------------------------------------
Feature #18285: NoMethodError#message uses a lot of CPU/is really expensive to call
https://bugs.ruby-lang.org/issues/18285#change-106058
* Author: ivoanjo (Ivo Anjo)
* Status: Closed
* Priority: Normal
----------------------------------------
Hello there! I'm working at Datadog on the ddtrace gem -- https://github.com/DataDog/dd-trace-rb and we ran into this issue on one of our internal testing applications. I also blogged about this issue in <https://ivoanjo.me/blog/2021/11/01/nomethoderror-ruby-cost/>.
### Background
While testing an application that threw a lot of `NoMethodError`s in a Rails controller (this was used for validation), we discovered that service performance was very much impacted when we were logging these exceptions. While investigating with a profiler, the performance impact was caused by calls to `NoMethodError#message`, because this Rails controller had a quite complex `#inspect` method, that was getting called every time we tried to get the `#message` from the exception.
### How to reproduce
```ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
end
puts RUBY_DESCRIPTION
class GemInformation
# ...
def get_no_method_error
method_does_not_exist
rescue => e
e
end
def get_runtime_error
raise 'Another Error'
rescue => e
e
end
def inspect # <-- expensive method gets called when calling NoMethodError#message
Gem::Specification._all.inspect
end
end
NO_METHOD_ERROR_INSTANCE = GemInformation.new.get_no_method_error
RUNTIME_ERROR_INSTANCE = GemInformation.new.get_runtime_error
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
x.report("no method error message cost") { NO_METHOD_ERROR_INSTANCE.message }
x.report("runtime error message cost") { RUNTIME_ERROR_INSTANCE.message }
x.compare!
end
```
### Expectation and result
Getting the `#message` from a `NoMethodError` should be no costly than getting it from any other exception.
In reality:
```
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
no method error message cost
115.390 (± 1.7%) i/s - 580.000 in 5.027822s
runtime error message cost
6.938M (± 0.5%) i/s - 35.334M in 5.092617s
Comparison:
runtime error message cost: 6938381.6 i/s
no method error message cost: 115.4 i/s - 60130.02x (± 0.00) slower
```
### Suggested solutions
1. Do not call `#inspect` on the object on which the method was not found (see <https://github.com/ruby/ruby/blob/e0915ba67964d843832148aeca29a1f8244ca7b1/…>)
2. Cache result of calling `#message` after the first call. Ideally this should be done together with suggestion 1.
--
https://bugs.ruby-lang.org/
Issue #20146 has been reported by shia (Sangyong Sim).
----------------------------------------
Bug #20146: Code using Ractor with env `RUBY_MAX_CPU=1` ends with unreachable
https://bugs.ruby-lang.org/issues/20146
* Author: shia (Sangyong Sim)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.4.0dev
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
## Reproducible code
```rb
# sample-code.rb
Ractor.new { 1 }
```
```bash
RUBY_MAX_CPU=1 ruby sample-code.rb # This will not end with exit code 0
RUBY_MAX_CPU=2 ruby sample-code.rb # This ends with exit code 0 as expected
```
## Expected
process with RUBY_MAX_CPU=1 exits successfully as same as RUBY_MAX_CPU more than 1.
--
https://bugs.ruby-lang.org/
Issue #20107 has been reported by kddnewton (Kevin Newton).
----------------------------------------
Misc #20107: Update required Oracle Solaris Studio version to 12.5
https://bugs.ruby-lang.org/issues/20107
* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
Per https://www.oracle.com/us/assets/lifetime-support-hardware-301321.pdf and https://www.oracle.com/a/ocom/docs/support/advanced-customer-support/solari…, 12.2, 12.3, and 12.4 are all end-of-life for "extended support". We should drop these old compilers from our support suite for Ruby 3.4.0 so that we can use more of C99.
Specifically, in conjunction with bumping to Visual Studio 2015, I believe this means we can now rely on `stdbool.h`, the `restrict` keyword, `va_copy`, `snprintf`, and the `%zu` printf specifier all functioning as expected.
--
https://bugs.ruby-lang.org/