Skip to content

Commit 90d74f3

Browse files
committed
[GR-32332] Backports for 20.2
PullRequest: truffleruby/2770
2 parents e62cff5 + 3f2e280 commit 90d74f3

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

.gitattributes

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Merge options
2-
3-
/CHANGELOG.md merge=union
4-
51
# Rules for GitHub's Linguist language-classification system. We're abusing the
62
# 'vendored' attribute to exclude files as a lot of this isn't really vendored,
73
# and a whole lot of actually vendored code isn't listed! What we want to do is

lib/truffle/truffle/cext_preprocessor.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def self.patch(file, contents, directory)
9696
# preprocessor macro which _must_ end with a newline and
9797
# so requires that we preserve the trailing whitespace.
9898
patched_file[:patches].each do |patch|
99-
last_line = patch[:replacement].rstrip.lines.last.lstrip
99+
replacement = patch[:replacement].rstrip
100+
last_line = replacement.lines.last || replacement # .lines returns an empty Array if String#empty?
101+
last_line = last_line.lstrip
100102
contents = contents.gsub(patch[:match],
101103
if last_line && last_line.start_with?('#')
102104
patch[:replacement]

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ protected List<String> preprocessArguments(List<String> args, Map<String, String
6868
final String launcher = ProcessProperties.getExecutableName();
6969
polyglotOptions.put(OptionsCatalog.LAUNCHER.getName(), launcher);
7070
}
71+
72+
// Instrumentation should not swallow exceptions, especially exceptions from Truffle safepoints (GR-32154)
73+
polyglotOptions.put("engine.InstrumentExceptionsAreThrown", "true");
74+
// TruffleRuby is never distributed without the GraalVM compiler, so this warning is not necessary
7175
polyglotOptions.put("engine.WarnInterpreterOnly", "false");
7276

7377
config = new CommandLineOptions();

src/main/java/org/truffleruby/core/array/ArrayAppendOneNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.oracle.truffle.api.profiles.ConditionProfile;
2626

2727
@NodeChild(value = "array", type = RubyNode.class)
28-
@NodeChild(value = "value", type = RubyNode.class)
28+
@NodeChild(value = "valueNode", type = RubyNode.class)
2929
@ImportStatic(ArrayGuards.class)
3030
public abstract class ArrayAppendOneNode extends RubyContextSourceNode {
3131

@@ -37,6 +37,8 @@ public static ArrayAppendOneNode create() {
3737

3838
public abstract RubyArray executeAppendOne(RubyArray array, Object value);
3939

40+
public abstract RubyNode getValueNode();
41+
4042
// Append of the correct type
4143

4244
@Specialization(

src/main/java/org/truffleruby/language/dispatch/RubyCallNode.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.truffleruby.RubyContext;
1313
import org.truffleruby.RubyLanguage;
14+
import org.truffleruby.core.array.ArrayAppendOneNode;
1415
import org.truffleruby.core.array.ArrayToObjectArrayNode;
1516
import org.truffleruby.core.array.ArrayToObjectArrayNodeGen;
1617
import org.truffleruby.core.array.AssignableNode;
@@ -100,8 +101,8 @@ public Object execute(VirtualFrame frame) {
100101

101102
@Override
102103
public void assign(VirtualFrame frame, Object value) {
103-
assert getLastArgumentNode() instanceof NilLiteralNode &&
104-
((NilLiteralNode) getLastArgumentNode()).isImplicit() : getLastArgumentNode();
104+
assert (getLastArgumentNode() instanceof NilLiteralNode &&
105+
((NilLiteralNode) getLastArgumentNode()).isImplicit()) : getLastArgumentNode();
105106

106107
final Object receiverObject = receiver.execute(frame);
107108
if (isSafeNavigation && nilProfile.profile(receiverObject == nil)) {
@@ -195,7 +196,11 @@ public boolean hasLiteralBlock() {
195196
}
196197

197198
private RubyNode getLastArgumentNode() {
198-
return arguments[arguments.length - 1];
199+
final RubyNode lastArg = arguments[arguments.length - 1];
200+
if (isSplatted && lastArg instanceof ArrayAppendOneNode) {
201+
return ((ArrayAppendOneNode) lastArg).getValueNode();
202+
}
203+
return lastArg;
199204
}
200205

201206
@Override

test/truffle/cexts/test-preprocess.rb renamed to test/truffle/cexts/test_preprocess.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,22 @@ def test_patch(file, directory, input, expected)
5656
}
5757
EOF
5858

59+
json_original = <<-EOF
60+
# else
61+
rb_str_resize(*result, RSTRING_LEN(*result));
62+
# endif
63+
EOF
64+
65+
json_patched = <<-EOF
66+
# else
67+
68+
# endif
69+
EOF
70+
5971
test_patch 'xml_sax_parser.c', 'ext/nokogiri', original, modified
6072
# Should not patch other files or other gems
6173
test_patch 'other_file.c', 'ext/nokogiri', original, original
6274
test_patch 'xml_sax_parser.c', 'ext/other_gem', original, original
75+
76+
# Tests an empty replacement
77+
test_patch 'parser.c', 'ext/json/ext/parser', json_original, json_patched

tool/jt.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,14 +1152,15 @@ def test(*args)
11521152

11531153
truffle_args = []
11541154
if truffleruby?
1155-
truffle_args += %w(--reveal --vm.Xmx2G)
1155+
vm_args, ruby_args, _parsed_options = ruby_options({}, %w[--vm.Xmx2G --reveal --experimental-options --testing-rubygems])
1156+
truffle_args = vm_args + ruby_args
11561157
end
11571158

11581159
env_vars = {
11591160
'EXCLUDES' => 'test/mri/excludes',
11601161
'RUBYGEMS_TEST_PATH' => "#{MRI_TEST_PREFIX}/rubygems",
11611162
'RUBYOPT' => [*ENV['RUBYOPT'], '--disable-gems'].join(' '),
1162-
'TRUFFLERUBYOPT' => [*ENV['TRUFFLERUBYOPT'], '--experimental-options', '--testing-rubygems'].join(' '),
1163+
'TRUFFLERUBYOPT' => [*ENV['TRUFFLERUBYOPT'], *truffle_args].join(' '),
11631164
}
11641165
compile_env = {
11651166
# MRI C-ext tests expect to be built with $extmk = true.
@@ -1203,7 +1204,7 @@ def test(*args)
12031204

12041205
command = %w[test/mri/tests/runner.rb -v --color=never --tty=no -q]
12051206
command.unshift("-I#{TRUFFLERUBY_DIR}/.ext") if !cext_tests.empty?
1206-
run_ruby(env_vars, *truffle_args, *extra_args, *command, *test_files, *runner_args, run_options)
1207+
run_ruby(env_vars, *extra_args, *command, *test_files, *runner_args, run_options)
12071208
end
12081209

12091210
def retag(*args)
@@ -1278,7 +1279,7 @@ def retag(*args)
12781279
case test_name
12791280
when 'tools'
12801281
# Test tools
1281-
run_ruby 'test/truffle/cexts/test-preprocess.rb'
1282+
run_ruby 'test/truffle/cexts/test_preprocess.rb'
12821283

12831284
when 'minimum', 'method', 'module', 'globals', 'backtraces', 'xopenssl'
12841285
# Test that we can compile and run some very basic C extensions

0 commit comments

Comments
 (0)