nokogiri 1.4.0-java → 1.4.1-java

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 (75) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +5 -6
  3. data/CHANGELOG.ja.rdoc +47 -11
  4. data/CHANGELOG.rdoc +31 -0
  5. data/Manifest.txt +8 -1
  6. data/README.ja.rdoc +4 -3
  7. data/README.rdoc +9 -1
  8. data/Rakefile +4 -0
  9. data/deps.rip +5 -0
  10. data/ext/nokogiri/extconf.rb +4 -0
  11. data/ext/nokogiri/html_element_description.c +1 -1
  12. data/ext/nokogiri/nokogiri.c +7 -0
  13. data/ext/nokogiri/nokogiri.h +4 -1
  14. data/ext/nokogiri/xml_document.c +3 -5
  15. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  16. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  17. data/ext/nokogiri/xml_namespace.c +8 -0
  18. data/ext/nokogiri/xml_namespace.h +1 -0
  19. data/ext/nokogiri/xml_node.c +61 -41
  20. data/ext/nokogiri/xml_node_set.c +22 -14
  21. data/ext/nokogiri/xml_sax_parser.c +0 -3
  22. data/ext/nokogiri/xml_sax_parser_context.c +2 -0
  23. data/ext/nokogiri/xml_sax_push_parser.c +26 -3
  24. data/ext/nokogiri/xml_syntax_error.c +18 -227
  25. data/lib/nokogiri/css/generated_parser.rb +173 -160
  26. data/lib/nokogiri/css/generated_tokenizer.rb +5 -1
  27. data/lib/nokogiri/css/parser.y +4 -1
  28. data/lib/nokogiri/css/tokenizer.rex +2 -1
  29. data/lib/nokogiri/css/xpath_visitor.rb +2 -0
  30. data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
  31. data/lib/nokogiri/ffi/html/element_description.rb +5 -9
  32. data/lib/nokogiri/ffi/libxml.rb +21 -5
  33. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
  34. data/lib/nokogiri/ffi/structs/xml_document.rb +3 -3
  35. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +110 -1
  36. data/lib/nokogiri/ffi/xml/dtd.rb +2 -4
  37. data/lib/nokogiri/ffi/xml/node.rb +38 -17
  38. data/lib/nokogiri/ffi/xml/node_set.rb +21 -8
  39. data/lib/nokogiri/ffi/xml/reader.rb +1 -1
  40. data/lib/nokogiri/ffi/xml/sax/parser.rb +1 -8
  41. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +16 -4
  42. data/lib/nokogiri/ffi/xml/syntax_error.rb +9 -2
  43. data/lib/nokogiri/ffi/xslt/stylesheet.rb +12 -9
  44. data/lib/nokogiri/version.rb +1 -1
  45. data/lib/nokogiri/xml/builder.rb +1 -1
  46. data/lib/nokogiri/xml/document.rb +35 -4
  47. data/lib/nokogiri/xml/document_fragment.rb +5 -1
  48. data/lib/nokogiri/xml/fragment_handler.rb +28 -20
  49. data/lib/nokogiri/xml/node.rb +84 -13
  50. data/lib/nokogiri/xml/node_set.rb +19 -2
  51. data/lib/nokogiri/xml/sax/push_parser.rb +1 -1
  52. data/lib/nokogiri/xml/syntax_error.rb +10 -5
  53. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  54. data/lib/xsd/xmlparser/nokogiri.rb +20 -1
  55. data/test/css/test_parser.rb +5 -0
  56. data/test/css/test_tokenizer.rb +7 -0
  57. data/test/helper.rb +0 -5
  58. data/test/html/test_document_fragment.rb +39 -1
  59. data/test/html/test_node.rb +14 -0
  60. data/test/test_encoding_handler.rb +46 -0
  61. data/test/test_memory_leak.rb +10 -0
  62. data/test/test_nokogiri.rb +5 -1
  63. data/test/test_soap4r_sax.rb +52 -0
  64. data/test/test_xslt_transforms.rb +69 -26
  65. data/test/xml/sax/test_parser_context.rb +7 -0
  66. data/test/xml/sax/test_push_parser.rb +33 -0
  67. data/test/xml/test_document.rb +27 -1
  68. data/test/xml/test_document_fragment.rb +6 -0
  69. data/test/xml/test_node.rb +63 -214
  70. data/test/xml/test_node_reparenting.rb +261 -0
  71. data/test/xml/test_node_set.rb +51 -0
  72. data/test/xml/test_syntax_error.rb +0 -15
  73. metadata +82 -52
  74. metadata.gz.sig +0 -0
  75. data/test/test_gc.rb +0 -15
