nokogiri 1.4.1-java → 1.4.2-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 (115) hide show
  1. data/CHANGELOG.ja.rdoc +45 -0
  2. data/CHANGELOG.rdoc +53 -1
  3. data/Manifest.txt +3 -3
  4. data/README.ja.rdoc +1 -1
  5. data/README.rdoc +11 -5
  6. data/Rakefile +13 -79
  7. data/ext/nokogiri/extconf.rb +22 -74
  8. data/ext/nokogiri/html_document.c +17 -8
  9. data/ext/nokogiri/html_element_description.c +20 -16
  10. data/ext/nokogiri/html_entity_lookup.c +2 -2
  11. data/ext/nokogiri/html_sax_parser_context.c +10 -8
  12. data/ext/nokogiri/libcharset-1.dll +0 -0
  13. data/ext/nokogiri/libexslt.dll +0 -0
  14. data/ext/nokogiri/libiconv-2.dll +0 -0
  15. data/ext/nokogiri/libxml2.dll +0 -0
  16. data/ext/nokogiri/libxslt.dll +0 -0
  17. data/ext/nokogiri/nokogiri.c +0 -1
  18. data/ext/nokogiri/nokogiri.h +33 -28
  19. data/ext/nokogiri/xml_attr.c +7 -5
  20. data/ext/nokogiri/xml_attribute_decl.c +5 -2
  21. data/ext/nokogiri/xml_cdata.c +4 -2
  22. data/ext/nokogiri/xml_comment.c +4 -2
  23. data/ext/nokogiri/xml_document.c +93 -15
  24. data/ext/nokogiri/xml_document.h +0 -1
  25. data/ext/nokogiri/xml_document_fragment.c +4 -2
  26. data/ext/nokogiri/xml_dtd.c +18 -8
  27. data/ext/nokogiri/xml_element_content.c +2 -2
  28. data/ext/nokogiri/xml_entity_decl.c +15 -2
  29. data/ext/nokogiri/xml_entity_reference.c +4 -2
  30. data/ext/nokogiri/xml_io.c +1 -1
  31. data/ext/nokogiri/xml_namespace.c +5 -3
  32. data/ext/nokogiri/xml_node.c +353 -114
  33. data/ext/nokogiri/xml_node_set.c +35 -22
  34. data/ext/nokogiri/xml_node_set.h +1 -1
  35. data/ext/nokogiri/xml_processing_instruction.c +4 -2
  36. data/ext/nokogiri/xml_reader.c +119 -47
  37. data/ext/nokogiri/xml_relax_ng.c +21 -12
  38. data/ext/nokogiri/xml_sax_parser.c +6 -3
  39. data/ext/nokogiri/xml_sax_parser.h +13 -17
  40. data/ext/nokogiri/xml_sax_parser_context.c +8 -6
  41. data/ext/nokogiri/xml_sax_push_parser.c +7 -6
  42. data/ext/nokogiri/xml_schema.c +62 -13
  43. data/ext/nokogiri/xml_syntax_error.c +18 -12
  44. data/ext/nokogiri/xml_syntax_error.h +1 -1
  45. data/ext/nokogiri/xml_text.c +4 -2
  46. data/ext/nokogiri/xml_xpath_context.c +60 -23
  47. data/ext/nokogiri/xslt_stylesheet.c +14 -3
  48. data/ext/nokogiri/zlib1.dll +0 -0
  49. data/lib/nokogiri.rb +17 -0
  50. data/lib/nokogiri/css/generated_parser.rb +72 -62
  51. data/lib/nokogiri/css/generated_tokenizer.rb +23 -24
  52. data/lib/nokogiri/css/parser.y +3 -1
  53. data/lib/nokogiri/css/tokenizer.rex +3 -3
  54. data/lib/nokogiri/css/xpath_visitor.rb +8 -3
  55. data/lib/nokogiri/ffi/html/sax/parser_context.rb +3 -3
  56. data/lib/nokogiri/ffi/libxml.rb +16 -2
  57. data/lib/nokogiri/ffi/structs/common_node.rb +15 -3
  58. data/lib/nokogiri/ffi/structs/xml_document.rb +13 -4
  59. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +3 -2
  60. data/lib/nokogiri/ffi/weak_bucket.rb +40 -0
  61. data/lib/nokogiri/ffi/xml/document.rb +27 -0
  62. data/lib/nokogiri/ffi/xml/entity_decl.rb +9 -0
  63. data/lib/nokogiri/ffi/xml/node.rb +142 -61
  64. data/lib/nokogiri/ffi/xml/node_set.rb +15 -12
  65. data/lib/nokogiri/ffi/xml/reader.rb +5 -0
  66. data/lib/nokogiri/ffi/xml/schema.rb +17 -0
  67. data/lib/nokogiri/ffi/xml/syntax_error.rb +4 -4
  68. data/lib/nokogiri/ffi/xml/xpath.rb +0 -10
  69. data/lib/nokogiri/ffi/xml/xpath_context.rb +22 -9
  70. data/lib/nokogiri/ffi/xslt/stylesheet.rb +3 -0
  71. data/lib/nokogiri/html/document.rb +5 -3
  72. data/lib/nokogiri/html/document_fragment.rb +28 -7
  73. data/lib/nokogiri/nokogiri.rb +1 -0
  74. data/lib/nokogiri/version.rb +6 -2
  75. data/lib/nokogiri/version_warning.rb +6 -3
  76. data/lib/nokogiri/xml.rb +1 -1
  77. data/lib/nokogiri/xml/builder.rb +35 -22
  78. data/lib/nokogiri/xml/document.rb +44 -12
  79. data/lib/nokogiri/xml/document_fragment.rb +16 -12
  80. data/lib/nokogiri/xml/entity_decl.rb +4 -0
  81. data/lib/nokogiri/xml/node.rb +152 -95
  82. data/lib/nokogiri/xml/node_set.rb +2 -1
  83. data/lib/nokogiri/xml/sax/push_parser.rb +1 -1
  84. data/lib/nokogiri/xml/schema.rb +1 -5
  85. data/lib/nokogiri/xml/syntax_error.rb +4 -0
  86. data/lib/nokogiri/xml/text.rb +9 -0
  87. data/lib/nokogiri/xml/xpath/syntax_error.rb +3 -0
  88. data/tasks/cross_compile.rb +157 -0
  89. data/tasks/test.rb +0 -6
  90. data/test/css/test_xpath_visitor.rb +9 -0
  91. data/test/helper.rb +49 -11
  92. data/test/html/sax/test_parser.rb +11 -1
  93. data/test/html/test_document.rb +8 -0
  94. data/test/html/test_document_fragment.rb +14 -2
  95. data/test/html/test_element_description.rb +5 -1
  96. data/test/html/test_node.rb +5 -66
  97. data/test/test_reader.rb +28 -0
  98. data/test/test_xslt_transforms.rb +14 -0
  99. data/test/xml/test_builder.rb +43 -0
  100. data/test/xml/test_cdata.rb +12 -0
  101. data/test/xml/test_document.rb +74 -39
  102. data/test/xml/test_document_fragment.rb +36 -0
  103. data/test/xml/test_entity_decl.rb +37 -0
  104. data/test/xml/test_node.rb +192 -65
  105. data/test/xml/test_node_reparenting.rb +253 -236
  106. data/test/xml/test_node_set.rb +67 -0
  107. data/test/xml/test_text.rb +8 -0
  108. data/test/xml/test_xpath.rb +32 -0
  109. metadata +119 -48
  110. data.tar.gz.sig +0 -0
  111. data/ext/nokogiri/iconv.dll +0 -0
  112. data/ext/nokogiri/xml_xpath.c +0 -53
  113. data/ext/nokogiri/xml_xpath.h +0 -11
  114. data/lib/nokogiri/xml/fragment_handler.rb +0 -79
  115. metadata.gz.sig +0 -0
