ox 2.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/README.md +121 -128
- data/ext/ox/attr.h +109 -0
- data/ext/ox/err.c +64 -0
- data/ext/ox/err.h +61 -0
- data/ext/ox/gen_load.c +32 -33
- data/ext/ox/helper.h +116 -0
- data/ext/ox/obj_load.c +551 -518
- data/ext/ox/ox.c +43 -20
- data/ext/ox/ox.h +9 -47
- data/ext/ox/parse.c +146 -70
- data/ext/ox/sax.c +19 -1
- data/ext/ox/sax_buf.c +5 -4
- data/ext/ox/sax_has.h +2 -0
- data/ext/ox/sax_stack.h +3 -3
- data/ext/ox/type.h +63 -0
- data/lib/ox/sax.rb +12 -6
- data/lib/ox/version.rb +1 -1
- metadata +8 -4
data/ext/ox/sax.c
CHANGED
@@ -96,9 +96,16 @@ char *stpncpy(char *dest, const char *src, size_t n) {
|
|
96
96
|
}
|
97
97
|
#endif
|
98
98
|
|
99
|
+
static VALUE protect_parse(VALUE drp) {
|
100
|
+
parse((SaxDrive)drp);
|
101
|
+
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
99
105
|
void
|
100
106
|
ox_sax_parse(VALUE handler, VALUE io, SaxOptions options) {
|
101
107
|
struct _SaxDrive dr;
|
108
|
+
int line = 0;
|
102
109
|
|
103
110
|
sax_drive_init(&dr, handler, io, options);
|
104
111
|
#if 0
|
@@ -107,6 +114,7 @@ ox_sax_parse(VALUE handler, VALUE io, SaxOptions options) {
|
|
107
114
|
printf(" has_end_instruct = %s\n", dr.has.end_instruct ? "true" : "false");
|
108
115
|
printf(" has_attr = %s\n", dr.has.attr ? "true" : "false");
|
109
116
|
printf(" has_attr_value = %s\n", dr.has.attr_value ? "true" : "false");
|
117
|
+
printf(" has_attrs_done = %s\n", dr.has.attrs_done ? "true" : "false");
|
110
118
|
printf(" has_doctype = %s\n", dr.has.doctype ? "true" : "false");
|
111
119
|
printf(" has_comment = %s\n", dr.has.comment ? "true" : "false");
|
112
120
|
printf(" has_cdata = %s\n", dr.has.cdata ? "true" : "false");
|
@@ -118,8 +126,12 @@ ox_sax_parse(VALUE handler, VALUE io, SaxOptions options) {
|
|
118
126
|
printf(" has_line = %s\n", dr.has.line ? "true" : "false");
|
119
127
|
printf(" has_column = %s\n", dr.has.column ? "true" : "false");
|
120
128
|
#endif
|
121
|
-
parse(&dr);
|
129
|
+
//parse(&dr);
|
130
|
+
rb_protect(protect_parse, (VALUE)&dr, &line);
|
122
131
|
ox_sax_drive_cleanup(&dr);
|
132
|
+
if (0 != line) {
|
133
|
+
rb_jump_tag(line);
|
134
|
+
}
|
123
135
|
}
|
124
136
|
|
125
137
|
static void
|
@@ -404,6 +416,9 @@ read_instruction(SaxDrive dr) {
|
|
404
416
|
buf_reset(&dr->buf);
|
405
417
|
dr->err = 0;
|
406
418
|
c = read_attrs(dr, c, '?', '?', is_xml, 1);
|
419
|
+
if (dr->has.attrs_done) {
|
420
|
+
rb_funcall(dr->handler, ox_attrs_done_id, 0);
|
421
|
+
}
|
407
422
|
if (dr->err) {
|
408
423
|
if (dr->has.text) {
|
409
424
|
VALUE args[1];
|
@@ -749,6 +764,9 @@ read_element_start(SaxDrive dr) {
|
|
749
764
|
}
|
750
765
|
closed = ('/' == c);
|
751
766
|
}
|
767
|
+
if (dr->has.attrs_done) {
|
768
|
+
rb_funcall(dr->handler, ox_attrs_done_id, 0);
|
769
|
+
}
|
752
770
|
if (closed) {
|
753
771
|
c = buf_next_non_white(&dr->buf);
|
754
772
|
line = dr->buf.line;
|
data/ext/ox/sax_buf.c
CHANGED
@@ -43,6 +43,8 @@
|
|
43
43
|
#include "ox.h"
|
44
44
|
#include "sax.h"
|
45
45
|
|
46
|
+
#define BUF_PAD 4
|
47
|
+
|
46
48
|
static VALUE rescue_cb(VALUE rdr, VALUE err);
|
47
49
|
static VALUE io_cb(VALUE rdr);
|
48
50
|
static VALUE partial_io_cb(VALUE rdr);
|
@@ -95,7 +97,7 @@ ox_sax_buf_init(Buf buf, VALUE io) {
|
|
95
97
|
}
|
96
98
|
buf->head = buf->base;
|
97
99
|
*buf->head = '\0';
|
98
|
-
buf->end = buf->head + sizeof(buf->base) -
|
100
|
+
buf->end = buf->head + sizeof(buf->base) - BUF_PAD;
|
99
101
|
buf->tail = buf->head;
|
100
102
|
buf->read_end = buf->head;
|
101
103
|
buf->pro = 0;
|
@@ -118,10 +120,9 @@ ox_sax_buf_read(Buf buf) {
|
|
118
120
|
} else {
|
119
121
|
shift = buf->pro - buf->head;
|
120
122
|
}
|
121
|
-
/*printf("\n*** shift: %lu\n", shift); */
|
122
123
|
if (0 == shift) { /* no space left so allocate more */
|
123
124
|
char *old = buf->head;
|
124
|
-
size_t size = buf->end - buf->head;
|
125
|
+
size_t size = buf->end - buf->head + BUF_PAD;
|
125
126
|
|
126
127
|
if (buf->head == buf->base) {
|
127
128
|
buf->head = ALLOC_N(char, size * 2);
|
@@ -129,7 +130,7 @@ ox_sax_buf_read(Buf buf) {
|
|
129
130
|
} else {
|
130
131
|
REALLOC_N(buf->head, char, size * 2);
|
131
132
|
}
|
132
|
-
buf->end = buf->head + size * 2;
|
133
|
+
buf->end = buf->head + size * 2 - BUF_PAD;
|
133
134
|
buf->tail = buf->head + (buf->tail - old);
|
134
135
|
buf->read_end = buf->head + (buf->read_end - old);
|
135
136
|
if (0 != buf->pro) {
|
data/ext/ox/sax_has.h
CHANGED
@@ -35,6 +35,7 @@ typedef struct _Has {
|
|
35
35
|
int instruct;
|
36
36
|
int end_instruct;
|
37
37
|
int attr;
|
38
|
+
int attrs_done;
|
38
39
|
int attr_value;
|
39
40
|
int doctype;
|
40
41
|
int comment;
|
@@ -70,6 +71,7 @@ has_init(Has has, VALUE handler) {
|
|
70
71
|
has->end_instruct = respond_to(handler, ox_end_instruct_id);
|
71
72
|
has->attr = respond_to(handler, ox_attr_id);
|
72
73
|
has->attr_value = respond_to(handler, ox_attr_value_id);
|
74
|
+
has->attrs_done = respond_to(handler, ox_attrs_done_id);
|
73
75
|
has->doctype = respond_to(handler, ox_doctype_id);
|
74
76
|
has->comment = respond_to(handler, ox_comment_id);
|
75
77
|
has->cdata = respond_to(handler, ox_cdata_id);
|
data/ext/ox/sax_stack.h
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
|
34
34
|
#include "sax_hint.h"
|
35
35
|
|
36
|
-
#define STACK_INC
|
36
|
+
#define STACK_INC 32
|
37
37
|
|
38
38
|
typedef struct _Nv {
|
39
39
|
const char *name;
|
@@ -57,7 +57,7 @@ stack_init(NStack stack) {
|
|
57
57
|
|
58
58
|
inline static int
|
59
59
|
stack_empty(NStack stack) {
|
60
|
-
return (stack->head == stack->
|
60
|
+
return (stack->head == stack->tail);
|
61
61
|
}
|
62
62
|
|
63
63
|
inline static void
|
@@ -77,7 +77,7 @@ stack_push(NStack stack, const char *name, VALUE val, Hint hint) {
|
|
77
77
|
stack->head = ALLOC_N(struct _Nv, len + STACK_INC);
|
78
78
|
memcpy(stack->head, stack->base, sizeof(struct _Nv) * len);
|
79
79
|
} else {
|
80
|
-
|
80
|
+
REALLOC_N(stack->head, struct _Nv, len + STACK_INC);
|
81
81
|
}
|
82
82
|
stack->tail = stack->head + toff;
|
83
83
|
stack->end = stack->head + len + STACK_INC;
|
data/ext/ox/type.h
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
/* type.h
|
2
|
+
* Copyright (c) 2011, Peter Ohler
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
7
|
+
*
|
8
|
+
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
+
* list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
* this list of conditions and the following disclaimer in the documentation
|
13
|
+
* and/or other materials provided with the distribution.
|
14
|
+
*
|
15
|
+
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
+
* used to endorse or promote products derived from this software without
|
17
|
+
* specific prior written permission.
|
18
|
+
*
|
19
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
#ifndef __OX_TYPE_H__
|
32
|
+
#define __OX_TYPE_H__
|
33
|
+
|
34
|
+
typedef enum {
|
35
|
+
NoCode = 0,
|
36
|
+
ArrayCode = 'a',
|
37
|
+
String64Code = 'b', /* base64 encoded String */
|
38
|
+
ClassCode = 'c',
|
39
|
+
Symbol64Code = 'd', /* base64 encoded Symbol */
|
40
|
+
DateCode = 'D',
|
41
|
+
ExceptionCode = 'e',
|
42
|
+
FloatCode = 'f',
|
43
|
+
RegexpCode = 'g',
|
44
|
+
HashCode = 'h',
|
45
|
+
FixnumCode = 'i',
|
46
|
+
BignumCode = 'j',
|
47
|
+
KeyCode = 'k', /* indicates the value is a hash key, kind of a hack */
|
48
|
+
RationalCode = 'l',
|
49
|
+
SymbolCode = 'm',
|
50
|
+
FalseClassCode = 'n',
|
51
|
+
ObjectCode = 'o',
|
52
|
+
RefCode = 'p',
|
53
|
+
RangeCode = 'r',
|
54
|
+
StringCode = 's',
|
55
|
+
TimeCode = 't',
|
56
|
+
StructCode = 'u',
|
57
|
+
ComplexCode = 'v',
|
58
|
+
RawCode = 'x',
|
59
|
+
TrueClassCode = 'y',
|
60
|
+
NilClassCode = 'z',
|
61
|
+
} Type;
|
62
|
+
|
63
|
+
#endif /* __OX_TYPE_H__ */
|
data/lib/ox/sax.rb
CHANGED
@@ -27,14 +27,16 @@ module Ox
|
|
27
27
|
# not be called during parsing. The 'name' argument in the callback methods
|
28
28
|
# will be a Symbol. The 'str' arguments will be a String. The 'value'
|
29
29
|
# arguments will be Ox::Sax::Value objects. Since both the text() and the
|
30
|
-
# value() methods are called for the same element in the XML document the
|
31
|
-
#
|
32
|
-
#
|
30
|
+
# value() methods are called for the same element in the XML document the the
|
31
|
+
# text() method is ignored if the value() method is defined or public. The
|
32
|
+
# same is true for attr() and attr_value(). When all attribtues have been read
|
33
|
+
# the attr_done() callback will be invoked.
|
33
34
|
#
|
34
35
|
# def instruct(target); end
|
35
36
|
# def end_instruct(target); end
|
36
37
|
# def attr(name, str); end
|
37
38
|
# def attr_value(name, value); end
|
39
|
+
# def attrs_done(); end
|
38
40
|
# def doctype(str); end
|
39
41
|
# def comment(str); end
|
40
42
|
# def cdata(str); end
|
@@ -43,9 +45,10 @@ module Ox
|
|
43
45
|
# def start_element(name); end
|
44
46
|
# def end_element(name); end
|
45
47
|
#
|
46
|
-
# Initializing @line in the initializer will cause that variable to be updated
|
47
|
-
#
|
48
|
-
# the
|
48
|
+
# Initializing @line in the initializer will cause that variable to be updated
|
49
|
+
# before each callback with the XML line number. The same is true for the
|
50
|
+
# @column but it will be updated with the column in the XML file that is the
|
51
|
+
# start of the element or node just read.
|
49
52
|
class Sax
|
50
53
|
# Create a new instance of the Sax handler class.
|
51
54
|
def initialize()
|
@@ -70,6 +73,9 @@ module Ox
|
|
70
73
|
def attr_value(name, value)
|
71
74
|
end
|
72
75
|
|
76
|
+
def attrs_done()
|
77
|
+
end
|
78
|
+
|
73
79
|
def doctype(str)
|
74
80
|
end
|
75
81
|
|
data/lib/ox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "A fast XML parser and object serializer that uses only standard C lib.\n
|
14
14
|
\ \nOptimized XML (Ox), as the name implies was written to provide speed
|
@@ -35,21 +35,26 @@ files:
|
|
35
35
|
- lib/ox/version.rb
|
36
36
|
- lib/ox.rb
|
37
37
|
- ext/ox/extconf.rb
|
38
|
+
- ext/ox/attr.h
|
38
39
|
- ext/ox/base64.h
|
39
40
|
- ext/ox/cache.h
|
40
41
|
- ext/ox/cache8.h
|
42
|
+
- ext/ox/err.h
|
43
|
+
- ext/ox/helper.h
|
41
44
|
- ext/ox/ox.h
|
42
45
|
- ext/ox/sax.h
|
43
46
|
- ext/ox/sax_buf.h
|
44
47
|
- ext/ox/sax_has.h
|
45
48
|
- ext/ox/sax_hint.h
|
46
49
|
- ext/ox/sax_stack.h
|
50
|
+
- ext/ox/type.h
|
47
51
|
- ext/ox/base64.c
|
48
52
|
- ext/ox/cache.c
|
49
53
|
- ext/ox/cache8.c
|
50
54
|
- ext/ox/cache8_test.c
|
51
55
|
- ext/ox/cache_test.c
|
52
56
|
- ext/ox/dump.c
|
57
|
+
- ext/ox/err.c
|
53
58
|
- ext/ox/gen_load.c
|
54
59
|
- ext/ox/obj_load.c
|
55
60
|
- ext/ox/ox.c
|
@@ -82,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
87
|
version: '0'
|
83
88
|
requirements: []
|
84
89
|
rubyforge_project: ox
|
85
|
-
rubygems_version: 2.0.
|
90
|
+
rubygems_version: 2.0.2
|
86
91
|
signing_key:
|
87
92
|
specification_version: 4
|
88
93
|
summary: A fast XML parser and object serializer.
|
89
94
|
test_files: []
|
90
|
-
has_rdoc: true
|