@@ -8,5 +8,6 @@ void init_xml_namespace();
8
8
  extern VALUE cNokogiriXmlNamespace ;
9
9
 
10
10
  VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node) ;
11
+ VALUE Nokogiri_wrap_xml_namespace2(VALUE document, xmlNsPtr node) ;
11
12
 
12
13
  #endif
@@ -56,6 +56,17 @@ static void relink_namespace(xmlNodePtr reparented)
56
56
  }
57
57
  }
58
58
 
59
+ /* :nodoc: */
60
+ static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr old, xmlNodePtr cur)
61
+ {
62
+ xmlNodePtr retval ;
63
+ retval = xmlReplaceNode(old, cur) ;
64
+ if (retval == old) {
65
+ return cur ; // return semantics for reparent_node_with
66
+ }
67
+ return retval ;
68
+ }
69
+
59
70
  /* :nodoc: */
60
71
  static VALUE reparent_node_with(VALUE node_obj, VALUE other_obj, node_other_func func)
61
72
  {
@@ -71,17 +82,6 @@ static VALUE reparent_node_with(VALUE node_obj, VALUE other_obj, node_other_func
71
82
  if(XML_DOCUMENT_NODE == node->type || XML_HTML_DOCUMENT_NODE == node->type)
72
83
  rb_raise(rb_eArgError, "cannot reparent a document node");
73
84
 
74
- // If a document fragment is added, we need to reparent all of it's children
75
- if(node->type == XML_DOCUMENT_FRAG_NODE)
76
- {
77
- xmlNodePtr child = node->children;
78
- while(NULL != child) {
79
- reparent_node_with(Nokogiri_wrap_xml_node((VALUE)NULL, child), other_obj, func);
80
- child = child->next;
81
- }
82
- return node_obj;
83
- }
84
-
85
85
  if(node->type == XML_TEXT_NODE) {
86
86
  NOKOGIRI_ROOT_NODE(node);
87
87
  node = xmlDocCopyNode(node, other->doc, 1);
@@ -370,17 +370,50 @@ static VALUE previous_sibling(VALUE self)
370
370
  return Nokogiri_wrap_xml_node(Qnil, sibling);
371
371
  }
372
372
 
373
- /* :nodoc: */
374
- static VALUE replace(VALUE self, VALUE _new_node)
373
+ /*
374
+ * call-seq:
375
+ * next_element
376
+ *
377
+ * Returns the next Nokogiri::XML::Element type sibling node.
378
+ */
379
+ static VALUE next_element(VALUE self)
375
380
  {
376
- xmlNodePtr node, new_node;
381
+ xmlNodePtr node, sibling;
377
382
  Data_Get_Struct(self, xmlNode, node);
378
- Data_Get_Struct(_new_node, xmlNode, new_node);
379
383
 
380
- xmlReplaceNode(node, new_node);
384
+ sibling = node->next;
385
+ if(!sibling) return Qnil;
381
386
 
382
- // Appropriately link in namespaces
383
- relink_namespace(new_node);
387
+ while(sibling && sibling->type != XML_ELEMENT_NODE)
388
+ sibling = sibling->next;
389
+
390
+ return sibling ? Nokogiri_wrap_xml_node(Qnil, sibling) : Qnil ;
391
+ }
392
+
393
+ /*
394
+ * call-seq:
395
+ * previous_element
396
+ *
397
+ * Returns the previous Nokogiri::XML::Element type sibling node.
398
+ */
399
+ static VALUE previous_element(VALUE self)
400
+ {
401
+ xmlNodePtr node, sibling;
402
+ Data_Get_Struct(self, xmlNode, node);
403
+
404
+ sibling = node->prev;
405
+ if(!sibling) return Qnil;
406
+
407
+ while(sibling && sibling->type != XML_ELEMENT_NODE)
408
+ sibling = sibling->prev;
409
+
410
+ return sibling ? Nokogiri_wrap_xml_node(Qnil, sibling) : Qnil ;
411
+ }
412
+
413
+ /* :nodoc: */
414
+ static VALUE replace(VALUE self, VALUE _new_node)
415
+ {
416
+ reparent_node_with(_new_node, self, xmlReplaceNodeWrapper) ;
384
417
  return self ;
385
418
  }
386
419
 
@@ -667,12 +700,7 @@ static VALUE get_content(VALUE self)
667
700
  return Qnil;
668
701
  }
669
702
 
670
- /*
671
- * call-seq:
672
- * add_child(node)
673
- *
674
- * Add +node+ as a child of this node. Returns the new child node.
675
- */
703
+ /* :nodoc: */
676
704
  static VALUE add_child(VALUE self, VALUE child)
677
705
  {
678
706
  return reparent_node_with(child, self, xmlAddChild);
@@ -742,23 +770,13 @@ static VALUE path(VALUE self)
742
770
  return rval ;
743
771
  }
744
772
 
745
- /*
746
- * call-seq:
747
- * add_next_sibling(node)
748
- *
749
- * Insert +node+ after this node (as a sibling).
750
- */
773
+ /* :nodoc: */
751
774
  static VALUE add_next_sibling(VALUE self, VALUE rb_node)
752
775
  {
753
776
  return reparent_node_with(rb_node, self, xmlAddNextSibling) ;
754
777
  }
755
778
 
756
- /*
757
- * call-seq:
758
- * add_previous_sibling(node)
759
- *
760
- * Insert +node+ before this node (as a sibling).
761
- */
779
+ /* :nodoc: */
762
780
  static VALUE add_previous_sibling(VALUE self, VALUE rb_node)
763
781
  {
764
782
  return reparent_node_with(rb_node, self, xmlAddPrevSibling) ;
@@ -1017,12 +1035,13 @@ void init_xml_node()
1017
1035
  rb_define_method(klass, "node_name", get_name, 0);
1018
1036
  rb_define_method(klass, "document", document, 0);
1019
1037
  rb_define_method(klass, "node_name=", set_name, 1);
1020
- rb_define_method(klass, "add_child", add_child, 1);
1021
1038
  rb_define_method(klass, "parent", get_parent, 0);
1022
1039
  rb_define_method(klass, "child", child, 0);
1023
1040
  rb_define_method(klass, "children", children, 0);
1024
1041
  rb_define_method(klass, "next_sibling", next_sibling, 0);
1025
1042
  rb_define_method(klass, "previous_sibling", previous_sibling, 0);
1043
+ rb_define_method(klass, "next_element", next_element, 0);
1044
+ rb_define_method(klass, "previous_element", previous_element, 0);
1026
1045
  rb_define_method(klass, "node_type", node_type, 0);
1027
1046
  rb_define_method(klass, "content", get_content, 0);
1028
1047
  rb_define_method(klass, "path", path, 0);
@@ -1035,8 +1054,6 @@ void init_xml_node()
1035
1054
  rb_define_method(klass, "attribute_with_ns", attribute_with_ns, 2);
1036
1055
  rb_define_method(klass, "namespace", namespace, 0);
1037
1056
  rb_define_method(klass, "namespace_definitions", namespace_definitions, 0);
1038
- rb_define_method(klass, "add_previous_sibling", add_previous_sibling, 1);
1039
- rb_define_method(klass, "add_next_sibling", add_next_sibling, 1);
1040
1057
  rb_define_method(klass, "encode_special_chars", encode_special_chars, 1);
1041
1058
  rb_define_method(klass, "dup", duplicate_node, -1);
1042
1059
  rb_define_method(klass, "unlink", unlink_node, 0);
@@ -1047,14 +1064,17 @@ void init_xml_node()
1047
1064
  rb_define_method(klass, "pointer_id", pointer_id, 0);
1048
1065
  rb_define_method(klass, "line", line, 0);
1049
1066
 
1067
+ rb_define_private_method(klass, "add_child_node", add_child, 1);
1068
+ rb_define_private_method(klass, "add_previous_sibling_node", add_previous_sibling, 1);
1069
+ rb_define_private_method(klass, "add_next_sibling_node", add_next_sibling, 1);
1070
+ rb_define_private_method(klass, "replace_node", replace, 1);
1050
1071
  rb_define_private_method(klass, "dump_html", dump_html, 0);
1051
1072
  rb_define_private_method(klass, "native_write_to", native_write_to, 4);
1052
- rb_define_private_method(klass, "replace_with_node", replace, 1);
1053
1073
  rb_define_private_method(klass, "native_content=", set_content, 1);
1054
1074
  rb_define_private_method(klass, "get", get, 1);
1055
1075
  rb_define_private_method(klass, "set_namespace", set_namespace, 1);
1056
1076
  rb_define_private_method(klass, "compare", compare, 1);
1057
1077
 
1058
- decorate = rb_intern("decorate");
1078
+ decorate = rb_intern("decorate");
1059
1079
  decorate_bang = rb_intern("decorate!");
1060
1080
  }
@@ -189,6 +189,8 @@ static VALUE index_at(VALUE self, long offset)
189
189
  if(offset >= node_set->nodeNr || abs(offset) > node_set->nodeNr) return Qnil;
190
190
  if(offset < 0) offset = offset + node_set->nodeNr;
191
191
 
192
+ if (XML_NAMESPACE_DECL == node_set->nodeTab[offset]->type)
193
+ return Nokogiri_wrap_xml_namespace2(rb_iv_get(self, "@document"), (xmlNsPtr)(node_set->nodeTab[offset]));
192
194
  return Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[offset]);