@@ -17,16 +17,18 @@ static VALUE validate_document(VALUE self, VALUE document)
17
17
  {
18
18
  xmlDocPtr doc;
19
19
  xmlRelaxNGPtr schema;
20
+ VALUE errors;
21
+ xmlRelaxNGValidCtxtPtr valid_ctxt;
20
22
 
21
23
  Data_Get_Struct(self, xmlRelaxNG, schema);
22
24
  Data_Get_Struct(document, xmlDoc, doc);
23
25
 
24
- VALUE errors = rb_ary_new();
26
+ errors = rb_ary_new();
25
27
 
26
- xmlRelaxNGValidCtxtPtr valid_ctxt = xmlRelaxNGNewValidCtxt(schema);
28
+ valid_ctxt = xmlRelaxNGNewValidCtxt(schema);
27
29
 
28
30
  if(NULL == valid_ctxt) {
29
- // we have a problem
31
+ /* we have a problem */
30
32
  rb_raise(rb_eRuntimeError, "Could not create a validation context");
31
33
  }
32
34
 
@@ -55,10 +57,12 @@ static VALUE read_memory(VALUE klass, VALUE content)
55
57
  {
56
58
  xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewMemParserCtxt(
57
59
  (const char *)StringValuePtr(content),
58
- RSTRING_LEN(content)
60
+ (int)RSTRING_LEN(content)
59
61
  );
60
-
62
+ xmlRelaxNGPtr schema;
61
63
  VALUE errors = rb_ary_new();
64
+ VALUE rb_schema;
65
+
62
66
  xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
63
67
 
64
68
  #ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
@@ -69,7 +73,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
69
73
  );
70
74
  #endif
71
75
 
72
- xmlRelaxNGPtr schema = xmlRelaxNGParse(ctx);
76
+ schema = xmlRelaxNGParse(ctx);
73
77
 
74
78
  xmlSetStructuredErrorFunc(NULL, NULL);
75
79
  xmlRelaxNGFreeParserCtxt(ctx);
@@ -84,7 +88,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
84
88
  return Qnil;
85
89
  }
