@@ -23,14 +23,8 @@ 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
26
+ def self . using_system_libraries?
27
+ !ARGV . include? ( '-DNOKOGIRI_PACKAGED_LIBRARIES' )
34
28
end
35
29
36
30
PATCHES = {
@@ -41,14 +35,16 @@ def self.patch_for_system_libraries(replacement)
41
35
# is called with. This works on MRI but causes an error in
42
36
# TruffleRuby.
43
37
match : 'static VALUE to_array(VALUE self, VALUE rb_node)' ,
44
- replacement : patch_for_system_libraries ( 'static VALUE to_array(VALUE self)' )
38
+ replacement : 'static VALUE to_array(VALUE self)' ,
39
+ predicate : -> { using_system_libraries? }
45
40
} ,
46
41
] ,
47
42
'xslt_stylesheet.c' => [
48
43
{ # It is not currently possible to pass var args from native
49
44
# functions to sulong, so we work round the issue here.
50
45
match : 'va_list args;' ,
51
- replacement : patch_for_system_libraries ( 'va_list args; rb_str_cat2(ctx, "Generic error"); return;' )
46
+ replacement : 'va_list args; rb_str_cat2(ctx, "Generic error"); return;' ,
47
+ predicate : -> { using_system_libraries? }
52
48
}
53
49
] ,
54
50
'xml_document.c' => [
@@ -61,31 +57,37 @@ def self.patch_for_system_libraries(replacement)
61
57
{ # It is not currently possible to pass var args from native
62
58
# functions to sulong, so we work round the issue here.
63
59
match : /va_list args;[^}]*id_warning, 1, ruby_message\) ;/ ,
64
- replacement : patch_for_system_libraries ( 'rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2("Warning."));' )
60
+ replacement : 'rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2("Warning."));' ,
61
+ predicate : -> { using_system_libraries? }
65
62
} ,
66
63
{ # It is not currently possible to pass var args from native
67
64
# functions to sulong, so we work round the issue here.
68
65
match : /va_list args;[^}]*id_error, 1, ruby_message\) ;/ ,
69
- replacement : patch_for_system_libraries ( 'rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2("Warning."));' )
66
+ replacement : 'rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2("Warning."));' ,
67
+ predicate : -> { using_system_libraries? }
70
68
}
71
69
] ,
72
70
'xml_xpath_context.c' => [
73
71
{ # It is not currently possible to pass var args from native
74
72
# functions to sulong, so we work round the issue here.
75
73
match : 'va_list args;' ,
76
- replacement : patch_for_system_libraries ( 'va_list args; rb_raise(rb_eRuntimeError, "%s", "Exception:"); return;' )
74
+ replacement : 'va_list args; rb_raise(rb_eRuntimeError, "%s", "Exception:"); return;' ,
75
+ predicate : -> { using_system_libraries? }
77
76
} ,
78
77
{
79
78
match : 'VALUE thing = Qnil;' ,
80
- replacement : patch_for_system_libraries ( "VALUE thing = Qnil;\n VALUE errors = rb_ary_new();" )
79
+ replacement : "VALUE thing = Qnil;\n VALUE errors = rb_ary_new();" ,
80
+ predicate : -> { using_system_libraries? }
81
81
} ,
82
82
{
83
83
match : 'xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);' ,
84
- replacement : patch_for_system_libraries ( 'xmlSetStructuredErrorFunc(errors, Nokogiri_error_array_pusher);' )
84
+ replacement : 'xmlSetStructuredErrorFunc(errors, Nokogiri_error_array_pusher);' ,
85
+ predicate : -> { using_system_libraries? }
85
86
} ,
86
87
{
87
88
match : 'if(xpath == NULL)' ,
88
- replacement : patch_for_system_libraries ( "if (RARRAY_LEN(errors) > 0) { rb_exc_raise(rb_ary_entry(errors, 0)); }\n if(xpath == NULL)" )
89
+ replacement : "if (RARRAY_LEN(errors) > 0) { rb_exc_raise(rb_ary_entry(errors, 0)); }\n if(xpath == NULL)" ,
90
+ predicate : -> { using_system_libraries? }
89
91
} ,
90
92
] ,
91
93
}
0 commit comments