193
195
  }
194
196
 
@@ -280,15 +282,19 @@ static VALUE to_array(VALUE self, VALUE rb_node)
280
282
  VALUE *elts = calloc((size_t)set->nodeNr, sizeof(VALUE *));
281
283
  int i;
282
284
  for(i = 0; i < set->nodeNr; i++) {
283
- xmlNodePtr node = set->nodeTab[i];
284
-
285
- if(node->_private) {
286
- if(node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE)
287
- elts[i] = DOC_RUBY_OBJECT(node->doc);
288
- else
289
- elts[i] = (VALUE)node->_private;
285
+ if (XML_NAMESPACE_DECL == set->nodeTab[i]->type) {
286
+ elts[i] = Nokogiri_wrap_xml_namespace2(rb_iv_get(self, "@document"), (xmlNsPtr)(set->nodeTab[i]));
290
287
  } else {
291
- elts[i] = Nokogiri_wrap_xml_node(Qnil, node);
288
+ xmlNodePtr node = set->nodeTab[i];
289
+
290
+ if(node->_private) {
291
+ if(node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE)
292
+ elts[i] = DOC_RUBY_OBJECT(node->doc);
293
+ else
294
+ elts[i] = (VALUE)node->_private;
295
+ } else {
296
+ elts[i] = Nokogiri_wrap_xml_node(Qnil, node);
297
+ }
292
298
  }
293
299
  }
294
300
 
@@ -313,12 +319,14 @@ static VALUE unlink_nodeset(VALUE self)
313
319
  Data_Get_Struct(self, xmlNodeSet, node_set);
314
320
  nodeNr = node_set->nodeNr ;
315
321
  for (j = 0 ; j < nodeNr ; j++) {
316
- VALUE node ;
317
- xmlNodePtr node_ptr;
318
- node = Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[j]);
319
- rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
320
- Data_Get_Struct(node, xmlNode, node_ptr);
321
- node_set->nodeTab[j] = node_ptr ;
322
+ if (XML_NAMESPACE_DECL != node_set->nodeTab[j]->type) {
323
+ VALUE node ;
324
+ xmlNodePtr node_ptr;
325
+ node = Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[j]);
326
+ rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
327
+ Data_Get_Struct(node, xmlNode, node_ptr);
328
+ node_set->nodeTab[j] = node_ptr ;
329
+ }
322
330
  }