86
90
 
87
- VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
91
+ rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
88
92
  rb_iv_set(rb_schema, "@errors", errors);
89
93
 
90
94
  return rb_schema;
@@ -99,14 +103,19 @@ static VALUE read_memory(VALUE klass, VALUE content)
99
103
  static VALUE from_document(VALUE klass, VALUE document)
100
104
  {
101
105
  xmlDocPtr doc;
106
+ xmlRelaxNGParserCtxtPtr ctx;
107
+ xmlRelaxNGPtr schema;
108
+ VALUE errors;
109
+ VALUE rb_schema;
110
+
102
111
  Data_Get_Struct(document, xmlDoc, doc);
103
112
 
104
- // In case someone passes us a node. ugh.
113
+ /* In case someone passes us a node. ugh. */
105
114
  doc = doc->doc;
106
115
 
107
- xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewDocParserCtxt(doc);
116
+ ctx = xmlRelaxNGNewDocParserCtxt(doc);
108
117
 
109
- VALUE errors = rb_ary_new();
118
+ errors = rb_ary_new();
110
119
  xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
111
120
 
112
121
  #ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
@@ -117,7 +126,7 @@ static VALUE from_document(VALUE klass, VALUE document)
117
126
  );
118
127
  #endif
119
128
 
120
- xmlRelaxNGPtr schema = xmlRelaxNGParse(ctx);
129
+ schema = xmlRelaxNGParse(ctx);
121
130
 
122
131
  xmlSetStructuredErrorFunc(NULL, NULL);
