@@ -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,14 +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 : 'static VALUE to_array(VALUE self)'
44
+ replacement : patch_for_system_libraries ( 'static VALUE to_array(VALUE self)' )
35
45
} ,
36
46
] ,
37
47
'xslt_stylesheet.c' => [
38
48
{ # It is not currently possible to pass var args from native
39
49
# functions to sulong, so we work round the issue here.
40
50
match : 'va_list args;' ,
41
- replacement : 'va_list args; rb_str_cat2(ctx, "Generic error"); return;'
51
+ replacement : patch_for_system_libraries ( 'va_list args; rb_str_cat2(ctx, "Generic error"); return;' )
42
52
}
43
53
] ,
44
54
'xml_document.c' => [
@@ -51,31 +61,31 @@ class NokogiriPatches
51
61
{ # It is not currently possible to pass var args from native
52
62
# functions to sulong, so we work round the issue here.
53
63
match : /va_list args;[^}]*id_warning, 1, ruby_message\) ;/ ,
54
- replacement : 'rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2("Warning."));'
64
+ replacement : patch_for_system_libraries ( 'rb_funcall(doc, id_warning, 1, NOKOGIRI_STR_NEW2("Warning."));' )
55
65
} ,
56
66
{ # It is not currently possible to pass var args from native
57
67
# functions to sulong, so we work round the issue here.
58
68
match : /va_list args;[^}]*id_error, 1, ruby_message\) ;/ ,
59
- replacement : 'rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2("Warning."));'
69
+ replacement : patch_for_system_libraries ( 'rb_funcall(doc, id_error, 1, NOKOGIRI_STR_NEW2("Warning."));' )
60
70
}
61
71
] ,
62
72
'xml_xpath_context.c' => [
63
73
{ # It is not currently possible to pass var args from native
64
74
# functions to sulong, so we work round the issue here.
65
75
match : 'va_list args;' ,
66
- replacement : 'va_list args; rb_raise(rb_eRuntimeError, "%s", "Exception:"); return;'
76
+ replacement : patch_for_system_libraries ( 'va_list args; rb_raise(rb_eRuntimeError, "%s", "Exception:"); return;' )
67
77
} ,
68
78
{
69
79
match : 'VALUE thing = Qnil;' ,
70
- replacement : "VALUE thing = Qnil;\n VALUE errors = rb_ary_new();"
80
+ replacement : patch_for_system_libraries ( "VALUE thing = Qnil;\n VALUE errors = rb_ary_new();" )
71
81
} ,
72
82
{
73
83
match : 'xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);' ,
74
- replacement : 'xmlSetStructuredErrorFunc(errors, Nokogiri_error_array_pusher);'
84
+ replacement : patch_for_system_libraries ( 'xmlSetStructuredErrorFunc(errors, Nokogiri_error_array_pusher);' )
75
85
} ,
76
86
{
77
87
match : 'if(xpath == NULL)' ,
78
- replacement : "if (RARRAY_LEN(errors) > 0) { rb_exc_raise(rb_ary_entry(errors, 0)); }\n 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)" )
79
89
} ,
80
90
] ,
81
91
}
0 commit comments