323
331
  return self ;
324
332
  }
@@ -8,9 +8,6 @@ static ID id_cdata_block, id_cAttribute;
8
8
  #define STRING_OR_NULL(str) \
9
9
  (RTEST(str) ? StringValuePtr(str) : NULL)
10
10
 
11
- #define RBSTR_OR_QNIL(_str) \
12
- (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
13
-
14
11
  static void start_document(void * ctx)
15
12
  {
16
13
  VALUE self = NOKOGIRI_SAX_SELF(ctx);
@@ -96,6 +96,8 @@ static VALUE parse_with(VALUE self, VALUE sax_handler)
96
96
  if(NULL != ctxt->myDoc) xmlFreeDoc(ctxt->myDoc);
97
97
 
98
98
  NOKOGIRI_SAX_TUPLE_DESTROY(ctxt->userData);
99
+
100
+ return Qnil ;
99
101
  }
100
102
 
101
103
  /*
@@ -35,8 +35,10 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
35
35
  }
36
36
 
37
37
  if(xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
38
- xmlErrorPtr e = xmlCtxtGetLastError(ctx);
39
- Nokogiri_error_raise(NULL, e);
38
+ if (!(ctx->options & XML_PARSE_RECOVER)) {
39
+ xmlErrorPtr e = xmlCtxtGetLastError(ctx);
40
+ Nokogiri_error_raise(NULL, e);
41
+ }
40
42
  }
41
43
 
42
44
  return self;
@@ -53,7 +55,7 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
53
55
  xmlSAXHandlerPtr sax;
54
56
 
55
57
  Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
56
-
58
+
57
59
  const char * filename = NULL;
58
60
 
59
61
  if(_filename != Qnil) filename = StringValuePtr(_filename);
@@ -75,6 +77,25 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
75
77
  return self;
76
78
  }
77
79
 
80
+ static VALUE get_options(VALUE self)
81
+ {
82
+ xmlParserCtxtPtr ctx;
83
+ Data_Get_Struct(self, xmlParserCtxt, ctx);
84
+
85
+ return INT2NUM(ctx->options);
86
+ }
87
+
88
+ static VALUE set_options(VALUE self, VALUE options)
89
+ {
90
+ xmlParserCtxtPtr ctx;
91
+ Data_Get_Struct(self, xmlParserCtxt, ctx);
92
+
93
+ if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0)
94
+ rb_raise(rb_eRuntimeError, "Cannot set XML parser context options");
95
+
96
+ return Qnil;
97
+ }
98
+
78
99
  VALUE cNokogiriXmlSaxPushParser ;
79
100
  void init_xml_sax_push_parser()
80
101
  {
@@ -88,4 +109,6 @@ void init_xml_sax_push_parser()
88
109
  rb_define_alloc_func(klass, allocate);
89
110
  rb_define_private_method(klass, "initialize_native", initialize_native, 2);
90
111
  rb_define_private_method(klass, "native_write", native_write, 2);
112
+ rb_define_method(klass, "options", get_options, 0);
113
+ rb_define_method(klass, "options=", set_options, 1);
91
114
  }
@@ -1,214 +1,5 @@
1
1
  #include <xml_syntax_error.h>
2
2
 
3
- static void dealloc(xmlErrorPtr ptr)
4
- {
5
- NOKOGIRI_DEBUG_START(ptr);
6
- xmlResetError(ptr);
7
- xmlFree(ptr);
8
- NOKOGIRI_DEBUG_END(ptr);
9
- }
10
-
11
- static VALUE allocate(VALUE klass)
12
- {
13
- xmlErrorPtr error = xmlMalloc(sizeof(xmlError));
14
- memset(error, 0, sizeof(xmlError));
15
- return Data_Wrap_Struct(klass, NULL, dealloc, error);
16
- }
17
-
18
- /*
19
- * call-seq:
20
- * column
21
- *
22
- * Column number or 0 if not available
23
- */
24
- static VALUE column(VALUE self)
25
- {
26
- xmlErrorPtr error;
27
- Data_Get_Struct(self, xmlError, error);
28
- return INT2NUM(error->int2);
29
- }
30
-
31
- /*
32
- * call-seq:
33
- * int1
34
- *
35
- * Extra number information
36
- */
37
- static VALUE int1(VALUE self)
38
- {
39
- xmlErrorPtr error;
40
- Data_Get_Struct(self, xmlError, error);
41
- return INT2NUM(error->int1);
42
- }
43
-
44
- /*
45
- * call-seq:
46
- * str3
47
- *
48
- * Extra string information
49
- */
50
- static VALUE str3(VALUE self)
51
- {
52
- xmlErrorPtr error;
53
- Data_Get_Struct(self, xmlError, error);
54
- if(error->str3) return NOKOGIRI_STR_NEW2(error->str3);
55
- return Qnil;
56
- }
57
-
58
- /*
59
- * call-seq:
60
- * str2
61
- *
62
- * Extra string information
63
- */
64
- static VALUE str2(VALUE self)
65
- {
66
- xmlErrorPtr error;
67
- Data_Get_Struct(self, xmlError, error);
68
- if(error->str2) return NOKOGIRI_STR_NEW2(error->str2);
69
- return Qnil;
70
- }
71
-
72
- /*
73
- * call-seq:
74
- * str1
75
- *
76
- * Extra string information
77
- */
78
- static VALUE str1(VALUE self)
79
- {
80
- xmlErrorPtr error;
81
- Data_Get_Struct(self, xmlError, error);
82
- if(error->str1) return NOKOGIRI_STR_NEW2(error->str1);
83
- return Qnil;
84
- }
85
-
86
- /*
87
- * call-seq:
88
- * line
89
- *
90
- * Get the line number of the error
91
- */
92
- static VALUE line(VALUE self)
93
- {
94
- xmlErrorPtr error;
95
- Data_Get_Struct(self, xmlError, error);
96
- return INT2NUM(error->line);
97
- }
98
-
99
- /*
100
- * call-seq:
101
- * file
102
- *
103
- * Get the filename for the error
104
- */
105
- static VALUE file(VALUE self)
106
- {
107
- xmlErrorPtr error;
108
- Data_Get_Struct(self, xmlError, error);
109
- if(error->file) return NOKOGIRI_STR_NEW2(error->file);
110
-
111
- return Qnil;
112
- }
113
-
114
- /*
115
- * call-seq:
116
- * level
117
- *
118
- * Get the error level
119
- */
120
- static VALUE level(VALUE self)
121
- {
122
- xmlErrorPtr error;
123
- Data_Get_Struct(self, xmlError, error);
124
- return INT2NUM((short)error->level);
125
- }
126
-
127
- /*
128
- * call-seq:
129
- * code
130
- *
131
- * Get the error code
132
- */
133
- static VALUE code(VALUE self)
134
- {
135
- xmlErrorPtr error;
136
- Data_Get_Struct(self, xmlError, error);
137
- return INT2NUM(error->code);
138
- }
139
-
140
- /*
141
- * call-seq:
142
- * domain
143
- *
144
- * Get the part of the library that raised this exception
145
- */
146
- static VALUE domain(VALUE self)
147
- {
148
- xmlErrorPtr error;
149
- Data_Get_Struct(self, xmlError, error);
150
- return INT2NUM(error->domain);
151
- }
152
-
153
- /*
154
- * call-seq:
155
- * message
156
- *
157
- * Get the human readable message.
158
- */
159
- static VALUE message(VALUE self)
160
- {
161
- xmlErrorPtr error;
162
- Data_Get_Struct(self, xmlError, error);
163
- if(error->message) return NOKOGIRI_STR_NEW2(error->message);
164
- return Qnil;
165
- }
166
-
167
- /*
168
- * call-seq:
169
- * message=
170
- *
171
- * Set the human readable message.
172
- */
173
- static VALUE set_message(VALUE self, VALUE _message)
174
- {
175
- xmlErrorPtr error;
176
- Data_Get_Struct(self, xmlError, error);
177
-
178
- if(error->message) {
179
- xmlFree(error->message);
180
- error->message = 0;
181
- }
182
-
183
- if(RTEST(_message)) {
184
- error->message = xmlMalloc(RSTRING_LEN(_message) + 1);
185
- memset(error->message, 0, RSTRING_LEN(_message) + 1);
186
- memcpy(error->message, StringValuePtr(_message), RSTRING_LEN(_message));
187
- }
188
-
189
- return message;
190
- }
191
-
192
- /*
193
- * call-seq:
194
- * initialize_copy(old_copy)
195
- *
196
- * Initialize a copy of the +old_copy+
197
- */
198
- static VALUE initialize_copy(VALUE self, VALUE _old_copy)
199
- {
200
- if(!rb_obj_is_kind_of(_old_copy, cNokogiriXmlSyntaxError))
201
- rb_raise(rb_eArgError, "node must be a Nokogiri::XML::SyntaxError");
202
-
203
- xmlErrorPtr error, old_error;
204
- Data_Get_Struct(self, xmlError, error);
205
- Data_Get_Struct(_old_copy, xmlError, old_error);
206
-
207
- xmlCopyError(old_error, error);
208
-
209
- return message;
210
- }
211
-
212
3
  void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
213
4
  {
214
5
  VALUE list = (VALUE)ctx;
@@ -224,10 +15,25 @@ VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error)
224
15
  {
225
16
  if(!klass) klass = cNokogiriXmlSyntaxError;
226
17
 
227
- xmlErrorPtr ptr = calloc(1, sizeof(xmlError));
228
- xmlCopyError(error, ptr);
18
+ VALUE msg = error->message ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
19
+
20
+ VALUE e = rb_class_new_instance(
21
+ 1,
22
+ &msg,
23
+ klass
24
+ );
25
+ rb_iv_set(e, "@domain", INT2NUM(error->domain));
26
+ rb_iv_set(e, "@code", INT2NUM(error->code));
27
+ rb_iv_set(e, "@level", INT2NUM((short)error->level));
28
+ rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
29
+ rb_iv_set(e, "@line", INT2NUM(error->line));
30
+ rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
31
+ rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
32
+ rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
33
+ rb_iv_set(e, "@int1", INT2NUM(error->int1));
34
+ rb_iv_set(e, "@column", INT2NUM(error->int2));
229
35
 
230
- return Data_Wrap_Struct(klass, NULL, dealloc, ptr);
36
+ return e;
231
37
  }
232
38
 
233
39
  VALUE cNokogiriXmlSyntaxError;
@@ -243,19 +49,4 @@ void init_xml_syntax_error()
243
49
  VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
244
50
  cNokogiriXmlSyntaxError = klass;
245
51
 
246
- rb_define_alloc_func(klass, allocate);
247
-
248
- rb_define_method(klass, "message", message, 0);
249
- rb_define_method(klass, "message=", set_message, 1);
250
- rb_define_method(klass, "initialize_copy", initialize_copy, 1);
251
- rb_define_method(klass, "domain", domain, 0);
252
- rb_define_method(klass, "code", code, 0);
253
- rb_define_method(klass, "level", level, 0);
254
- rb_define_method(klass, "file", file, 0);
255
- rb_define_method(klass, "line", line, 0);
256
- rb_define_method(klass, "str1", str1, 0);
257
- rb_define_method(klass, "str2", str2, 0);
258
- rb_define_method(klass, "str3", str3, 0);
259
- rb_define_method(klass, "int1", int1, 0);
260
- rb_define_method(klass, "column", column, 0);
261
52
  }