ox 1.2.11 → 1.2.12
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ox might be problematic. Click here for more details.
- data/ext/ox/dump.c +47 -39
- data/ext/ox/gen_load.c +14 -0
- data/ext/ox/obj_load.c +8 -1
- data/ext/ox/ox.c +2 -0
- data/ext/ox/ox.h +6 -0
- data/ext/ox/parse.c +2 -0
- data/lib/ox/version.rb +1 -1
- metadata +2 -2
data/ext/ox/dump.c
CHANGED
@@ -35,7 +35,7 @@
|
|
35
35
|
#include <string.h>
|
36
36
|
|
37
37
|
#include "ruby.h"
|
38
|
-
#include "ruby/
|
38
|
+
#include "ruby/st.h"
|
39
39
|
#include "base64.h"
|
40
40
|
#include "cache8.h"
|
41
41
|
#include "ox.h"
|
@@ -118,28 +118,32 @@ is_xml_friendly(const u_char *str, int len) {
|
|
118
118
|
inline static Type
|
119
119
|
obj_class_code(VALUE obj) {
|
120
120
|
switch (rb_type(obj)) {
|
121
|
-
case
|
122
|
-
case
|
123
|
-
case
|
124
|
-
case
|
125
|
-
case
|
126
|
-
case
|
127
|
-
case
|
128
|
-
case
|
129
|
-
case
|
121
|
+
case T_NIL: return NilClassCode;
|
122
|
+
case T_ARRAY: return ArrayCode;
|
123
|
+
case T_HASH: return HashCode;
|
124
|
+
case T_TRUE: return TrueClassCode;
|
125
|
+
case T_FALSE: return FalseClassCode;
|
126
|
+
case T_FIXNUM: return FixnumCode;
|
127
|
+
case T_FLOAT: return FloatCode;
|
128
|
+
case T_STRING: return (is_xml_friendly((u_char*)StringValuePtr(obj), (int)RSTRING_LEN(obj))) ? StringCode : String64Code;
|
129
|
+
case T_SYMBOL:
|
130
130
|
{
|
131
131
|
const char *sym = rb_id2name(SYM2ID(obj));
|
132
132
|
|
133
133
|
return (is_xml_friendly((u_char*)sym, (int)strlen(sym))) ? SymbolCode : Symbol64Code;
|
134
134
|
}
|
135
|
-
case
|
136
|
-
case
|
137
|
-
case
|
138
|
-
case
|
139
|
-
case
|
140
|
-
|
141
|
-
case
|
142
|
-
|
135
|
+
case T_DATA: return (rb_cTime == rb_obj_class(obj)) ? TimeCode : 0;
|
136
|
+
case T_STRUCT: return (rb_cRange == rb_obj_class(obj)) ? RangeCode : StructCode;
|
137
|
+
case T_OBJECT: return (ox_document_clas == rb_obj_class(obj) || ox_element_clas == rb_obj_class(obj)) ? RawCode : ObjectCode;
|
138
|
+
case T_REGEXP: return RegexpCode;
|
139
|
+
case T_BIGNUM: return BignumCode;
|
140
|
+
#ifdef T_COMPLEX
|
141
|
+
case T_COMPLEX: return ComplexCode;
|
142
|
+
#endif
|
143
|
+
#ifdef T_RATIONAL
|
144
|
+
case T_RATIONAL: return RationalCode;
|
145
|
+
#endif
|
146
|
+
case T_CLASS: return ClassCode;
|
143
147
|
default: return 0;
|
144
148
|
}
|
145
149
|
}
|
@@ -449,12 +453,12 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
449
453
|
e.clas.len = 0;
|
450
454
|
e.clas.str = 0;
|
451
455
|
switch (rb_type(obj)) {
|
452
|
-
case
|
456
|
+
case T_NIL:
|
453
457
|
e.type = NilClassCode;
|
454
458
|
e.closed = 1;
|
455
459
|
out->w_start(out, &e);
|
456
460
|
break;
|
457
|
-
case
|
461
|
+
case T_ARRAY:
|
458
462
|
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
|
459
463
|
break;
|
460
464
|
}
|
@@ -473,7 +477,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
473
477
|
out->w_end(out, &e);
|
474
478
|
}
|
475
479
|
break;
|
476
|
-
case
|
480
|
+
case T_HASH:
|
477
481
|
if (0 != out->circ_cache && check_circular(out, obj, &e)) {
|
478
482
|
break;
|
479
483
|
}
|
@@ -490,24 +494,24 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
490
494
|
out->w_end(out, &e);
|
491
495
|
}
|
492
496
|
break;
|
493
|
-
case
|
497
|
+
case T_TRUE:
|
494
498
|
e.type = TrueClassCode;
|
495
499
|
e.closed = 1;
|
496
500
|
out->w_start(out, &e);
|
497
501
|
break;
|
498
|
-
case
|
502
|
+
case T_FALSE:
|
499
503
|
e.type = FalseClassCode;
|
500
504
|
e.closed = 1;
|
501
505
|
out->w_start(out, &e);
|
502
506
|
break;
|
503
|
-
case
|
507
|
+
case T_FIXNUM:
|
504
508
|
e.type = FixnumCode;
|
505
509
|
out->w_start(out, &e);
|
506
510
|
dump_num(out, obj);
|
507
511
|
e.indent = -1;
|
508
512
|
out->w_end(out, &e);
|
509
513
|
break;
|
510
|
-
case
|
514
|
+
case T_FLOAT:
|
511
515
|
e.type = FloatCode;
|
512
516
|
cnt = sprintf(value_buf, "%0.16g", RFLOAT_VALUE(obj)); // used sprintf due to bug in snprintf
|
513
517
|
out->w_start(out, &e);
|
@@ -515,7 +519,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
515
519
|
e.indent = -1;
|
516
520
|
out->w_end(out, &e);
|
517
521
|
break;
|
518
|
-
case
|
522
|
+
case T_STRING:
|
519
523
|
{
|
520
524
|
const char *str;
|
521
525
|
|
@@ -552,7 +556,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
552
556
|
}
|
553
557
|
break;
|
554
558
|
}
|
555
|
-
case
|
559
|
+
case T_SYMBOL:
|
556
560
|
{
|
557
561
|
const char *sym = rb_id2name(SYM2ID(obj));
|
558
562
|
|
@@ -585,7 +589,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
585
589
|
}
|
586
590
|
break;
|
587
591
|
}
|
588
|
-
case
|
592
|
+
case T_DATA:
|
589
593
|
{
|
590
594
|
VALUE clas;
|
591
595
|
|
@@ -598,7 +602,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
598
602
|
out->w_end(out, &e);
|
599
603
|
} else {
|
600
604
|
if (StrictEffort == out->opts->effort) {
|
601
|
-
rb_raise(rb_eNotImpError, "Failed to dump
|
605
|
+
rb_raise(rb_eNotImpError, "Failed to dump T_DATA %s\n", rb_class2name(clas));
|
602
606
|
} else {
|
603
607
|
e.type = NilClassCode;
|
604
608
|
e.closed = 1;
|
@@ -607,7 +611,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
607
611
|
}
|
608
612
|
break;
|
609
613
|
}
|
610
|
-
case
|
614
|
+
case T_STRUCT:
|
611
615
|
{
|
612
616
|
VALUE clas;
|
613
617
|
|
@@ -645,7 +649,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
645
649
|
}
|
646
650
|
break;
|
647
651
|
}
|
648
|
-
case
|
652
|
+
case T_OBJECT:
|
649
653
|
{
|
650
654
|
VALUE clas;
|
651
655
|
|
@@ -681,7 +685,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
681
685
|
}
|
682
686
|
break;
|
683
687
|
}
|
684
|
-
case
|
688
|
+
case T_REGEXP:
|
685
689
|
{
|
686
690
|
#if 1
|
687
691
|
VALUE rs = rb_funcall2(obj, inspect_id, 0, 0);
|
@@ -731,7 +735,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
731
735
|
out->w_end(out, &e);
|
732
736
|
break;
|
733
737
|
}
|
734
|
-
case
|
738
|
+
case T_BIGNUM:
|
735
739
|
{
|
736
740
|
VALUE rs = rb_big2str(obj, 10);
|
737
741
|
|
@@ -742,21 +746,25 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
742
746
|
out->w_end(out, &e);
|
743
747
|
break;
|
744
748
|
}
|
745
|
-
|
749
|
+
#ifdef T_COMPLEX
|
750
|
+
case T_COMPLEX:
|
746
751
|
e.type = ComplexCode;
|
747
752
|
out->w_start(out, &e);
|
748
753
|
dump_obj(0, RCOMPLEX(obj)->real, depth + 1, out);
|
749
754
|
dump_obj(0, RCOMPLEX(obj)->imag, depth + 1, out);
|
750
755
|
out->w_end(out, &e);
|
751
756
|
break;
|
752
|
-
|
757
|
+
#endif
|
758
|
+
#ifdef T_RATIONAL
|
759
|
+
case T_RATIONAL:
|
753
760
|
e.type = RationalCode;
|
754
761
|
out->w_start(out, &e);
|
755
762
|
dump_obj(0, RRATIONAL(obj)->num, depth + 1, out);
|
756
763
|
dump_obj(0, RRATIONAL(obj)->den, depth + 1, out);
|
757
764
|
out->w_end(out, &e);
|
758
765
|
break;
|
759
|
-
|
766
|
+
#endif
|
767
|
+
case T_CLASS:
|
760
768
|
{
|
761
769
|
e.type = ClassCode;
|
762
770
|
e.clas.str = rb_class2name(obj);
|
@@ -780,7 +788,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
780
788
|
|
781
789
|
static int
|
782
790
|
dump_var(ID key, VALUE value, Out out) {
|
783
|
-
if (
|
791
|
+
if (T_DATA == rb_type(value) && rb_cTime != rb_obj_class(value)) {
|
784
792
|
/* There is a secret recipe that keeps Exception mesg attributes as a
|
785
793
|
* T_DATA until it is needed. StringValue() makes the value needed and
|
786
794
|
* it is converted to a regular Ruby Object. It might seem reasonable
|
@@ -909,7 +917,7 @@ dump_gen_nodes(VALUE obj, unsigned int depth, Out out) {
|
|
909
917
|
|
910
918
|
static int
|
911
919
|
dump_gen_attr(VALUE key, VALUE value, Out out) {
|
912
|
-
const char *ks = (
|
920
|
+
const char *ks = (T_SYMBOL == rb_type(key)) ? rb_id2name(SYM2ID(key)) : StringValuePtr(key);
|
913
921
|
size_t klen = strlen(ks);
|
914
922
|
size_t size = 4 + klen + RSTRING_LEN(value);
|
915
923
|
|
@@ -936,7 +944,7 @@ dump_gen_val_node(VALUE obj, unsigned int depth,
|
|
936
944
|
size_t size;
|
937
945
|
int indent;
|
938
946
|
|
939
|
-
if (
|
947
|
+
if (T_STRING != rb_type(v)) {
|
940
948
|
return;
|
941
949
|
}
|
942
950
|
val = StringValuePtr(v);
|
data/ext/ox/gen_load.c
CHANGED
@@ -99,9 +99,11 @@ create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
|
|
99
99
|
ah = rb_hash_new();
|
100
100
|
for (; 0 != attrs->name; attrs++) {
|
101
101
|
rb_hash_aset(ah, ID2SYM(rb_intern(attrs->name)), rb_str_new2(attrs->value));
|
102
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
102
103
|
if (0 == strcmp("encoding", attrs->name)) {
|
103
104
|
pi->encoding = rb_enc_find(attrs->value);
|
104
105
|
}
|
106
|
+
#endif
|
105
107
|
}
|
106
108
|
nodes = rb_ary_new();
|
107
109
|
rb_ivar_set(doc, attributes_id, ah);
|
@@ -170,9 +172,11 @@ add_doctype(PInfo pi, const char *docType) {
|
|
170
172
|
VALUE n = rb_obj_alloc(ox_doctype_clas);
|
171
173
|
VALUE s = rb_str_new2(docType);
|
172
174
|
|
175
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
173
176
|
if (0 != pi->encoding) {
|
174
177
|
rb_enc_associate(s, pi->encoding);
|
175
178
|
}
|
179
|
+
#endif
|
176
180
|
rb_ivar_set(n, value_id, s);
|
177
181
|
rb_ary_push(pi->h->obj, n);
|
178
182
|
}
|
@@ -182,9 +186,11 @@ add_comment(PInfo pi, const char *comment) {
|
|
182
186
|
VALUE n = rb_obj_alloc(ox_comment_clas);
|
183
187
|
VALUE s = rb_str_new2(comment);
|
184
188
|
|
189
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
185
190
|
if (0 != pi->encoding) {
|
186
191
|
rb_enc_associate(s, pi->encoding);
|
187
192
|
}
|
193
|
+
#endif
|
188
194
|
rb_ivar_set(n, value_id, s);
|
189
195
|
rb_ary_push(pi->h->obj, n);
|
190
196
|
}
|
@@ -194,9 +200,11 @@ add_cdata(PInfo pi, const char *cdata, size_t len) {
|
|
194
200
|
VALUE n = rb_obj_alloc(ox_cdata_clas);
|
195
201
|
VALUE s = rb_str_new2(cdata);
|
196
202
|
|
203
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
197
204
|
if (0 != pi->encoding) {
|
198
205
|
rb_enc_associate(s, pi->encoding);
|
199
206
|
}
|
207
|
+
#endif
|
200
208
|
rb_ivar_set(n, value_id, s);
|
201
209
|
rb_ary_push(pi->h->obj, n);
|
202
210
|
}
|
@@ -205,9 +213,11 @@ static void
|
|
205
213
|
add_text(PInfo pi, char *text, int closed) {
|
206
214
|
VALUE s = rb_str_new2(text);
|
207
215
|
|
216
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
208
217
|
if (0 != pi->encoding) {
|
209
218
|
rb_enc_associate(s, pi->encoding);
|
210
219
|
}
|
220
|
+
#endif
|
211
221
|
rb_ary_push(pi->h->obj, s);
|
212
222
|
}
|
213
223
|
|
@@ -216,9 +226,11 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
216
226
|
VALUE e;
|
217
227
|
VALUE s = rb_str_new2(ename);
|
218
228
|
|
229
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
219
230
|
if (0 != pi->encoding) {
|
220
231
|
rb_enc_associate(s, pi->encoding);
|
221
232
|
}
|
233
|
+
#endif
|
222
234
|
e = rb_obj_alloc(ox_element_clas);
|
223
235
|
rb_ivar_set(e, value_id, s);
|
224
236
|
if (0 != attrs->name) {
|
@@ -233,9 +245,11 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
233
245
|
*slot = sym;
|
234
246
|
}
|
235
247
|
s = rb_str_new2(attrs->value);
|
248
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
236
249
|
if (0 != pi->encoding) {
|
237
250
|
rb_enc_associate(s, pi->encoding);
|
238
251
|
}
|
252
|
+
#endif
|
239
253
|
rb_hash_aset(ah, sym, s);
|
240
254
|
}
|
241
255
|
rb_ivar_set(e, attributes_id, ah);
|
data/ext/ox/obj_load.c
CHANGED
@@ -36,7 +36,6 @@
|
|
36
36
|
#include <time.h>
|
37
37
|
|
38
38
|
#include "ruby.h"
|
39
|
-
#include "ruby/oniguruma.h"
|
40
39
|
#include "base64.h"
|
41
40
|
#include "ox.h"
|
42
41
|
|
@@ -330,6 +329,7 @@ parse_regexp(const char *text) {
|
|
330
329
|
int options = 0;
|
331
330
|
|
332
331
|
te = text + strlen(text) - 1;
|
332
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
333
333
|
for (; text < te && '/' != *te; te--) {
|
334
334
|
switch (*te) {
|
335
335
|
case 'i': options |= ONIG_OPTION_IGNORECASE; break;
|
@@ -338,17 +338,20 @@ parse_regexp(const char *text) {
|
|
338
338
|
default: break;
|
339
339
|
}
|
340
340
|
}
|
341
|
+
#endif
|
341
342
|
return rb_reg_new(text + 1, te - text - 1, options);
|
342
343
|
}
|
343
344
|
|
344
345
|
static void
|
345
346
|
instruct(PInfo pi, const char *target, Attr attrs) {
|
346
347
|
if (0 == strcmp("xml", target)) {
|
348
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
347
349
|
for (; 0 != attrs->name; attrs++) {
|
348
350
|
if (0 == strcmp("encoding", attrs->name)) {
|
349
351
|
pi->encoding = rb_enc_find(attrs->value);
|
350
352
|
}
|
351
353
|
}
|
354
|
+
#endif
|
352
355
|
}
|
353
356
|
}
|
354
357
|
|
@@ -367,9 +370,11 @@ add_text(PInfo pi, char *text, int closed) {
|
|
367
370
|
case NoCode:
|
368
371
|
case StringCode:
|
369
372
|
pi->h->obj = rb_str_new2(text);
|
373
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
370
374
|
if (0 != pi->encoding) {
|
371
375
|
rb_enc_associate(pi->h->obj, pi->encoding);
|
372
376
|
}
|
377
|
+
#endif
|
373
378
|
if (0 != pi->circ_array) {
|
374
379
|
circ_array_set(pi->circ_array, pi->h->obj, (unsigned long)pi->id);
|
375
380
|
}
|
@@ -430,9 +435,11 @@ add_text(PInfo pi, char *text, int closed) {
|
|
430
435
|
}
|
431
436
|
from_base64(text, (u_char*)str);
|
432
437
|
v = rb_str_new(str, str_size);
|
438
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
433
439
|
if (0 != pi->encoding) {
|
434
440
|
rb_enc_associate(v, pi->encoding);
|
435
441
|
}
|
442
|
+
#endif
|
436
443
|
if (0 != pi->circ_array) {
|
437
444
|
circ_array_set(pi->circ_array, v, (unsigned long)pi->h->obj);
|
438
445
|
}
|
data/ext/ox/ox.c
CHANGED
@@ -519,9 +519,11 @@ dump(int argc, VALUE *argv, VALUE self) {
|
|
519
519
|
rb_raise(rb_eNoMemError, "Not enough memory.\n");
|
520
520
|
}
|
521
521
|
rstr = rb_str_new2(xml);
|
522
|
+
#ifdef ENCODING_INLINE_MAX
|
522
523
|
if ('\0' != *copts.encoding) {
|
523
524
|
rb_enc_associate(rstr, rb_enc_find(copts.encoding));
|
524
525
|
}
|
526
|
+
#endif
|
525
527
|
free(xml);
|
526
528
|
|
527
529
|
return rstr;
|
data/ext/ox/ox.h
CHANGED
@@ -38,7 +38,11 @@ extern "C" {
|
|
38
38
|
#endif
|
39
39
|
#endif
|
40
40
|
|
41
|
+
#include "ruby.h"
|
42
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
43
|
+
// RUBY_T_NIL defined for Ruby 1.9
|
41
44
|
#include "ruby/encoding.h"
|
45
|
+
#endif
|
42
46
|
#include "cache.h"
|
43
47
|
|
44
48
|
#define raise_error(msg, xml, current) _raise_error(msg, xml, current, __FILE__, __LINE__)
|
@@ -163,7 +167,9 @@ struct _PInfo {
|
|
163
167
|
VALUE obj;
|
164
168
|
ParseCallbacks pcb;
|
165
169
|
CircArray circ_array;
|
170
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
166
171
|
rb_encoding *encoding;
|
172
|
+
#endif
|
167
173
|
unsigned long id; /* set for text types when cirs_array is set */
|
168
174
|
int trace;
|
169
175
|
Effort effort;
|
data/ext/ox/parse.c
CHANGED
@@ -96,7 +96,9 @@ parse(char *xml, ParseCallbacks pcb, char **endp, int trace, Effort effort) {
|
|
96
96
|
pi.pcb = pcb;
|
97
97
|
pi.obj = Qnil;
|
98
98
|
pi.circ_array = 0;
|
99
|
+
#ifdef ENCODING_INLINE_MAX
|
99
100
|
pi.encoding = 0;
|
101
|
+
#endif
|
100
102
|
pi.trace = trace;
|
101
103
|
pi.effort = effort;
|
102
104
|
while (1) {
|
data/lib/ox/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.12
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Peter Ohler
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-31 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|