123
132
  if (! is_2_6_16()) {
@@ -138,7 +147,7 @@ static VALUE from_document(VALUE klass, VALUE document)
138
147
  xmlRelaxNGFreeParserCtxt(ctx);
139
148
  }
140
149
 
141
- VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
150
+ rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
142
151
  rb_iv_set(rb_schema, "@errors", errors);
143
152
 
144
153
  return rb_schema;
@@ -1,5 +1,7 @@
1
1
  #include <xml_sax_parser.h>
2
2
 
3
+ int vasprintf (char **strp, const char *fmt, va_list ap);
4
+
3
5
  static ID id_start_document, id_end_document, id_start_element, id_end_element;
4
6
  static ID id_start_element_namespace, id_end_element_namespace;
5
7
  static ID id_comment, id_characters, id_xmldecl, id_error, id_warning;
@@ -16,7 +18,7 @@ static void start_document(void * ctx)
16
18
  xmlParserCtxtPtr ctxt = NOKOGIRI_SAX_CTXT(ctx);
17
19
 
18
20
  if(NULL != ctxt && ctxt->html != 1) {
19
- if(ctxt->standalone != -1) { // -1 means there was no declaration
21
+ if(ctxt->standalone != -1) { /* -1 means there was no declaration */
20
22
  VALUE encoding = ctxt->encoding ?
21
23
  NOKOGIRI_STR_NEW2(ctxt->encoding) :
22
24
  Qnil;
@@ -92,7 +94,8 @@ static VALUE attributes_as_list(
92
94
  /* Each attribute is an array of [localname, prefix, URI, value, end] */
93
95
  int i;
94
96
  for (i = 0; i < nb_attributes * 5; i += 5) {
95
- VALUE argv[4];
97
+ VALUE argv[4], attribute;
98
+
96
99
  argv[0] = RBSTR_OR_QNIL(attributes[i + 0]); /* localname */
97
100
  argv[1] = RBSTR_OR_QNIL(attributes[i + 1]); /* prefix */
98
101
  argv[2] = RBSTR_OR_QNIL(attributes[i + 2]); /* URI */
@@ -101,7 +104,7 @@ static VALUE attributes_as_list(
101
104
  argv[3] = NOKOGIRI_STR_NEW((const char*)attributes[i+3],
102
105
  (attributes[i+4] - attributes[i+3]));
103
106
 
104
- VALUE attribute = rb_class_new_instance(4, argv, attr_klass);
107
+ attribute = rb_class_new_instance(4, argv, attr_klass);
105
108
  rb_ary_push(list, attribute);
106
109
  }
107
110
  }
@@ -15,29 +15,25 @@ typedef struct _nokogiriSAXTuple {
15
15
  typedef nokogiriSAXTuple * nokogiriSAXTuplePtr;
16
16
 
17
17
  #define NOKOGIRI_SAX_SELF(_ctxt) \
18
- ({ \
19
- nokogiriSAXTuplePtr _tuple = (nokogiriSAXTuplePtr)(_ctxt); \
20
- _tuple->self; \
21
- })
18
+ ((nokogiriSAXTuplePtr)(_ctxt))->self
22
19
 
23
20
  #define NOKOGIRI_SAX_CTXT(_ctxt) \
24
- ({ \
25
- nokogiriSAXTuplePtr _tuple = (nokogiriSAXTuplePtr)(_ctxt); \
26
- _tuple->ctxt; \
27
- })
21
+ ((nokogiriSAXTuplePtr)(_ctxt))->ctxt
28
22
 
29
23
  #define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) \
30
- ({ \
31
- nokogiriSAXTuplePtr _tuple = malloc(sizeof(nokogiriSAXTuple)); \
32
- _tuple->self = _self; \
33
- _tuple->ctxt = _ctxt; \
34
- _tuple; \
35
- })
24
+ nokogiri_sax_tuple_new(_ctxt, _self)
25
+
26
+ static inline nokogiriSAXTuplePtr
27
+ nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
28
+ {
29
+ nokogiriSAXTuplePtr tuple = malloc(sizeof(nokogiriSAXTuple));
30
+ tuple->self = self;
31
+ tuple->ctxt = ctxt;
32
+ return tuple;
33
+ }
36
34
 
37
35
  #define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) \
38
- ({ \
39
- free(_tuple); \
40
- })
36
+ free(_tuple) \
41
37
 
42
38
  #endif
43
39
 
@@ -21,7 +21,7 @@ static void deallocate(xmlParserCtxtPtr ctxt)
21
21
  */
22
22
  static VALUE parse_io(VALUE klass, VALUE io, VALUE encoding)
23
23
  {
24
- xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
24
+ xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
25
25
 
26
26
  xmlParserCtxtPtr ctxt = xmlCreateIOParserCtxt(
27
27
  NULL,
@@ -55,11 +55,13 @@ static VALUE parse_file(VALUE klass, VALUE filename)
55
55
  */
56
56
  static VALUE parse_memory(VALUE klass, VALUE data)
57
57
  {
58
+ xmlParserCtxtPtr ctxt;
59
+
58
60
  if(NIL_P(data)) rb_raise(rb_eArgError, "data cannot be nil");
59
61
  if(!(int)RSTRING_LEN(data))
60
62
  rb_raise(rb_eRuntimeError, "data cannot be empty");
61
63
 
62
- xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(
64
+ ctxt = xmlCreateMemoryParserCtxt(
63
65
  StringValuePtr(data),
64
66
  (int)RSTRING_LEN(data)
65
67
  );
@@ -75,16 +77,16 @@ static VALUE parse_memory(VALUE klass, VALUE data)
75
77
  */
76
78
  static VALUE parse_with(VALUE self, VALUE sax_handler)
77
79
  {
80
+ xmlParserCtxtPtr ctxt;
81
+ xmlSAXHandlerPtr sax;
82
+
78
83
  if(!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser))
79
84
  rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
80
85
 
81
- xmlParserCtxtPtr ctxt;
82
86
  Data_Get_Struct(self, xmlParserCtxt, ctxt);
83
-
84
- xmlSAXHandlerPtr sax;
85
87
  Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
86
88
 
87
- // Free the sax handler since we'll assign our own
89
+ /* Free the sax handler since we'll assign our own */
88
90
  if(ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
89
91
  xmlFree(ctxt->sax);
90
92
 
@@ -24,14 +24,15 @@ static VALUE allocate(VALUE klass)
24
24
  static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
25
25
  {
26
26
  xmlParserCtxtPtr ctx;
27
- Data_Get_Struct(self, xmlParserCtxt, ctx);
28
-
29
27
  const char * chunk = NULL;
30
28
  int size = 0;
31
29
 
30
+
31
+ Data_Get_Struct(self, xmlParserCtxt, ctx);
32
+
32
33
  if(Qnil != _chunk) {
33
34
  chunk = StringValuePtr(_chunk);
34
- size = RSTRING_LEN(_chunk);
35
+ size = (int)RSTRING_LEN(_chunk);
35
36
  }
36
37
 
37
38
  if(xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
@@ -53,14 +54,14 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
53
54
  static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
54
55
  {
55
56
  xmlSAXHandlerPtr sax;
57
+ const char * filename = NULL;
58
+ xmlParserCtxtPtr ctx;
56
59
 
57
60
  Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
58
61
 
59
- const char * filename = NULL;
60
-
61
62
  if(_filename != Qnil) filename = StringValuePtr(_filename);
62
63
 
63
- xmlParserCtxtPtr ctx = xmlCreatePushParserCtxt(
64
+ ctx = xmlCreatePushParserCtxt(
64
65
  sax,
65
66
  NULL,
66
67
  NULL,
@@ -17,16 +17,18 @@ static VALUE validate_document(VALUE self, VALUE document)
17
17
  {
18
18
  xmlDocPtr doc;
19
19
  xmlSchemaPtr schema;
20
+ xmlSchemaValidCtxtPtr valid_ctxt;
21
+ VALUE errors;
20
22
 
21
23
  Data_Get_Struct(self, xmlSchema, schema);
22
24
  Data_Get_Struct(document, xmlDoc, doc);
23
25
 
24
- VALUE errors = rb_ary_new();
26
+ errors = rb_ary_new();
25
27
 
26
- xmlSchemaValidCtxtPtr valid_ctxt = xmlSchemaNewValidCtxt(schema);
28
+ valid_ctxt = xmlSchemaNewValidCtxt(schema);
27
29
 
28
30
  if(NULL == valid_ctxt) {
29
- // we have a problem
31
+ /* we have a problem */
30
32
  rb_raise(rb_eRuntimeError, "Could not create a validation context");
31
33
  }
32
34
 
@@ -45,6 +47,46 @@ static VALUE validate_document(VALUE self, VALUE document)
45
47
  return errors;
46
48
  }
47
49
 
50
+ /*
51
+ * call-seq:
52
+ * validate_file(filename)
53
+ *
54
+ * Validate a file against this Schema.
55
+ */
56
+ static VALUE validate_file(VALUE self, VALUE rb_filename)
57
+ {
58
+ xmlSchemaPtr schema;
59
+ xmlSchemaValidCtxtPtr valid_ctxt;
60
+ const char *filename ;
61
+ VALUE errors;
62
+
63
+ Data_Get_Struct(self, xmlSchema, schema);
64
+ filename = (const char*)StringValuePtr(rb_filename) ;
65
+
66
+ errors = rb_ary_new();
67
+
68
+ valid_ctxt = xmlSchemaNewValidCtxt(schema);
69
+
70
+ if(NULL == valid_ctxt) {
71
+ /* we have a problem */
72
+ rb_raise(rb_eRuntimeError, "Could not create a validation context");
73
+ }
74
+
75
+ #ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
76
+ xmlSchemaSetValidStructuredErrors(
77
+ valid_ctxt,
78
+ Nokogiri_error_array_pusher,
79
+ (void *)errors
80
+ );
81
+ #endif
82
+
83
+ xmlSchemaValidateFile(valid_ctxt, filename, 0);
84
+
85
+ xmlSchemaFreeValidCtxt(valid_ctxt);
86
+
87
+ return errors;
88
+ }
89
+
48
90
  /*
49
91
  * call-seq:
50
92
  * read_memory(string)
@@ -53,12 +95,12 @@ static VALUE validate_document(VALUE self, VALUE document)
53
95
  */
54
96
  static VALUE read_memory(VALUE klass, VALUE content)
55
97
  {
56
-
98
+ xmlSchemaPtr schema;
57
99
  xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt(
58
100
  (const char *)StringValuePtr(content),
59
- RSTRING_LEN(content)
101
+ (int)RSTRING_LEN(content)
60
102
  );
61
-
103
+ VALUE rb_schema;
62
104
  VALUE errors = rb_ary_new();
63
105
  xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
64
106
 
@@ -70,7 +112,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
70
112
  );
71
113
  #endif
72
114
 
73
- xmlSchemaPtr schema = xmlSchemaParse(ctx);
115
+ schema = xmlSchemaParse(ctx);
74
116
 
75
117
  xmlSetStructuredErrorFunc(NULL, NULL);
76
118
  xmlSchemaFreeParserCtxt(ctx);
@@ -85,7 +127,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
85
127
  return Qnil;
86
128
  }
87
129
 
88
- VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
130
+ rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
89
131
  rb_iv_set(rb_schema, "@errors", errors);
90
132
 
91
133
  return rb_schema;
@@ -100,14 +142,19 @@ static VALUE read_memory(VALUE klass, VALUE content)
100
142
  static VALUE from_document(VALUE klass, VALUE document)
101
143
  {
102
144
  xmlDocPtr doc;
145
+ xmlSchemaParserCtxtPtr ctx;
146
+ xmlSchemaPtr schema;
147
+ VALUE errors;
148
+ VALUE rb_schema;
149
+
103
150
  Data_Get_Struct(document, xmlDoc, doc);
104
151
 
105
- // In case someone passes us a node. ugh.
152
+ /* In case someone passes us a node. ugh. */
106
153
  doc = doc->doc;
107
154
 
108
- xmlSchemaParserCtxtPtr ctx = xmlSchemaNewDocParserCtxt(doc);
155
+ ctx = xmlSchemaNewDocParserCtxt(doc);
109
156
 
110
- VALUE errors = rb_ary_new();
157
+ errors = rb_ary_new();
111
158
  xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
112
159
 
113
160
  #ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
@@ -118,7 +165,7 @@ static VALUE from_document(VALUE klass, VALUE document)
118
165
  );
119
166
  #endif
120
167
 
121
- xmlSchemaPtr schema = xmlSchemaParse(ctx);
168
+ schema = xmlSchemaParse(ctx);
122
169
 
123
170
  xmlSetStructuredErrorFunc(NULL, NULL);
124
171
  xmlSchemaFreeParserCtxt(ctx);
@@ -133,7 +180,7 @@ static VALUE from_document(VALUE klass, VALUE document)
133
180
  return Qnil;
134
181
  }
135
182
 
136
- VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
183
+ rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
137
184
  rb_iv_set(rb_schema, "@errors", errors);
138
185
 
139
186
  return rb_schema;
@@ -152,5 +199,7 @@ void init_xml_schema()
152
199
 
153
200
  rb_define_singleton_method(klass, "read_memory", read_memory, 1);
154
201
  rb_define_singleton_method(klass, "from_document", from_document, 1);
202
+
155
203
  rb_define_private_method(klass, "validate_document", validate_document, 1);
204
+ rb_define_private_method(klass, "validate_file", validate_file, 1);
156
205
  }
@@ -13,25 +13,31 @@ void Nokogiri_error_raise(void * ctx, xmlErrorPtr error)
13
13
 
14
14
  VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error)
15
15
  {
16
+ VALUE msg, e;
17
+
16
18
  if(!klass) klass = cNokogiriXmlSyntaxError;
17
19
 
18
- VALUE msg = error->message ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
20
+ msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
19
21
 
20
- VALUE e = rb_class_new_instance(
22
+ e = rb_class_new_instance(
21
23
  1,
22
24
  &msg,
23
25
  klass
24
26
  );
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));
27
+
28
+ if (error)
29
+ {
30
+ rb_iv_set(e, "@domain", INT2NUM(error->domain));
31
+ rb_iv_set(e, "@code", INT2NUM(error->code));
32
+ rb_iv_set(e, "@level", INT2NUM((short)error->level));
33
+ rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
34
+ rb_iv_set(e, "@line", INT2NUM(error->line));
35
+ rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
36
+ rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
37
+ rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
38
+ rb_iv_set(e, "@int1", INT2NUM(error->int1));
39
+ rb_iv_set(e, "@column", INT2NUM(error->int2));
40
+ }
35
41
 
36
42
  return e;
37
43
  }
@@ -6,7 +6,7 @@
6
6
  void init_xml_syntax_error();
7
7
  VALUE Nokogiri_wrap_xml_syntax_error(VALUE klass, xmlErrorPtr error);
8
8
  void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error);
9
- void Nokogiri_error_raise(void * ctx, xmlErrorPtr error);
9
+ NORETURN(void Nokogiri_error_raise(void * ctx, xmlErrorPtr error));
10
10
 
11
11
  extern VALUE cNokogiriXmlSyntaxError;
12
12
  #endif