Skip to content

Commit 5691abf

Browse files
committed
[GR-37530] [GR-37755] Backports for 22.1 batch 1
PullRequest: truffleruby/3284
2 parents 24a6f80 + b22160b commit 5691abf

File tree

63 files changed

+835
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+835
-295
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Bug fixes:
2020
* Fix `Random#rand` not returning random floats when given float ranges (#2612, @bjfish).
2121
* Fix `Array#sample` for `[]` when called without `n` and a `Random` is given (#2612, @bjfish).
2222
* Fix `Module#const_get` to raise a `NameError` when nested modules do not exist (#2610, @bjfish).
23+
* Ensure native `VALUE`s returned from C are unwrapped before the objects can be collected (@aardvark179).
24+
* Fix `Enumerator::Lazy#with_index` to start with new index for multiple enumerations (@bjfish).
25+
* Fix `rb_id2name` to ensure the native string will have the same lifetime as the id (#2630, @aardvark179).
26+
* Fix `MatchData#[]` exception when passing a length argument larger than the number of match values (#2636, @nirvdrum).
27+
* Fix `MatchData#[]` exception when supplying a large negative index along with a length argument (@nirvdrum).
28+
* Fix `Integer#fdiv` and `Rational#to_f` for large `Integer` values (#2631, @bjfish).
2329

2430
Compatibility:
2531

@@ -48,6 +54,8 @@ Compatibility:
4854
* Update `Dir.foreach` to accept an `encoding` parameter (#2627, @bjfish).
4955
* Update `IO.readlines` to ignore negative limit parameters (#2625 , @bjfish).
5056
* Update `Math.sqrt` to raise a `Math::DomainError` for negative numbers (#2621, @bjfish).
57+
* Update `Enumerable#inject` to raise an `ArgumentError` if no block or symbol are given (#2626, @bjfish).
58+
* Fix `Marshal.dump` to raise an error when an object has singleton methods (@bjfish).
5159

5260
Performance:
5361

@@ -58,7 +66,7 @@ Performance:
5866
* Reduce memory footprint by tracking `VALUE`s created during C extension init separately (@aardvark179).
5967
* Rewrote `ArrayEachIteratorNode` to optimize performance for a constant-sized array and reduce specializations to 1 general case (#2587, @MattAlp)
6068
* Reduce conversion of `VALUE`s to native handle during common operations in C extensions (@aardvark179).
61-
* Improved performance of regex boolean matches (e.g., `Regexp#match?`) by avoiding match data allocation in TRegex (#2558, @nirvdrum).
69+
* Improved performance of regex boolean matches (e.g., `Regexp#match?`) by avoiding match data allocation in TRegex (#2588, @nirvdrum).
6270
* Remove overhead when getting using `RDATA_PTR` (@aardvark179).
6371
* Additional copy operations have been reduced when performing IO (#2536, @aardvark179).
6472

bench/micro/dispatch/dispatch-mono-splat.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Callee
2-
def call(arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil)
2+
def call(arg1 = nil, arg2 = nil, arg3 = nil)
33
:foo
44
end
55
end

ci.jsonnet

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ local part_definitions = {
150150
environment+: { path+:: ["$NODE/bin"] },
151151
},
152152

153-
sqlite331: { packages+: { sqlite: ">=3.31" } },
153+
sqlite331: { packages+: { sqlite: "==3.31.0" } },
154154

155155
no_multi_tier: {
156156
environment+: {
@@ -453,7 +453,8 @@ local part_definitions = {
453453
micro: { benchmarks+:: ["micro"] },
454454
other_extra: { benchmarks+:: ["savina"] },
455455
other: { benchmarks+:: ["image-demo", "optcarrot", "synthetic", "rubykon", "liquid"] },
456-
warmup: {
456+
457+
warmup: $.use.sqlite331 + {
457458
benchmarks+:: [
458459
["--fork-count-file", "mx.truffleruby/warmup-fork-counts.json", "ruby-warmup:*"],
459460
],

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6
1+
7

lib/cext/ABI_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.1.0
1+
22.1.1

lib/truffle/truffle/cext.rb

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -975,14 +975,13 @@ def rb_path_to_class(path)
975975

976976
def rb_proc_new(function, value)
977977
Proc.new do |*args, &block|
978-
Primitive.cext_unwrap(
979-
Primitive.call_with_c_mutex_and_frame(function, [
980-
Primitive.cext_wrap(args.first), # yieldarg
981-
Primitive.cext_wrap(value), # procarg,
982-
args.size, # argc
983-
Truffle::CExt.RARRAY_PTR(args), # argv
984-
Primitive.cext_wrap(block), # blockarg
985-
], Primitive.caller_special_variables_if_available, nil))
978+
Primitive.call_with_c_mutex_and_frame_and_unwrap(function, [
979+
Primitive.cext_wrap(args.first), # yieldarg
980+
Primitive.cext_wrap(value), # procarg,
981+
args.size, # argc
982+
Truffle::CExt.RARRAY_PTR(args), # argv
983+
Primitive.cext_wrap(block), # blockarg
984+
], Primitive.caller_special_variables_if_available, nil)
986985
end
987986
end
988987

@@ -1062,7 +1061,7 @@ def rb_ivar_lookup(object, name, default_value)
10621061
end
10631062

10641063
def rb_cvar_defined(cls, id)
1065-
id_s = id.to_s
1064+
id_s = id.name
10661065
if id_s.start_with?('@@') || !id_s.start_with?('@')
10671066
cls.class_variable_defined?(id)
10681067
else
@@ -1127,7 +1126,7 @@ def rb_special_const_p(object)
11271126
end
11281127

11291128
def rb_id2str(sym)
1130-
sym.to_s
1129+
sym.name
11311130
end
11321131

11331132
def rb_const_defined?(mod, name)
@@ -1227,7 +1226,7 @@ def rb_enumeratorize(obj, meth, args)
12271226
def rb_enumeratorize_with_size(obj, meth, args, size_fn)
12281227
return rb_enumeratorize(obj, meth, args) if size_fn.nil?
12291228
enum = obj.to_enum(meth, *args) do
1230-
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(size_fn, [Primitive.cext_wrap(obj), Primitive.cext_wrap(args), Primitive.cext_wrap(enum)], Primitive.caller_special_variables_if_available, nil))
1229+
Primitive.call_with_c_mutex_and_frame_and_unwrap(size_fn, [Primitive.cext_wrap(obj), Primitive.cext_wrap(args), Primitive.cext_wrap(enum)], Primitive.caller_special_variables_if_available, nil)
12311230
end
12321231
enum
12331232
end
@@ -1242,7 +1241,7 @@ def rb_newobj_of(ruby_class)
12421241

12431242
def rb_define_alloc_func(ruby_class, function)
12441243
ruby_class.singleton_class.define_method(:__allocate__) do
1245-
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(function, [Primitive.cext_wrap(self)], Primitive.caller_special_variables_if_available, nil))
1244+
Primitive.call_with_c_mutex_and_frame_and_unwrap(function, [Primitive.cext_wrap(self)], Primitive.caller_special_variables_if_available, nil)
12461245
end
12471246
class << ruby_class
12481247
private :__allocate__
@@ -1667,13 +1666,13 @@ def rb_thread_call_without_gvl(function, data1, unblock, data2)
16671666
def rb_iterate(iteration, iterated_object, callback, callback_arg)
16681667
block = rb_block_proc
16691668
wrapped_callback = proc do |block_arg|
1670-
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(callback, [
1669+
Primitive.call_with_c_mutex_and_frame_and_unwrap(callback, [
16711670
Primitive.cext_wrap(block_arg),
16721671
Primitive.cext_wrap(callback_arg),
16731672
0, # argc
16741673
nil, # argv
16751674
nil, # blockarg
1676-
], Primitive.cext_special_variables_from_stack, block))
1675+
], Primitive.cext_special_variables_from_stack, block)
16771676
end
16781677
Primitive.cext_unwrap(
16791678
Primitive.call_with_c_mutex_and_frame(iteration, [Primitive.cext_wrap(iterated_object)], Primitive.cext_special_variables_from_stack, wrapped_callback))
@@ -1761,7 +1760,7 @@ def rb_gv_set(name, value)
17611760
end
17621761

17631762
def rb_gv_get(name)
1764-
name = "$#{name}" unless name.to_s.start_with?('$')
1763+
name = "$#{name}" unless name.start_with?('$')
17651764
if name == '$~'
17661765
rb_backref_get
17671766
else
@@ -1785,7 +1784,7 @@ def rb_define_hooked_variable(name, gvar, getter, setter)
17851784
id = name.to_sym
17861785

17871786
getter_proc = -> {
1788-
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(getter, [Primitive.cext_wrap(id), gvar, Primitive.cext_wrap(nil)], Primitive.caller_special_variables_if_available, nil))
1787+
Primitive.call_with_c_mutex_and_frame_and_unwrap(getter, [Primitive.cext_wrap(id), gvar, Primitive.cext_wrap(nil)], Primitive.caller_special_variables_if_available, nil)
17891788
}
17901789

17911790
setter_proc = -> value {
@@ -1910,14 +1909,13 @@ def rb_fiber_current
19101909

19111910
def rb_fiber_new(function, value)
19121911
Fiber.new do |*args|
1913-
Primitive.cext_unwrap(
1914-
Primitive.call_with_c_mutex_and_frame(function, [
1915-
Primitive.cext_wrap(args.first), # yieldarg
1916-
nil, # procarg,
1917-
0, # argc
1918-
nil, # argv
1919-
nil, # blockarg
1920-
], nil, nil))
1912+
Primitive.call_with_c_mutex_and_frame_and_unwrap(function, [
1913+
Primitive.cext_wrap(args.first), # yieldarg
1914+
nil, # procarg,
1915+
0, # argc
1916+
nil, # argv
1917+
nil, # blockarg
1918+
], nil, nil)
19211919
end
19221920
end
19231921

lib/truffle/truffle/cext_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def rb_define_method(mod, name, function, argc)
3838
# We must set block argument if given here so that the
3939
# `rb_block_*` functions will be able to find it by walking the
4040
# stack.
41-
res = Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(function, args, Primitive.caller_special_variables_if_available, block))
41+
res = Primitive.call_with_c_mutex_and_frame_and_unwrap(function, args, Primitive.caller_special_variables_if_available, block)
4242
Primitive.thread_set_exception(exc)
4343
res
4444
end

spec/mspec/lib/mspec/expectations/expectations.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ def self.fail_predicate(receiver, predicate, args, block, result, expectation)
3232
result_to_s = MSpec.format(result)
3333
raise SpecExpectationNotMetError, "Expected #{receiver_to_s}#{predicate_to_s}#{args_to_s}\n#{expectation} but was #{result_to_s}"
3434
end
35+
36+
def self.fail_single_arg_predicate(receiver, predicate, arg, result, expectation)
37+
fail_predicate(receiver, predicate, [arg], nil, result, expectation)
38+
end
3539
end

spec/mspec/lib/mspec/matchers/base.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ def initialize(actual)
1616
end
1717

1818
def ==(expected)
19-
method_missing(:==, expected)
19+
result = @actual == expected
20+
unless result
21+
::SpecExpectation.fail_single_arg_predicate(@actual, :==, expected, result, "to be truthy")
22+
end
2023
end
2124

2225
def !=(expected)
23-
method_missing(:!=, expected)
26+
result = @actual != expected
27+
unless result
28+
::SpecExpectation.fail_single_arg_predicate(@actual, :!=, expected, result, "to be truthy")
29+
end
2430
end
2531

2632
def equal?(expected)
27-
method_missing(:equal?, expected)
33+
result = @actual.equal?(expected)
34+
unless result
35+
::SpecExpectation.fail_single_arg_predicate(@actual, :equal?, expected, result, "to be truthy")
36+
end
2837
end
2938

3039
def method_missing(name, *args, &block)
@@ -41,15 +50,24 @@ def initialize(actual)
4150
end
4251

4352
def ==(expected)
44-
method_missing(:==, expected)
53+
result = @actual == expected
54+
if result
55+
::SpecExpectation.fail_single_arg_predicate(@actual, :==, expected, result, "to be falsy")
56+
end
4557
end
4658

4759
def !=(expected)
48-
method_missing(:!=, expected)
60+
result = @actual != expected
61+
if result
62+
::SpecExpectation.fail_single_arg_predicate(@actual, :!=, expected, result, "to be falsy")
63+
end
4964
end
5065

5166
def equal?(expected)
52-
method_missing(:equal?, expected)
67+
result = @actual.equal?(expected)
68+
if result
69+
::SpecExpectation.fail_single_arg_predicate(@actual, :equal?, expected, result, "to be falsy")
70+
end
5371
end
5472

5573
def method_missing(name, *args, &block)

spec/ruby/core/enumerable/shared/inject.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
end
1818

1919
it "ignores the block if two arguments" do
20-
EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-){ raise "we never get here"}.should == 4
20+
EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-) { raise "we never get here"}.should == 4
21+
[].send(@method, 3, :+) { raise "we never get here"}.should == 3
2122
end
2223

2324
it "can take a symbol argument" do
@@ -66,4 +67,11 @@
6667
it "returns nil when fails(legacy rubycon)" do
6768
EnumerableSpecs::EachDefiner.new().send(@method) {|acc,x| 999 }.should == nil
6869
end
70+
71+
ruby_bug '#18635', ''...'3.2' do
72+
it "raises an ArgumentError when no parameters or block is given" do
73+
-> { [1,2].send(@method) }.should raise_error(ArgumentError)
74+
-> { {one: 1, two: 2}.send(@method) }.should raise_error(ArgumentError)
75+
end
76+
end
6977
end

0 commit comments

Comments
 (0)