nokogiri 1.12.5 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +41 -0
  3. data/LICENSE-DEPENDENCIES.md +830 -509
  4. data/LICENSE.md +1 -1
  5. data/README.md +23 -14
  6. data/bin/nokogiri +63 -50
  7. data/dependencies.yml +33 -66
  8. data/ext/nokogiri/extconf.rb +159 -63
  9. data/ext/nokogiri/gumbo.c +21 -11
  10. data/ext/nokogiri/html4_document.c +2 -2
  11. data/ext/nokogiri/html4_element_description.c +1 -1
  12. data/ext/nokogiri/html4_entity_lookup.c +2 -2
  13. data/ext/nokogiri/html4_sax_parser_context.c +3 -9
  14. data/ext/nokogiri/html4_sax_push_parser.c +1 -1
  15. data/ext/nokogiri/nokogiri.c +38 -51
  16. data/ext/nokogiri/nokogiri.h +26 -14
  17. data/ext/nokogiri/test_global_handlers.c +1 -1
  18. data/ext/nokogiri/xml_attr.c +3 -3
  19. data/ext/nokogiri/xml_attribute_decl.c +5 -5
  20. data/ext/nokogiri/xml_cdata.c +3 -3
  21. data/ext/nokogiri/xml_comment.c +1 -1
  22. data/ext/nokogiri/xml_document.c +53 -44
  23. data/ext/nokogiri/xml_document_fragment.c +1 -3
  24. data/ext/nokogiri/xml_dtd.c +11 -11
  25. data/ext/nokogiri/xml_element_content.c +3 -3
  26. data/ext/nokogiri/xml_element_decl.c +5 -5
  27. data/ext/nokogiri/xml_encoding_handler.c +28 -14
  28. data/ext/nokogiri/xml_entity_decl.c +6 -6
  29. data/ext/nokogiri/xml_entity_reference.c +1 -1
  30. data/ext/nokogiri/xml_namespace.c +80 -14
  31. data/ext/nokogiri/xml_node.c +982 -396
  32. data/ext/nokogiri/xml_node_set.c +4 -6
  33. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  34. data/ext/nokogiri/xml_reader.c +133 -32
  35. data/ext/nokogiri/xml_relax_ng.c +1 -3
  36. data/ext/nokogiri/xml_sax_parser.c +23 -17
  37. data/ext/nokogiri/xml_sax_parser_context.c +11 -9
  38. data/ext/nokogiri/xml_sax_push_parser.c +1 -3
  39. data/ext/nokogiri/xml_schema.c +4 -6
  40. data/ext/nokogiri/xml_syntax_error.c +1 -1
  41. data/ext/nokogiri/xml_text.c +2 -2
  42. data/ext/nokogiri/xml_xpath_context.c +144 -114
  43. data/ext/nokogiri/xslt_stylesheet.c +122 -23
  44. data/gumbo-parser/Makefile +10 -0
  45. data/gumbo-parser/src/attribute.h +1 -1
  46. data/gumbo-parser/src/error.c +2 -2
  47. data/gumbo-parser/src/error.h +1 -1
  48. data/gumbo-parser/src/foreign_attrs.c +2 -2
  49. data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
  50. data/gumbo-parser/src/parser.c +8 -16
  51. data/gumbo-parser/src/replacement.h +1 -1
  52. data/gumbo-parser/src/string_buffer.h +1 -1
  53. data/gumbo-parser/src/string_piece.c +1 -1
  54. data/gumbo-parser/src/svg_attrs.c +2 -2
  55. data/gumbo-parser/src/svg_tags.c +2 -2
  56. data/gumbo-parser/src/tag.c +2 -1
  57. data/gumbo-parser/src/tag_lookup.c +7 -7
  58. data/gumbo-parser/src/tag_lookup.gperf +1 -0
  59. data/gumbo-parser/src/tag_lookup.h +1 -1
  60. data/gumbo-parser/src/token_buffer.h +1 -1
  61. data/gumbo-parser/src/tokenizer.c +1 -1
  62. data/gumbo-parser/src/tokenizer.h +1 -1
  63. data/gumbo-parser/src/utf8.c +1 -1
  64. data/gumbo-parser/src/utf8.h +1 -1
  65. data/gumbo-parser/src/util.c +1 -3
  66. data/gumbo-parser/src/util.h +4 -0
  67. data/gumbo-parser/src/vector.h +1 -1
  68. data/lib/nokogiri/class_resolver.rb +67 -0
  69. data/lib/nokogiri/css/node.rb +9 -8
  70. data/lib/nokogiri/css/parser.rb +360 -341
  71. data/lib/nokogiri/css/parser.y +249 -244
  72. data/lib/nokogiri/css/parser_extras.rb +22 -20
  73. data/lib/nokogiri/css/syntax_error.rb +1 -0
  74. data/lib/nokogiri/css/tokenizer.rb +4 -3
  75. data/lib/nokogiri/css/tokenizer.rex +3 -2
  76. data/lib/nokogiri/css/xpath_visitor.rb +184 -85
  77. data/lib/nokogiri/css.rb +44 -6
  78. data/lib/nokogiri/decorators/slop.rb +8 -7
  79. data/lib/nokogiri/encoding_handler.rb +57 -0
  80. data/lib/nokogiri/extension.rb +4 -3
  81. data/lib/nokogiri/gumbo.rb +1 -0
  82. data/lib/nokogiri/html.rb +16 -10
  83. data/lib/nokogiri/html4/builder.rb +1 -0
  84. data/lib/nokogiri/html4/document.rb +56 -164
  85. data/lib/nokogiri/html4/document_fragment.rb +11 -7
  86. data/lib/nokogiri/html4/element_description.rb +1 -0
  87. data/lib/nokogiri/html4/element_description_defaults.rb +432 -532
  88. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  89. data/lib/nokogiri/html4/entity_lookup.rb +2 -1
  90. data/lib/nokogiri/html4/sax/parser.rb +5 -2
  91. data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
  92. data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
  93. data/lib/nokogiri/html4.rb +12 -5
  94. data/lib/nokogiri/html5/document.rb +126 -32
  95. data/lib/nokogiri/html5/document_fragment.rb +14 -4
  96. data/lib/nokogiri/html5/node.rb +12 -7
  97. data/lib/nokogiri/html5.rb +138 -222
  98. data/lib/nokogiri/jruby/dependencies.rb +2 -19
  99. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  100. data/lib/nokogiri/syntax_error.rb +1 -0
  101. data/lib/nokogiri/version/constant.rb +2 -1
  102. data/lib/nokogiri/version/info.rb +32 -24
  103. data/lib/nokogiri/version.rb +1 -0
  104. data/lib/nokogiri/xml/attr.rb +54 -3
  105. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  106. data/lib/nokogiri/xml/builder.rb +35 -33
  107. data/lib/nokogiri/xml/cdata.rb +2 -1
  108. data/lib/nokogiri/xml/character_data.rb +1 -0
  109. data/lib/nokogiri/xml/document.rb +232 -143
  110. data/lib/nokogiri/xml/document_fragment.rb +88 -42
  111. data/lib/nokogiri/xml/dtd.rb +3 -2
  112. data/lib/nokogiri/xml/element_content.rb +1 -0
  113. data/lib/nokogiri/xml/element_decl.rb +2 -1
  114. data/lib/nokogiri/xml/entity_decl.rb +3 -2
  115. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  116. data/lib/nokogiri/xml/namespace.rb +44 -0
  117. data/lib/nokogiri/xml/node/save_options.rb +14 -8
  118. data/lib/nokogiri/xml/node.rb +708 -383
  119. data/lib/nokogiri/xml/node_set.rb +134 -59
  120. data/lib/nokogiri/xml/notation.rb +12 -0
  121. data/lib/nokogiri/xml/parse_options.rb +140 -56
  122. data/lib/nokogiri/xml/pp/character_data.rb +8 -6
  123. data/lib/nokogiri/xml/pp/node.rb +26 -26
  124. data/lib/nokogiri/xml/pp.rb +1 -0
  125. data/lib/nokogiri/xml/processing_instruction.rb +3 -1
  126. data/lib/nokogiri/xml/reader.rb +20 -24
  127. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  128. data/lib/nokogiri/xml/sax/document.rb +20 -19
  129. data/lib/nokogiri/xml/sax/parser.rb +38 -36
  130. data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
  131. data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
  132. data/lib/nokogiri/xml/sax.rb +1 -0
  133. data/lib/nokogiri/xml/schema.rb +7 -6
  134. data/lib/nokogiri/xml/searchable.rb +93 -62
  135. data/lib/nokogiri/xml/syntax_error.rb +5 -4
  136. data/lib/nokogiri/xml/text.rb +1 -0
  137. data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
  138. data/lib/nokogiri/xml/xpath.rb +12 -0
  139. data/lib/nokogiri/xml/xpath_context.rb +2 -3
  140. data/lib/nokogiri/xml.rb +4 -3
  141. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  142. data/lib/nokogiri/xslt.rb +21 -13
  143. data/lib/nokogiri.rb +22 -27
  144. data/lib/xsd/xmlparser/nokogiri.rb +28 -25
  145. data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
  146. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
  147. data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
  148. data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
  149. metadata +20 -171
  150. data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
  151. data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
  152. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -2511
  153. data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
  154. data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
  155. data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
  156. data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -5,13 +5,8 @@ VALUE cNokogiriHtml4SaxParserContext ;
