Skip to content

Commit 82619a8

Browse files
committed
Detect patches ending in a preprocessor directive and don't rstrip.
1 parent 19001af commit 82619a8

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

lib/truffle/truffle/cext_preprocessor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +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.split("\n").last.lstrip
99100
contents = contents.gsub(patch[:match],
100-
if patch[:no_rstrip]
101+
if last_line && last_line.start_with?('#')
101102
patch[:replacement]
102103
else
103104
patch[:replacement].rstrip

lib/truffle/truffle/patches/nokogiri_patches.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class NokogiriPatches
3131
# is called with. This works on MRI but causes an error in
3232
# TruffleRuby.
3333
match: 'static VALUE to_array(VALUE self, VALUE rb_node)',
34-
no_rstrip: true,
3534
replacement: <<-EOF
3635
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
3736
static VALUE to_array(VALUE self, VALUE rb_node)
@@ -45,7 +44,6 @@ class NokogiriPatches
4544
{ # It is not currently possible to pass var args from native
4645
# functions to sulong, so we work round the issue here.
4746
match: 'va_list args;',
48-
no_rstrip: true,
4947
replacement: <<-EOF
5048
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
5149
va_list args;
@@ -65,7 +63,6 @@ class NokogiriPatches
6563
{ # It is not currently possible to pass var args from native
6664
# functions to sulong, so we work round the issue here.
6765
match: /va_list args;[^}]*id_warning, 1, ruby_message\);/,
68-
no_rstrip: true,
6966
replacement: <<-EOF
7067
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
7168
\\&
@@ -77,7 +74,6 @@ class NokogiriPatches
7774
{ # It is not currently possible to pass var args from native
7875
# functions to sulong, so we work round the issue here.
7976
match: /va_list args;[^}]*id_error, 1, ruby_message\);/,
80-
no_rstrip: true,
8177
replacement: <<-EOF
8278
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
8379
\\&
@@ -91,7 +87,6 @@ class NokogiriPatches
9187
{ # It is not currently possible to pass var args from native
9288
# functions to sulong, so we work round the issue here.
9389
match: 'va_list args;',
94-
no_rstrip: true,
9590
replacement: <<-EOF
9691
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
9792
va_list args;
@@ -113,7 +108,6 @@ class NokogiriPatches
113108
},
114109
{
115110
match: 'xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);',
116-
no_rstrip: true,
117111
replacement: <<-EOF
118112
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
119113
xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);
@@ -124,7 +118,6 @@ class NokogiriPatches
124118
},
125119
{
126120
match: 'if(xpath == NULL)',
127-
no_rstrip: true,
128121
replacement: <<-EOF
129122
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
130123
if(xpath == NULL)

0 commit comments

Comments
 (0)