Skip to content

Commit 5f52ae9

Browse files
committed
[GR-35563] Backports for 22.0 batch 2
PullRequest: truffleruby/3108
2 parents 5dd49f1 + abd7825 commit 5f52ae9

File tree

29 files changed

+184
-64
lines changed

29 files changed

+184
-64
lines changed

CHANGELOG.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,55 @@
22

33
New features:
44

5-
* Updated to Ruby 3.0.2 (#2453).
5+
* Updated to Ruby 3.0.2 (#2453, @eregon).
66

77
Bug fixes:
88

9-
* Fix `File.utime` to use nanoseconds (#2448).
10-
* Capture the intercepted feature path during patching to reuse during patch require (#2441).
11-
* Update `Module#constants` to filter invalid constant identifiers (#2452).
12-
* Fixed `-0.0 <=> 0.0` and `-0.0 <=> 0` to return `0` like on CRuby (#1391).
9+
* Fix `File.utime` to use nanoseconds (#2448, @bjfish).
10+
* Capture the intercepted feature path during patching to reuse during patch require (#2441, @bjfish).
11+
* Update `Module#constants` to filter invalid constant identifiers (#2452, @bjfish).
12+
* Fixed `-0.0 <=> 0.0` and `-0.0 <=> 0` to return `0` like on CRuby (#1391, @eregon).
1313
* Fixed `Range#step` to return correct class with begin-less range (@ccocchi, #2516).
1414
* Fixed exception creation when an `Errno` is sub-classed (@bjfish, #2521).
15+
* Fixed `String#[]=` to use the negotiated encoding (@bjfish, #2545).
1516

1617
Compatibility:
1718

18-
* Implement `rb_sprintf` in our format compiler to provide consistent formatting across C standard libraries.
19-
* Update `defined?` to return frozen strings (#2450).
20-
* Use compensated summation for `{Array,Enumerable}#sum` when floating point values are included.
19+
* Implement `rb_sprintf` in our format compiler to provide consistent formatting across C standard libraries (@eregon).
20+
* Update `defined?` to return frozen strings (#2450, @bjfish).
21+
* Use compensated summation for `{Array,Enumerable}#sum` when floating point values are included (@eregon).
2122
* `Module#attr_*` methods now return an array of method names (#2498, @gogainda).
2223
* Fixed `Socket#(local|remote)_address` to retrieve family and type from the file descriptor (#2444, @larskanis).
23-
* Add `Thread.ignore_deadlock` accessor (#2453).
24+
* Add `Thread.ignore_deadlock` accessor (#2453, @bjfish).
2425
* Allow `Hash#transform_keys` to take a hash argument (@ccocchi, #2464).
25-
* Add `Enumerable#grep{_v}` optimization for `Regexp` (#2453).
26-
* Update `IO#write` to accept multiple arguments (#2501).
26+
* Add `Enumerable#grep{_v}` optimization for `Regexp` (#2453, @bjfish).
27+
* Update `IO#write` to accept multiple arguments (#2501, @bjfish).
2728
* Do not warn when uninitialized instance variable is accessed (#2502, @andrykonchin).
2829
* Remove `TRUE`, `FALSE`, and `NIL` constants like CRuby 3.0 (#2505, @andrykonchin).
2930
* `Symbol#to_proc` now returns a lambda like in Ruby 3 (#2508, @andrykonchin).
3031
* `Kernel#lambda` now warns if called without a literal block (#2500, @andrykonchin).
3132
* Implement Hash#except (#2463, @wildmaples).
32-
* Remove special `$SAFE` global and related C API methods (#2453).
33+
* Remove special `$SAFE` global and related C API methods (#2453, @bjfish).
3334
* Assigning to a numbered parameter raises `SyntaxError` (#2506, @andrykonchin).
34-
* Implement `--backtrace-limit` option (#2453).
35-
* Update `String` methods to return `String` instances when called on a subclass (#2453).
36-
* Update `String#encode` to support the `:fallback` option (#1391).
35+
* Implement `--backtrace-limit` option (#2453, @bjfish).
36+
* Update `String` methods to return `String` instances when called on a subclass (#2453, @bjfish).
37+
* Update `String#encode` to support the `:fallback` option (#1391, @aardvark179).
3738
* `Module#alias_method` now returns the defined alias as a symbol(#2499, @gogainda).
38-
* Implement `Symbol#name` (#2453).
39-
* Update `Module#{public, protected, private, public_class_method, private_class_method}` and top-level `private` and `public` methods to accept single array argument with a list of method names (#2453).
40-
* Constants deprecated by `Module#deprecate_constant` only warn if `Warning[:deprecated]` is `true`.
39+
* Implement `Symbol#name` (#2453, @bjfish).
40+
* Update `Module#{public, protected, private, public_class_method, private_class_method}` and top-level `private` and `public` methods to accept single array argument with a list of method names (#2453, @bjfish).
41+
* Constants deprecated by `Module#deprecate_constant` only warn if `Warning[:deprecated]` is `true` (@eregon).
4142
* All Array methods now return Array instances and not subclasses (#2510, @Strech).
42-
* Integer#zero? overrides Numeric#zero? for optimization (#2453).
43-
* Default `Kernel#eval` source file and line to `(eval):1` like CRuby 3 (#2453).
44-
* Add `GC.auto_compact` accessors for compatibility (#2453).
43+
* Integer#zero? overrides Numeric#zero? for optimization (#2453, @bjfish).
44+
* Default `Kernel#eval` source file and line to `(eval):1` like CRuby 3 (#2453, @aardvark179).
45+
* Add `GC.auto_compact` accessors for compatibility (#2453, @bjfish).
4546
* Update accessing a class variable from the top-level scope to be a `RuntimeError` (#2453, @bjfish).
46-
* Update interpolated strings to not be frozen (#2453).
47+
* Update interpolated strings to not be frozen (#2453, @bjfish).
4748
* Add `WERRORFLAG` to `RbConfig` (#2519, @bjfish).
4849
* Update `MatchData` methods to return `String` instances when called on a subclass (#2453, @bjfish).
49-
* Implement `Proc#{==,eql?}` (#2453).
50+
* Implement `Proc#{==,eql?}` (#2453, @bjfish).
5051
* Implement all `StringScanner` methods (#2520, @eregon).
5152
* Handle `Kernel#clone(freeze: true)` (#2512, @andrykonchin).
52-
* Relax `Fiber#transfer` limitations (#2453).
53+
* Relax `Fiber#transfer` limitations (#2453, @bjfish).
5354
* Implement `Fiber#blocking?` like CRuby 3 (#2453, @aardvark179).
5455
* Sort by default for `Dir.{glob,[]}` and add `sort:` keyword argument (#2523, @Strech).
5556
* Implement `rb_str_locktmp` and `rb_str_unlocktmp` (#2524, @bjfish).
@@ -59,13 +60,16 @@ Compatibility:
5960
* Add category kwarg to Kernel.warn and Warning.warn (#2533, @Strech).
6061
* Implement `GC.{measure_total_time, total_time}` and update `GC.stat` to update provided hash (#2535, @bjfish).
6162
* Implement `Array#slice` with `ArithmeticSequence` (#2526, @ccocchi).
62-
* Update `Hash#each` to consistently yield a 2-element array (#2453).
63+
* Update `Hash#each` to consistently yield a 2-element array (#2453, @bjfish).
64+
* Remove `Hash#{__store__, index}` methods for compatibility (#2546, @bjfish).
65+
* Implement more correct conversion of array elements by `Array#pack` (#2503, #2504, @aardvark179).
66+
* Update `String#split` to raise a `RangeError` when `limit` is larger than `int` (@bjfish).
6367

6468
Performance:
6569

66-
* Regexp objects are now interned in a similar way to symbols.
70+
* Regexp objects are now interned in a similar way to symbols (@aardvark179).
6771
* Improve performance of regexps using POSIX bracket expressions (e.g., `[[:lower:]]`) matching against ASCII-only strings (#2447, @nirvdrum).
68-
* `String#sub`, `sub!`, `gsub`, and `gsub!` have been refactored for better performance.
72+
* `String#sub`, `sub!`, `gsub`, and `gsub!` have been refactored for better performance (@aardvark179).
6973
* Don't allocate a `MatchData` object when `Regexp#match?` or `String#match?` is used (#2509, @nirvdrum).
7074
* Add `ENV.except` (#2507, @Strech).
7175
* Fully inline the `Integer#+` and `Integer#-` logic for interpreter speed (#2518, @smarr).
@@ -75,7 +79,7 @@ Performance:
7579

7680
Changes:
7781

78-
* TruffleRuby now requires Java 11+ and no longer supports Java 8.
82+
* TruffleRuby now requires Java 11+ and no longer supports Java 8 (@eregon).
7983

8084
# 21.3.0
8185

lib/truffle/truffle/openssl-prefix.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727

2828
if homebrew and prefix = search_homebrew.call(homebrew)
2929
# found
30-
elsif Dir.exist?('/opt/local/include/openssl') # MacPorts
30+
elsif Dir.exist?('/opt/local/libexec/openssl11') # MacPorts, prefer OpenSSL 1.1 as known to be compatible
31+
prefix = '/opt/local/libexec/openssl11'
32+
# MacPorts, try the generic version, too, but might not be compatible
33+
elsif Dir.exist?('/opt/local/include/openssl')
3134
prefix = '/opt/local'
3235
end
3336
end

spec/ruby/core/array/pack/a_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
it_behaves_like :array_pack_string, 'A'
1313
it_behaves_like :array_pack_taint, 'A'
1414

15+
it "calls #to_str to convert an Object to a String" do
16+
obj = mock("pack A string")
17+
obj.should_receive(:to_str).and_return("``abcdef")
18+
[obj].pack("A*").should == "``abcdef"
19+
end
20+
21+
it "will not implicitly convert a number to a string" do
22+
-> { [0].pack('A') }.should raise_error(TypeError)
23+
-> { [0].pack('a') }.should raise_error(TypeError)
24+
end
25+
1526
it "adds all the bytes to the output when passed the '*' modifier" do
1627
["abc"].pack("A*").should == "abc"
1728
end

spec/ruby/core/array/pack/b_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
it_behaves_like :array_pack_taint, 'B'
1414

1515
it "calls #to_str to convert an Object to a String" do
16-
obj = mock("pack H string")
16+
obj = mock("pack B string")
1717
obj.should_receive(:to_str).and_return("``abcdef")
1818
[obj].pack("B*").should == "\x2a"
1919
end
2020

21+
it "will not implicitly convert a number to a string" do
22+
-> { [0].pack('B') }.should raise_error(TypeError)
23+
-> { [0].pack('b') }.should raise_error(TypeError)
24+
end
25+
2126
it "encodes one bit for each character starting with the most significant bit" do
2227
[ [["0"], "\x00"],
2328
[["1"], "\x80"]

spec/ruby/core/array/pack/h_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
[obj].pack("H").should == "\xa0"
1919
end
2020

21+
it "will not implicitly convert a number to a string" do
22+
-> { [0].pack('H') }.should raise_error(TypeError)
23+
-> { [0].pack('h') }.should raise_error(TypeError)
24+
end
25+
2126
it "encodes the first character as the most significant nibble when passed no count modifier" do
2227
["ab"].pack("H").should == "\xa0"
2328
end

spec/ruby/core/array/pack/shared/float.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
it "encodes a negative Float outside the range of a single precision float" do
5454
[-1e150].pack(pack_format).should == "\x00\x00\x80\xff"
5555
end
56+
57+
it "encodes a bignum as a float" do
58+
[2 ** 65].pack(pack_format).should == [(2 ** 65).to_f].pack(pack_format)
59+
end
60+
61+
it "encodes a rational as a float" do
62+
[Rational(3, 4)].pack(pack_format).should == [Rational(3, 4).to_f].pack(pack_format)
63+
end
5664
end
5765

5866
describe :array_pack_float_be, shared: true do

spec/ruby/core/array/pack/u_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
it_behaves_like :array_pack_arguments, 'u'
1919
it_behaves_like :array_pack_taint, 'u'
2020

21+
it "calls #to_str to convert an Object to a String" do
22+
obj = mock("pack u string")
23+
obj.should_receive(:to_str).and_return("``abcdef")
24+
[obj].pack("u*").should == "(8&!A8F-D968`\n"
25+
end
26+
27+
it "will not implicitly convert a number to a string" do
28+
-> { [0].pack('u') }.should raise_error(TypeError)
29+
end
30+
2131
it "encodes an empty string as an empty string" do
2232
[""].pack("u").should == ""
2333
end

spec/ruby/core/array/pack/z_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
it_behaves_like :array_pack_string, 'Z'
1313
it_behaves_like :array_pack_taint, 'Z'
1414

15+
it "calls #to_str to convert an Object to a String" do
16+
obj = mock("pack Z string")
17+
obj.should_receive(:to_str).and_return("``abcdef")
18+
[obj].pack("Z*").should == "``abcdef\x00"
19+
end
20+
21+
it "will not implicitly convert a number to a string" do
22+
-> { [0].pack('Z') }.should raise_error(TypeError)
23+
end
24+
1525
it "adds all the bytes and appends a NULL byte when passed the '*' modifier" do
1626
["abc"].pack("Z*").should == "abc\x00"
1727
end

spec/ruby/core/module/include_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,27 @@ def self.foo
532532
B.foo.should == 'n'
533533
end
534534
end
535+
536+
it "overrides a previous super method call" do
537+
c1 = Class.new do
538+
def foo
539+
[:c1]
540+
end
541+
end
542+
c2 = Class.new(c1) do
543+
def foo
544+
[:c2] + super
545+
end
546+
end
547+
c2.new.foo.should == [:c2, :c1]
548+
m = Module.new do
549+
def foo
550+
[:m1]
551+
end
552+
end
553+
c2.include(m)
554+
c2.new.foo.should == [:c2, :m1]
555+
end
535556
end
536557

537558
describe "Module#include?" do

spec/ruby/core/string/element_set_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@
141141
str.encoding.should equal(Encoding::BINARY)
142142
end
143143

144+
it "updates the string to a compatible encoding" do
145+
str = " "
146+
str[1] = [0xB9].pack("C*")
147+
str.encoding.should == Encoding::ASCII_8BIT
148+
end
149+
144150
it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
145151
str = "あれ"
146152
rep = "が".encode Encoding::EUC_JP

0 commit comments

Comments
 (0)