5
5
  static void
6
6
  deallocate(xmlParserCtxtPtr ctxt)
7
7
  {
8
- NOKOGIRI_DEBUG_START(ctxt);
9
-
10
8
  ctxt->sax = NULL;
11
-
12
9
  htmlFreeParserCtxt(ctxt);
13
-
14
- NOKOGIRI_DEBUG_END(ctxt);
15
10
  }
16
11
 
17
12
  static VALUE
@@ -19,9 +14,8 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
19
14
  {
20
15
  htmlParserCtxtPtr ctxt;
21
16
 
22
- if (NIL_P(data)) {
23
- rb_raise(rb_eArgError, "data cannot be nil");
24
- }
17
+ Check_Type(data, T_STRING);
18
+
25
19
  if (!(int)RSTRING_LEN(data)) {
26
20
  rb_raise(rb_eRuntimeError, "data cannot be empty");
27
21
  }
@@ -107,7 +101,7 @@ parse_with(VALUE self, VALUE sax_handler)
107
101
  }
108
102
 
109
103
  void
110
- noko_init_html_sax_parser_context()
104
+ noko_init_html_sax_parser_context(void)
111
105
  {
112
106
  assert(cNokogiriXmlSaxParserContext);
113
107
  cNokogiriHtml4SaxParserContext = rb_define_class_under(mNokogiriHtml4Sax, "ParserContext",
@@ -85,7 +85,7 @@ initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
85
85
  }
86
86
 
87
87
  void
88
- noko_init_html_sax_push_parser()
88
+ noko_init_html_sax_push_parser(void)
89
89
  {
90
90
  assert(cNokogiriXmlSaxPushParser);
91
91
  cNokogiriHtml4SaxPushParser = rb_define_class_under(mNokogiriHtml4Sax, "PushParser", cNokogiriXmlSaxPushParser);
@@ -49,34 +49,11 @@ void noko_init_html_sax_push_parser(void);
49
49
  void noko_init_gumbo(void);
50
50
  void noko_init_test_global_handlers(void);
51
51
 
52
- static ID id_read, id_write;
53
-
54
-
55
- #ifndef HAVE_VASPRINTF
56
- /*
57
- * Thank you Geoffroy Couprie for this implementation of vasprintf!
58
- */
59
- int
60
- vasprintf(char **strp, const char *fmt, va_list ap)
61
- {
62
- /* Mingw32/64 have a broken vsnprintf implementation that fails when
63
- * using a zero-byte limit in order to retrieve the required size for malloc.
64
- * So we use a one byte buffer instead.
65
- */
66
- char tmp[1];
67
- int len = vsnprintf(tmp, 1, fmt, ap) + 1;
68
- char *res = (char *)malloc((unsigned int)len);
69
- if (res == NULL) {
70
- return -1;
71
- }
72
- *strp = res;
73
- return vsnprintf(res, (unsigned int)len, fmt, ap);
74
- }
75
- #endif
52
+ static ID id_read, id_write, id_external_encoding;
76
53
 
77
54
 
78
55
  static VALUE
79
- read_check(VALUE val)
56
+ noko_io_read_check(VALUE val)
80
57
  {
81
58
  VALUE *args = (VALUE *)val;
82
59
  return rb_funcall(args[0], id_read, 1, args[1]);
@@ -84,75 +61,84 @@ read_check(VALUE val)
84
61
 
85
62
 
86
63
  static VALUE
87
- read_failed(VALUE arg, VALUE exc)
64
+ noko_io_read_failed(VALUE arg, VALUE exc)
88
65
  {
89
66
  return Qundef;
90
67
  }
91
68
 
92
69
 
93
70
  int
94
- noko_io_read(void *ctx, char *buffer, int len)
71
+ noko_io_read(void *io, char *c_buffer, int c_buffer_len)
95
72
  {
96
- VALUE string, args[2];
97
- size_t str_len, safe_len;
73
+ VALUE rb_io = (VALUE)io;
74
+ VALUE rb_read_string, rb_args[2];
75
+ size_t n_bytes_read, safe_len;
98
76
 
99
- args[0] = (VALUE)ctx;
100
- args[1] = INT2NUM(len);
77
+ rb_args[0] = rb_io;
78
+ rb_args[1] = INT2NUM(c_buffer_len);
101
79
 
102
- string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
80
+ rb_read_string = rb_rescue(noko_io_read_check, (VALUE)rb_args, noko_io_read_failed, 0);
103
81
 
104
- if (NIL_P(string)) { return 0; }
105
- if (string == Qundef) { return -1; }
106
- if (TYPE(string) != T_STRING) { return -1; }
82
+ if (NIL_P(rb_read_string)) { return 0; }
83
+ if (rb_read_string == Qundef) { return -1; }
84
+ if (TYPE(rb_read_string) != T_STRING) { return -1; }
107
85
 
108
- str_len = (size_t)RSTRING_LEN(string);
109
- safe_len = str_len > (size_t)len ? (size_t)len : str_len;
110
- memcpy(buffer, StringValuePtr(string), safe_len);
86
+ n_bytes_read = (size_t)RSTRING_LEN(rb_read_string);
87
+ safe_len = (n_bytes_read > (size_t)c_buffer_len) ? (size_t)c_buffer_len : n_bytes_read;
88
+ memcpy(c_buffer, StringValuePtr(rb_read_string), safe_len);
111
89
 
112
90
  return (int)safe_len;
113
91
  }
114
92
 
115
93
 
116
94
  static VALUE
117
- write_check(VALUE val)
95
+ noko_io_write_check(VALUE rb_args)
118
96
  {
119
- VALUE *args = (VALUE *)val;
120
- return rb_funcall(args[0], id_write, 1, args[1]);
97
+ VALUE rb_io = ((VALUE *)rb_args)[0];
98
+ VALUE rb_output = ((VALUE *)rb_args)[1];
99
+ return rb_funcall(rb_io, id_write, 1, rb_output);
121
100
  }
122
101
 
123
102
 
124
103
  static VALUE
125
- write_failed(VALUE arg, VALUE exc)
104
+ noko_io_write_failed(VALUE arg, VALUE exc)
126
105
  {
127
106
  return Qundef;
128
107
  }
129
108
 
130
109
 
131
110
  int
132
- noko_io_write(void *ctx, char *buffer, int len)
111
+ noko_io_write(void *io, char *c_buffer, int c_buffer_len)
133
112
  {
134
- VALUE args[2], size;
113
+ VALUE rb_args[2], rb_n_bytes_written;
114
+ VALUE rb_io = (VALUE)io;
115
+ VALUE rb_enc = Qnil;
116
+ rb_encoding *io_encoding;
135
117
 
136
- args[0] = (VALUE)ctx;
137
- args[1] = rb_str_new(buffer, (long)len);
118
+ if (rb_respond_to(rb_io, id_external_encoding)) {
119
+ rb_enc = rb_funcall(rb_io, id_external_encoding, 0);
120
+ }
121
+ io_encoding = RB_NIL_P(rb_enc) ? rb_ascii8bit_encoding() : rb_to_encoding(rb_enc);
138
122
 
139
- size = rb_rescue(write_check, (VALUE)args, write_failed, 0);
123
+ rb_args[0] = rb_io;
124
+ rb_args[1] = rb_enc_str_new(c_buffer, (long)c_buffer_len, io_encoding);
140
125
 
141
- if (size == Qundef) { return -1; }
126
+ rb_n_bytes_written = rb_rescue(noko_io_write_check, (VALUE)rb_args, noko_io_write_failed, 0);
127
+ if (rb_n_bytes_written == Qundef) { return -1; }
142
128
 
143
- return NUM2INT(size);
129
+ return NUM2INT(rb_n_bytes_written);
144
130
  }
145
131
 
146
132
 
147
133
  int
148
- noko_io_close(void *ctx)
134
+ noko_io_close(void *io)
149
135
  {
150
136
  return 0;
151
137
  }
152
138
 
153
139
 
154
140
  void
155
- Init_nokogiri()
141
+ Init_nokogiri(void)
156
142
  {
157
143
  mNokogiri = rb_define_module("Nokogiri");
158
144
  mNokogiriGumbo = rb_define_module_under(mNokogiri, "Gumbo");
@@ -275,4 +261,5 @@ Init_nokogiri()
275
261
 
276
262
  id_read = rb_intern("read");
277
263
  id_write = rb_intern("write");
264
+ id_external_encoding = rb_intern("external_encoding");
278
265
  }
@@ -1,6 +1,8 @@
1
1
  #ifndef NOKOGIRI_NATIVE
2
2
  #define NOKOGIRI_NATIVE
3
3
 
4
+ #include <ruby/defines.h> // https://github.com/sparklemotion/nokogiri/issues/2696
5
+
4
6
  #ifdef _MSC_VER
5
7
  # ifndef WIN32_LEAN_AND_MEAN
6
8
  # define WIN32_LEAN_AND_MEAN
@@ -23,7 +25,6 @@
23
25
  # define NOKOPUBVAR extern
24
26
  #endif
25
27
 
26
-
27
28
  #include <stdlib.h>
28
29
  #include <string.h>
29
30
  #include <assert.h>
@@ -75,22 +76,25 @@ xmlNodePtr xmlLastElementChild(xmlNodePtr parent);
75
76
  #define NOKOGIRI_STR_NEW(str, len) rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
76
77
  #define RBSTR_OR_QNIL(_str) (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
77
78
 
78
- #ifdef DEBUG
79
- # define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
80
- # define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
81
- #else
82
- # define NOKOGIRI_DEBUG_START(p)
83
- # define NOKOGIRI_DEBUG_END(p)
79
+ #ifndef NORETURN_DECL
80
+ # if defined(__GNUC__)
81
+ # define NORETURN_DECL __attribute__ ((noreturn))
82
+ # else
83
+ # define NORETURN_DECL
84
+ # endif
84
85
  #endif
85
86
 
86
- #ifndef NORETURN
87
+ #ifndef PRINTFLIKE_DECL
87
88
  # if defined(__GNUC__)
88
- # define NORETURN(name) __attribute__((noreturn)) name
89
+ # define PRINTFLIKE_DECL(stringidx, argidx) __attribute__ ((format(printf,stringidx,argidx)))
89
90
  # else
90
- # define NORETURN(name) name
91
+ # define PRINTFLIKE_DECL(stringidx, argidx)
91
92
  # endif
92
93
  #endif
93
94
 
95
+ #if defined(TRUFFLERUBY) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
96
+ # define TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
97
+ #endif
94
98
 
95
99
  NOKOPUBVAR VALUE mNokogiri ;
96
100
  NOKOPUBVAR VALUE mNokogiriGumbo ;
@@ -162,7 +166,6 @@ typedef struct _nokogiriXsltStylesheetTuple {
162
166
  VALUE func_instances;
163
167
  } nokogiriXsltStylesheetTuple;
164
168
 
165
- int vasprintf(char **strp, const char *fmt, va_list ap);
166
169
  void noko_xml_document_pin_node(xmlNodePtr);
167
170
  void noko_xml_document_pin_namespace(xmlNsPtr, xmlDocPtr);
168
171
 
@@ -170,6 +173,9 @@ int noko_io_read(void *ctx, char *buffer, int len);
170
173
  int noko_io_write(void *ctx, char *buffer, int len);
171
174
  int noko_io_close(void *ctx);
172
175
 
176
+ #define Noko_Node_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
177
+ #define Noko_Namespace_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
178
+
173
179
  VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
174
180
  VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
175
181
  VALUE noko_xml_node_attrs(xmlNodePtr node) ;
@@ -195,18 +201,24 @@ NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
195
201
  #define NOKOGIRI_SAX_SELF(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->self
196
202
  #define NOKOGIRI_SAX_CTXT(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->ctxt
197
203
  #define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) nokogiri_sax_tuple_new(_ctxt, _self)
198
- #define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) free(_tuple)
204
+ #define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) ruby_xfree(_tuple)
199
205
 
200
206
  #define DISCARD_CONST_QUAL(t, v) ((t)(uintptr_t)(v))
201
207
  #define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
202
208
 
209
+ #if HAVE_RB_CATEGORY_WARNING
210
+ # define NOKO_WARN_DEPRECATION(message) rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, message)
211
+ #else
212
+ # define NOKO_WARN_DEPRECATION(message) rb_warning(message)
213
+ #endif
214
+
203
215
  void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
204
216
  void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
205
217
  xmlStructuredErrorFunc handler);
206
218
  void Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
207
219
  VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
208
220
  void Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error);
209
- NORETURN(void Nokogiri_error_raise(void *ctx, xmlErrorPtr error));
221
+ NORETURN_DECL void Nokogiri_error_raise(void *ctx, xmlErrorPtr error);
210
222
  void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
211
223
  const char *function_name) ;
