@@ -23,6 +23,16 @@ class NokogiriPatches
23
23
xmlDocPtr doc = (xmlDocPtr)c;
24
24
EOF
25
25
26
+ def self . patch_for_system_libraries ( replacement )
27
+ <<-EOF
28
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
29
+ \\ &
30
+ #else
31
+ #{ replacement }
32
+ #endif
33
+ EOF
34
+ end
35
+
26
36
PATCHES = {
27
37
gem : 'nokogiri' ,
28
38
patches : {
@@ -31,26 +41,14 @@ class NokogiriPatches
31
41
# is called with. This works on MRI but causes an error in
32
42
# TruffleRuby.
33
43
match : 'static VALUE to_array(VALUE self, VALUE rb_node)' ,
34
- replacement : <<-EOF
35
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
36
- static VALUE to_array(VALUE self, VALUE rb_node)
37
- #else
38
- static VALUE to_array(VALUE self)
39
- #endif
40
- EOF
44
+ replacement : patch_for_system_libraries ( 'static VALUE to_array(VALUE self)' )
41
45
} ,
42
46
] ,
43
47
'xslt_stylesheet.c' => [
44
48
{ # It is not currently possible to pass var args from native
45
49
# functions to sulong, so we work round the issue here.
46
50
match : 'va_list args;' ,
47
- replacement : <<-EOF
48
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
49
- va_list args;
50
- #else
51
- va_list args; rb_str_cat2(ctx, "Generic error"); return;
52
- #endif
53
- EOF
51
+ replacement : patch_for_system_libraries ( 'va_list args; rb_str_cat2(ctx, "Generic error"); return;' )
54
52
}
55
53
] ,
56
54
'xml_document.c' => [
@@ -63,69 +61,31 @@ class NokogiriPatches
63
61
{ # It is not currently possible to pass var args from native
64
62
# functions to sulong, so we work round the issue here.
65
63
match : /va_list args;[^}]*id_warning, 1, ruby_message\) ;/ ,
66
- replacement : <<-EOF
67
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
68
- \\ &
69
- #else
70
- rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2("Warning."));
71
- #endif
72
- EOF
64
+ replacement : patch_for_system_libraries ( 'rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2("Warning."));' )
73
65
} ,
74
66
{ # It is not currently possible to pass var args from native
75
67
# functions to sulong, so we work round the issue here.
76
68
match : /va_list args;[^}]*id_error, 1, ruby_message\) ;/ ,
77
- replacement : <<-EOF
78
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
79
- \\ &
80
- #else
81
- rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2("Warning."));
82
- #endif
83
- EOF
69
+ replacement : patch_for_system_libraries ( 'rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2("Warning."));' )
84
70
}
85
71
] ,
86
72
'xml_xpath_context.c' => [
87
73
{ # It is not currently possible to pass var args from native
88
74
# functions to sulong, so we work round the issue here.
89
75
match : 'va_list args;' ,
90
- replacement : <<-EOF
91
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
92
- va_list args;
93
- #else
94
- va_list args; rb_raise(rb_eRuntimeError, "%s", "Exception:"); return;
95
- #endif
96
- EOF
76
+ replacement : patch_for_system_libraries ( 'va_list args; rb_raise(rb_eRuntimeError, "%s", "Exception:"); return;' )
97
77
} ,
98
78
{
99
79
match : 'VALUE thing = Qnil;' ,
100
- replacement : <<-EOF
101
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
102
- VALUE thing = Qnil;
103
- #else
104
- VALUE thing = Qnil;
105
- VALUE errors = rb_ary_new();
106
- #endif
107
- EOF
80
+ replacement : patch_for_system_libraries ( "VALUE thing = Qnil;\n VALUE errors = rb_ary_new();" )
108
81
} ,
109
82
{
110
83
match : 'xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);' ,
111
- replacement : <<-EOF
112
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
113
- xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);
114
- #else
115
- xmlSetStructuredErrorFunc(errors, Nokogiri_error_array_pusher);
116
- #endif
117
- EOF
84
+ replacement : patch_for_system_libraries ( 'xmlSetStructuredErrorFunc(errors, Nokogiri_error_array_pusher);' )
118
85
} ,
119
86
{
120
87
match : 'if(xpath == NULL)' ,
121
- replacement : <<-EOF
122
- #ifdef NOKOGIRI_PACKAGED_LIBRARIES
123
- if(xpath == NULL)
124
- #else
125
- if (RARRAY_LEN(errors) > 0) { rb_exc_raise(rb_ary_entry(errors, 0)); }
126
- if(xpath == NULL)
127
- #endif
128
- EOF
88
+ replacement : patch_for_system_libraries ( "if (RARRAY_LEN(errors) > 0) { rb_exc_raise(rb_ary_entry(errors, 0)); }\n if(xpath == NULL)" )
129
89
} ,
130
90
] ,
131
91
}
0 commit comments