212
224
 
@@ -214,7 +226,7 @@ static inline
214
226
  nokogiriSAXTuplePtr
215
227
  nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
216
228
  {
217
- nokogiriSAXTuplePtr tuple = malloc(sizeof(nokogiriSAXTuple));
229
+ nokogiriSAXTuplePtr tuple = ruby_xmalloc(sizeof(nokogiriSAXTuple));
218
230
  tuple->self = self;
219
231
  tuple->ctxt = ctxt;
220
232
  return tuple;
@@ -32,7 +32,7 @@ rb_foreign_error_handler(VALUE klass)
32
32
  * Do NOT use this outside of the Nokogiri test suite.
33
33
  */
34
34
  void
35
- noko_init_test_global_handlers()
35
+ noko_init_test_global_handlers(void)
36
36
  {
37
37
  VALUE mNokogiriTest = rb_define_module_under(mNokogiri, "Test");
38
38
 
@@ -16,7 +16,7 @@ set_value(VALUE self, VALUE content)
16
16
  xmlChar *value;
17
17
  xmlNode *cur;
18
18
 
19
- Data_Get_Struct(self, xmlAttr, attr);
19
+ Noko_Node_Get_Struct(self, xmlAttr, attr);
20
20
 
21
21
  if (attr->children) {
22
22
  xmlFreeNodeList(attr->children);
@@ -68,7 +68,7 @@ new (int argc, VALUE *argv, VALUE klass)
68
68
  rb_raise(rb_eArgError, "parameter must be a Nokogiri::XML::Document");
69
69
  }
70
70
 
71
- Data_Get_Struct(document, xmlDoc, xml_doc);
71
+ Noko_Node_Get_Struct(document, xmlDoc, xml_doc);
72
72
 
73
73
  node = xmlNewDocProp(
74
74
  xml_doc,
@@ -89,7 +89,7 @@ new (int argc, VALUE *argv, VALUE klass)
89
89
  }
90
90
 
91
91
  void
92
- noko_init_xml_attr()
92
+ noko_init_xml_attr(void)
93
93
  {
94
94
  assert(cNokogiriXmlNode);
95
95
  /*
@@ -12,8 +12,8 @@ static VALUE
12
12
  attribute_type(VALUE self)
13
13
  {
14
14
  xmlAttributePtr node;
15
- Data_Get_Struct(self, xmlAttribute, node);
16
- return INT2NUM((long)node->atype);
15
+ Noko_Node_Get_Struct(self, xmlAttribute, node);
16
+ return INT2NUM(node->atype);
17
17
  }
18
18
 
19
19
  /*
@@ -26,7 +26,7 @@ static VALUE
26
26
  default_value(VALUE self)
27
27
  {
28
28
  xmlAttributePtr node;
29
- Data_Get_Struct(self, xmlAttribute, node);
29
+ Noko_Node_Get_Struct(self, xmlAttribute, node);
30
30
 
31
31
  if (node->defaultValue) { return NOKOGIRI_STR_NEW2(node->defaultValue); }
32
32
  return Qnil;
@@ -45,7 +45,7 @@ enumeration(VALUE self)
45
45
  xmlEnumerationPtr enm;
46
46
  VALUE list;
47
47
 
48
- Data_Get_Struct(self, xmlAttribute, node);
48
+ Noko_Node_Get_Struct(self, xmlAttribute, node);
49
49
 
50
50
  list = rb_ary_new();
51
51
  enm = node->tree;
@@ -59,7 +59,7 @@ enumeration(VALUE self)
59
59
  }
60
60
 
61
61
  void
62
- noko_init_xml_attribute_decl()
62
+ noko_init_xml_attribute_decl(void)
63
63
  {
64
64
  assert(cNokogiriXmlNode);
65
65
  cNokogiriXmlAttributeDecl = rb_define_class_under(mNokogiriXml, "AttributeDecl", cNokogiriXmlNode);
@@ -25,11 +25,11 @@ new (int argc, VALUE *argv, VALUE klass)
25
25
 
26
26
  rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
27
27
 
28
- Data_Get_Struct(doc, xmlDoc, xml_doc);
28
+ Noko_Node_Get_Struct(doc, xmlDoc, xml_doc);
29
29
 
30
30
  if (!NIL_P(content)) {
31
31
  content_str = (xmlChar *)StringValuePtr(content);
32
- content_str_len = RSTRING_LEN(content);
32
+ content_str_len = RSTRING_LENINT(content);
33
33
  }
34
34
 
35
35
  node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);
@@ -45,7 +45,7 @@ new (int argc, VALUE *argv, VALUE klass)
45
45
  }
46
46
 
47
47
  void
48
- noko_init_xml_cdata()
48
+ noko_init_xml_cdata(void)
49
49
  {
50
50
  assert(cNokogiriXmlText);
51
51
  /*
@@ -48,7 +48,7 @@ new (int argc, VALUE *argv, VALUE klass)
48
48
  }
49
49
 
50
50
  void
51
- noko_init_xml_comment()
51
+ noko_init_xml_comment(void)
52
52
  {
53
53
  assert(cNokogiriXmlCharacterData);
54
54
  /*
@@ -65,14 +65,12 @@ dealloc(xmlDocPtr doc)
65
65
  {
66
66
  st_table *node_hash;
67
67
 
68
- NOKOGIRI_DEBUG_START(doc);
69
-
70
68
  node_hash = DOC_UNLINKED_NODE_HASH(doc);
71
69
 
72
70
  st_foreach(node_hash, dealloc_node_i, (st_data_t)doc);
73
71
  st_free_table(node_hash);
74
72
 
75
- free(doc->_private);
73
+ ruby_xfree(doc->_private);
76
74
 
77
75
  /* When both Nokogiri and libxml-ruby are loaded, make sure that all nodes
78
76
  * have their _private pointers cleared. This is to avoid libxml-ruby's
@@ -84,8 +82,6 @@ dealloc(xmlDocPtr doc)
84
82
  }
85
83
 
86
84
  xmlFreeDoc(doc);
87
-
88
- NOKOGIRI_DEBUG_END(doc);
89
85
  }
90
86
 
91
87
  static void
@@ -104,7 +100,11 @@ recursively_remove_namespaces_from_node(xmlNodePtr node)
104
100
  (node->type == XML_XINCLUDE_START) ||
105
101
  (node->type == XML_XINCLUDE_END)) &&
106
102
  node->nsDef) {
107
- xmlFreeNsList(node->nsDef);
103
+ xmlNsPtr curr = node->nsDef;
104
+ while (curr) {
105
+ noko_xml_document_pin_namespace(curr, node->doc);
106
+ curr = curr->next;
107
+ }
108
108
  node->nsDef = NULL;
109
109
  }
110
110
 
@@ -161,7 +161,7 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
161
161
  rb_obj_class(rb_new_root));
162
162
  }
163
163
 
164
- Data_Get_Struct(rb_new_root, xmlNode, c_new_root);
164
+ Noko_Node_Get_Struct(rb_new_root, xmlNode, c_new_root);
165
165
 
166
166
  /* If the new root's document is not the same as the current document,
167
167
  * then we need to dup the node in to this document. */
@@ -533,59 +533,68 @@ block_caller(void *ctx, xmlNodePtr c_node, xmlNodePtr c_parent_node)
533
533
  static VALUE
534
534
  rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
535
535
  {
536
- VALUE mode;
537
- VALUE incl_ns;
538
- VALUE with_comments;
539
- xmlChar **ns;
540
- long ns_len, i;
536
+ VALUE rb_mode;
537
+ VALUE rb_namespaces;
538
+ VALUE rb_comments_p;
539
+ int c_mode = 0;
540
+ xmlChar **c_namespaces;
541
541
 
542
- xmlDocPtr doc;
543
- xmlOutputBufferPtr buf;
544
- xmlC14NIsVisibleCallback cb = NULL;
545
- void *ctx = NULL;
542
+ xmlDocPtr c_doc;
543
+ xmlOutputBufferPtr c_obuf;
544
+ xmlC14NIsVisibleCallback c_callback_wrapper = NULL;
545
+ void *rb_callback = NULL;
546
546
 
547
547
  VALUE rb_cStringIO;
548
- VALUE io;
548
+ VALUE rb_io;
549
549
 
550
- rb_scan_args(argc, argv, "03", &mode, &incl_ns, &with_comments);
550
+ rb_scan_args(argc, argv, "03", &rb_mode, &rb_namespaces, &rb_comments_p);
551
+ if (!NIL_P(rb_mode)) {
552
+ Check_Type(rb_mode, T_FIXNUM);
553
+ c_mode = NUM2INT(rb_mode);
554
+ }
555
+ if (!NIL_P(rb_namespaces)) {
556
+ Check_Type(rb_namespaces, T_ARRAY);
557
+ if (c_mode == XML_C14N_1_0 || c_mode == XML_C14N_1_1) {
558
+ rb_raise(rb_eRuntimeError, "This canonicalizer does not support this operation");
559
+ }
560
+ }
551
561
 
552
- Data_Get_Struct(self, xmlDoc, doc);
562
+ Data_Get_Struct(self, xmlDoc, c_doc);
553
563
 
554
564
  rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
555
- io = rb_class_new_instance(0, 0, rb_cStringIO);
556
- buf = xmlAllocOutputBuffer(NULL);
565
+ rb_io = rb_class_new_instance(0, 0, rb_cStringIO);
566
+ c_obuf = xmlAllocOutputBuffer(NULL);
557
567
 
558
- buf->writecallback = (xmlOutputWriteCallback)noko_io_write;
559
- buf->closecallback = (xmlOutputCloseCallback)noko_io_close;
560
- buf->context = (void *)io;
568
+ c_obuf->writecallback = (xmlOutputWriteCallback)noko_io_write;
569
+ c_obuf->closecallback = (xmlOutputCloseCallback)noko_io_close;
570
+ c_obuf->context = (void *)rb_io;
561
571
 
562
572
  if (rb_block_given_p()) {
563
- cb = block_caller;
564
- ctx = (void *)rb_block_proc();
573
+ c_callback_wrapper = block_caller;
574
+ rb_callback = (void *)rb_block_proc();
565
575
  }
566
576
 
567
- if (NIL_P(incl_ns)) {
568
- ns = NULL;
577
+ if (NIL_P(rb_namespaces)) {
578
+ c_namespaces = NULL;
569
579
  } else {
570
- Check_Type(incl_ns, T_ARRAY);
571
- ns_len = RARRAY_LEN(incl_ns);
572
- ns = calloc((size_t)ns_len + 1, sizeof(xmlChar *));
573
- for (i = 0 ; i < ns_len ; i++) {
574
- VALUE entry = rb_ary_entry(incl_ns, i);
575
- ns[i] = (xmlChar *)StringValueCStr(entry);
580
+ long ns_len = RARRAY_LEN(rb_namespaces);
581
+ c_namespaces = ruby_xcalloc((size_t)ns_len + 1, sizeof(xmlChar *));
582
+ for (int j = 0 ; j < ns_len ; j++) {
583
+ VALUE entry = rb_ary_entry(rb_namespaces, j);
584
+ c_namespaces[j] = (xmlChar *)StringValueCStr(entry);
576
585
  }
577
586
  }
578
587
 
588
+ xmlC14NExecute(c_doc, c_callback_wrapper, rb_callback,
589
+ c_mode,
590
+ c_namespaces,
591
+ (int)RTEST(rb_comments_p),
592
+ c_obuf);
579
593
 
580
- xmlC14NExecute(doc, cb, ctx,
581
- (int)(NIL_P(mode) ? 0 : NUM2INT(mode)),
582
- ns,
583
- (int) RTEST(with_comments),
584
- buf);
585
-
586
- xmlOutputBufferClose(buf);
594
+ ruby_xfree(c_namespaces);
595
+ xmlOutputBufferClose(c_obuf);
587
596
 
588
- return rb_funcall(io, rb_intern("string"), 0);
597
+ return rb_funcall(rb_io, rb_intern("string"), 0);
589
598
  }
590
599
 
591
600
  VALUE
@@ -600,7 +609,7 @@ noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int arg
600
609
 
601
610
  rb_document = Data_Wrap_Struct(klass, mark, dealloc, c_document);
602
611
 
603
- tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
612
+ tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
604
613
  tuple->doc = rb_document;
605
614
  tuple->unlinkedNodes = st_init_numtable_with_size(128);
606
615
  tuple->node_cache = rb_ary_new();
@@ -655,7 +664,7 @@ noko_xml_document_pin_namespace(xmlNsPtr ns, xmlDocPtr doc)
655
664
 
656
665
 
657
666
  void
658
- noko_init_xml_document()
667
+ noko_init_xml_document(void)
659
668
  {
660
669
  assert(cNokogiriXmlNode);
661
670
  /*
@@ -28,13 +28,11 @@ new (int argc, VALUE *argv, VALUE klass)
28
28
  rb_node = noko_xml_node_wrap(klass, node);
29
29
  rb_obj_call_init(rb_node, argc, argv);
30
30
 
31
- if (rb_block_given_p()) { rb_yield(rb_node); }
32
-
33
31
  return rb_node;
34
32
  }
35
33
 
36
34
  void
37
- noko_init_xml_document_fragment()
35
+ noko_init_xml_document_fragment(void)
38
36
  {
39
37
  assert(cNokogiriXmlNode);
40
38
  /*
@@ -44,7 +44,7 @@ entities(VALUE self)
44
44
  xmlDtdPtr dtd;
45
45
  VALUE hash;
46
46
 
47
- Data_Get_Struct(self, xmlDtd, dtd);
47
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
48
48
 
49
49
  if (!dtd->entities) { return Qnil; }
50
50
 
@@ -57,9 +57,9 @@ entities(VALUE self)
57
57
 
58
58
  /*
59
59
  * call-seq:
60
- * notations
60
+ * notations() → Hash<name(String)⇒Notation>
61
61
  *
62
- * Get a hash of the notations for this DTD.
62
+ * [Returns] All the notations for this DTD in a Hash of Notation +name+ to Notation.
63
63
  */
64
64
  static VALUE
65
65
  notations(VALUE self)
@@ -67,7 +67,7 @@ notations(VALUE self)
67
67
  xmlDtdPtr dtd;
68
68
  VALUE hash;
69
69
 
70
- Data_Get_Struct(self, xmlDtd, dtd);
70
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
71
71
 
72
72
  if (!dtd->notations) { return Qnil; }
73
73
 
@@ -90,7 +90,7 @@ attributes(VALUE self)
90
90
  xmlDtdPtr dtd;
91
91
  VALUE hash;
92
92
 
93
- Data_Get_Struct(self, xmlDtd, dtd);
93
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
94
94
 
95
95
  hash = rb_hash_new();
96
96
 
@@ -113,7 +113,7 @@ elements(VALUE self)
113
113
  xmlDtdPtr dtd;
114
114
  VALUE hash;
115
115
 
116
- Data_Get_Struct(self, xmlDtd, dtd);
116
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
117
117
 
118
118
  if (!dtd->elements) { return Qnil; }
119
119
 
@@ -138,8 +138,8 @@ validate(VALUE self, VALUE document)
138
138
  xmlValidCtxtPtr ctxt;
139
139
  VALUE error_list;
140
140
 
141
- Data_Get_Struct(self, xmlDtd, dtd);
142
- Data_Get_Struct(document, xmlDoc, doc);
141
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
142
+ Noko_Node_Get_Struct(document, xmlDoc, doc);
143
143
  error_list = rb_ary_new();
144
144
 
145
145
  ctxt = xmlNewValidCtxt();
@@ -165,7 +165,7 @@ static VALUE
165
165
  system_id(VALUE self)
166
166
  {
167
167
  xmlDtdPtr dtd;
168
- Data_Get_Struct(self, xmlDtd, dtd);
168
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
169
169
 
170
170
  if (!dtd->SystemID) { return Qnil; }
171
171
 
@@ -182,7 +182,7 @@ static VALUE
182
182
  external_id(VALUE self)
183
183
  {
184
184
  xmlDtdPtr dtd;
185
- Data_Get_Struct(self, xmlDtd, dtd);
185
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
186
186
 
187
187
  if (!dtd->ExternalID) { return Qnil; }
188
188
 
@@ -190,7 +190,7 @@ external_id(VALUE self)
190
190
  }
191
191
 
192
192
  void
193
- noko_init_xml_dtd()
193
+ noko_init_xml_dtd(void)
194
194
  {
195
195
  assert(cNokogiriXmlNode);
196
196
  /*