ox 2.14.13 → 2.14.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +1 -1
- data/ext/ox/attr.h +33 -39
- data/ext/ox/base64.c +48 -42
- data/ext/ox/base64.h +4 -4
- data/ext/ox/buf.h +80 -86
- data/ext/ox/builder.c +378 -423
- data/ext/ox/cache.c +2 -2
- data/ext/ox/cache8.c +37 -40
- data/ext/ox/cache8.h +7 -7
- data/ext/ox/dump.c +838 -867
- data/ext/ox/err.c +16 -13
- data/ext/ox/err.h +11 -12
- data/ext/ox/extconf.rb +5 -5
- data/ext/ox/gen_load.c +135 -137
- data/ext/ox/hash_load.c +130 -148
- data/ext/ox/helper.h +32 -39
- data/ext/ox/intern.c +1 -2
- data/ext/ox/obj_load.c +590 -644
- data/ext/ox/ox.c +2 -2
- data/ext/ox/ox.h +5 -5
- data/ext/ox/parse.c +836 -874
- data/ext/ox/sax.c +38 -23
- data/ext/ox/sax.h +2 -2
- data/ext/ox/sax_as.c +78 -94
- data/ext/ox/sax_buf.c +85 -94
- data/ext/ox/sax_buf.h +101 -120
- data/ext/ox/sax_hint.c +175 -184
- data/ext/ox/sax_hint.h +19 -19
- data/ext/ox/sax_stack.h +59 -45
- data/ext/ox/slotcache.c +2 -2
- data/ext/ox/slotcache.h +4 -4
- data/ext/ox/special.c +320 -327
- data/ext/ox/special.h +2 -2
- data/ext/ox/type.h +19 -19
- data/lib/ox/bag.rb +13 -9
- data/lib/ox/cdata.rb +0 -2
- data/lib/ox/comment.rb +0 -2
- data/lib/ox/doctype.rb +0 -2
- data/lib/ox/document.rb +3 -5
- data/lib/ox/element.rb +41 -26
- data/lib/ox/error.rb +0 -3
- data/lib/ox/hasattrs.rb +7 -8
- data/lib/ox/instruct.rb +4 -6
- data/lib/ox/node.rb +3 -4
- data/lib/ox/raw.rb +0 -2
- data/lib/ox/sax.rb +20 -36
- data/lib/ox/version.rb +1 -2
- data/lib/ox/xmlrpc_adapter.rb +4 -6
- data/lib/ox.rb +15 -16
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 673ab7acb7140b9e29888304ab457c13558c2f774dbd4364d1899349b6f68210
|
4
|
+
data.tar.gz: 7eebc70a320a14359ba774c22700764916fd1b3399b1e3bf9e555e43f1643a5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6019b22adf12fe6390280281705552a171c62e5863f74281f658ceb1743401f429b9324716bbb7eaa96a79ea06f1d8a1f205c8706fb00685c3fe45bdeed00f9d
|
7
|
+
data.tar.gz: f64209e6be760b0f6a1606c7ecbcbd51769ddd70bc908b21b1b935ab99ce5ba9f7049015171f7b9fd6ec2801d20823b40b5546a80d1736ce84ddfa7a2acb7278
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
All changes to the Ox gem are documented here. Releases follow semantic versioning.
|
4
4
|
|
5
|
+
## [2.14.15] - 2023-04-10
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- Fixed free on moved pointer.
|
10
|
+
|
11
|
+
## [2.14.14] - 2023-01-26
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
- Change free to xfree on ruby alloced memory.
|
16
|
+
|
5
17
|
## [2.14.13] - 2023-01-16
|
6
18
|
|
7
19
|
### Fixed
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Ox gem
|
2
2
|
A fast XML parser and Object marshaller as a Ruby gem.
|
3
3
|
|
4
|
-
[![
|
4
|
+
[![CI](https://github.com/ohler55/ox/actions/workflows/CI.yml/badge.svg)](https://github.com/ohler55/ox/actions/workflows/CI.yml)
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
gem install ox
|
data/ext/ox/attr.h
CHANGED
@@ -6,77 +6,71 @@
|
|
6
6
|
#ifndef OX_ATTR_H
|
7
7
|
#define OX_ATTR_H
|
8
8
|
|
9
|
-
#include
|
9
|
+
#include <ruby.h>
|
10
10
|
|
11
|
-
#define ATTR_STACK_INC
|
11
|
+
#define ATTR_STACK_INC 8
|
12
12
|
|
13
13
|
typedef struct _attr {
|
14
|
-
const char
|
15
|
-
const char
|
14
|
+
const char *name;
|
15
|
+
const char *value;
|
16
16
|
} *Attr;
|
17
17
|
|
18
18
|
typedef struct _attrStack {
|
19
|
-
struct _attr
|
20
|
-
Attr
|
21
|
-
Attr
|
22
|
-
Attr
|
19
|
+
struct _attr base[ATTR_STACK_INC];
|
20
|
+
Attr head; /* current stack */
|
21
|
+
Attr end; /* stack end */
|
22
|
+
Attr tail; /* pointer to one past last element name on stack */
|
23
23
|
} *AttrStack;
|
24
24
|
|
25
|
-
inline static void
|
26
|
-
|
27
|
-
stack->
|
28
|
-
stack->
|
29
|
-
stack->tail = stack->head;
|
25
|
+
inline static void attr_stack_init(AttrStack stack) {
|
26
|
+
stack->head = stack->base;
|
27
|
+
stack->end = stack->base + sizeof(stack->base) / sizeof(struct _attr);
|
28
|
+
stack->tail = stack->head;
|
30
29
|
stack->head->name = 0;
|
31
30
|
}
|
32
31
|
|
33
|
-
inline static int
|
34
|
-
attr_stack_empty(AttrStack stack) {
|
32
|
+
inline static int attr_stack_empty(AttrStack stack) {
|
35
33
|
return (stack->head == stack->tail);
|
36
34
|
}
|
37
35
|
|
38
|
-
inline static void
|
39
|
-
attr_stack_cleanup(AttrStack stack) {
|
36
|
+
inline static void attr_stack_cleanup(AttrStack stack) {
|
40
37
|
if (stack->base != stack->head) {
|
41
38
|
xfree(stack->head);
|
42
|
-
|
39
|
+
stack->head = stack->base;
|
43
40
|
}
|
44
41
|
}
|
45
42
|
|
46
|
-
inline static void
|
47
|
-
attr_stack_push(AttrStack stack, const char *name, const char *value) {
|
43
|
+
inline static void attr_stack_push(AttrStack stack, const char *name, const char *value) {
|
48
44
|
if (stack->end <= stack->tail + 1) {
|
49
|
-
|
50
|
-
|
45
|
+
size_t len = stack->end - stack->head;
|
46
|
+
size_t toff = stack->tail - stack->head;
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
48
|
+
if (stack->base == stack->head) {
|
49
|
+
stack->head = ALLOC_N(struct _attr, len + ATTR_STACK_INC);
|
50
|
+
memcpy(stack->head, stack->base, sizeof(struct _attr) * len);
|
51
|
+
} else {
|
52
|
+
REALLOC_N(stack->head, struct _attr, len + ATTR_STACK_INC);
|
53
|
+
}
|
54
|
+
stack->tail = stack->head + toff;
|
55
|
+
stack->end = stack->head + len + ATTR_STACK_INC;
|
60
56
|
}
|
61
|
-
stack->tail->name
|
57
|
+
stack->tail->name = name;
|
62
58
|
stack->tail->value = value;
|
63
59
|
stack->tail++;
|
64
|
-
stack->tail->name = 0;
|
60
|
+
stack->tail->name = 0; // terminate
|
65
61
|
}
|
66
62
|
|
67
|
-
inline static Attr
|
68
|
-
attr_stack_peek(AttrStack stack) {
|
63
|
+
inline static Attr attr_stack_peek(AttrStack stack) {
|
69
64
|
if (stack->head < stack->tail) {
|
70
|
-
|
65
|
+
return stack->tail - 1;
|
71
66
|
}
|
72
67
|
return 0;
|
73
68
|
}
|
74
69
|
|
75
|
-
inline static Attr
|
76
|
-
attr_stack_pop(AttrStack stack) {
|
70
|
+
inline static Attr attr_stack_pop(AttrStack stack) {
|
77
71
|
if (stack->head < stack->tail) {
|
78
|
-
|
79
|
-
|
72
|
+
stack->tail--;
|
73
|
+
return stack->tail;
|
80
74
|
}
|
81
75
|
return 0;
|
82
76
|
}
|
data/ext/ox/base64.c
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#include <stdlib.h>
|
7
|
-
#include <stdio.h>
|
8
|
-
|
9
6
|
#include "base64.h"
|
10
7
|
|
11
|
-
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
|
11
|
+
static char digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
12
12
|
|
13
13
|
/* invalid or terminating characters are set to 'X' or \x58 */
|
14
|
-
static uchar
|
14
|
+
static uchar s_digits[256] = "\
|
15
15
|
\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\
|
16
16
|
\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\
|
17
17
|
\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x3E\x58\x58\x58\x3F\
|
@@ -29,46 +29,45 @@ static uchar s_digits[256] = "\
|
|
29
29
|
\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\
|
30
30
|
\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58";
|
31
31
|
|
32
|
-
void
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
void to_base64(const uchar *src, int len, char *b64) {
|
33
|
+
const uchar *end3;
|
34
|
+
int len3 = len % 3;
|
35
|
+
uchar b1, b2, b3;
|
36
|
+
|
38
37
|
end3 = src + (len - len3);
|
39
38
|
while (src < end3) {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
b1 = *src++;
|
40
|
+
b2 = *src++;
|
41
|
+
b3 = *src++;
|
42
|
+
*b64++ = digits[(uchar)(b1 >> 2)];
|
43
|
+
*b64++ = digits[(uchar)(((b1 & 0x03) << 4) | (b2 >> 4))];
|
44
|
+
*b64++ = digits[(uchar)(((b2 & 0x0F) << 2) | (b3 >> 6))];
|
45
|
+
*b64++ = digits[(uchar)(b3 & 0x3F)];
|
47
46
|
}
|
48
47
|
if (1 == len3) {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
b1 = *src++;
|
49
|
+
*b64++ = digits[b1 >> 2];
|
50
|
+
*b64++ = digits[(b1 & 0x03) << 4];
|
51
|
+
*b64++ = '=';
|
52
|
+
*b64++ = '=';
|
54
53
|
} else if (2 == len3) {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
b1 = *src++;
|
55
|
+
b2 = *src++;
|
56
|
+
*b64++ = digits[b1 >> 2];
|
57
|
+
*b64++ = digits[((b1 & 0x03) << 4) | (b2 >> 4)];
|
58
|
+
*b64++ = digits[(b2 & 0x0F) << 2];
|
59
|
+
*b64++ = '=';
|
61
60
|
}
|
62
61
|
*b64 = '\0';
|
63
62
|
}
|
64
63
|
|
65
|
-
unsigned long
|
66
|
-
|
67
|
-
|
68
|
-
unsigned long size = 0;
|
64
|
+
unsigned long b64_orig_size(const char *text) {
|
65
|
+
const char *start = text;
|
66
|
+
unsigned long size = 0;
|
69
67
|
|
70
68
|
if ('\0' != *text) {
|
71
|
-
for (; 0 != *text; text++) {
|
69
|
+
for (; 0 != *text; text++) {
|
70
|
+
}
|
72
71
|
size = (text - start) * 3 / 4;
|
73
72
|
text--;
|
74
73
|
if ('=' == *text) {
|
@@ -82,17 +81,24 @@ b64_orig_size(const char *text) {
|
|
82
81
|
return size;
|
83
82
|
}
|
84
83
|
|
85
|
-
void
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
void from_base64(const char *b64, uchar *str) {
|
85
|
+
uchar b0, b1, b2, b3;
|
86
|
+
|
89
87
|
while (1) {
|
90
|
-
if ('X' == (b0 = s_digits[(uchar)*b64++])) {
|
91
|
-
|
88
|
+
if ('X' == (b0 = s_digits[(uchar)*b64++])) {
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
if ('X' == (b1 = s_digits[(uchar)*b64++])) {
|
92
|
+
break;
|
93
|
+
}
|
92
94
|
*str++ = (b0 << 2) | ((b1 >> 4) & 0x03);
|
93
|
-
if ('X' == (b2 = s_digits[(uchar)*b64++])) {
|
95
|
+
if ('X' == (b2 = s_digits[(uchar)*b64++])) {
|
96
|
+
break;
|
97
|
+
}
|
94
98
|
*str++ = (b1 << 4) | ((b2 >> 2) & 0x0F);
|
95
|
-
if ('X' == (b3 = s_digits[(uchar)*b64++])) {
|
99
|
+
if ('X' == (b3 = s_digits[(uchar)*b64++])) {
|
100
|
+
break;
|
101
|
+
}
|
96
102
|
*str++ = (b2 << 6) | b3;
|
97
103
|
}
|
98
104
|
*str = '\0';
|
data/ext/ox/base64.h
CHANGED
@@ -6,13 +6,13 @@
|
|
6
6
|
#ifndef BASE64_H
|
7
7
|
#define BASE64_H
|
8
8
|
|
9
|
-
typedef unsigned char
|
9
|
+
typedef unsigned char uchar;
|
10
10
|
|
11
11
|
#define b64_size(len) ((len + 2) / 3 * 4)
|
12
12
|
|
13
|
-
extern unsigned long
|
13
|
+
extern unsigned long b64_orig_size(const char *text);
|
14
14
|
|
15
|
-
extern void
|
16
|
-
extern void
|
15
|
+
extern void to_base64(const uchar *src, int len, char *b64);
|
16
|
+
extern void from_base64(const char *b64, uchar *str);
|
17
17
|
|
18
18
|
#endif /* BASE64_H */
|
data/ext/ox/buf.h
CHANGED
@@ -31,137 +31,131 @@
|
|
31
31
|
#ifndef OX_BUF_H
|
32
32
|
#define OX_BUF_H
|
33
33
|
|
34
|
+
#include <ruby.h>
|
34
35
|
#include <stdbool.h>
|
35
36
|
#include <unistd.h>
|
36
37
|
|
37
38
|
typedef struct _buf {
|
38
|
-
char
|
39
|
-
char
|
40
|
-
char
|
41
|
-
int
|
42
|
-
bool
|
43
|
-
char
|
39
|
+
char *head;
|
40
|
+
char *end;
|
41
|
+
char *tail;
|
42
|
+
int fd;
|
43
|
+
bool err;
|
44
|
+
char base[16384];
|
44
45
|
} *Buf;
|
45
46
|
|
46
|
-
inline static void
|
47
|
-
buf_init(Buf buf, int fd, long initial_size) {
|
47
|
+
inline static void buf_init(Buf buf, int fd, long initial_size) {
|
48
48
|
if (sizeof(buf->base) < (size_t)initial_size) {
|
49
|
-
|
50
|
-
|
49
|
+
buf->head = ALLOC_N(char, initial_size);
|
50
|
+
buf->end = buf->head + initial_size - 1;
|
51
51
|
} else {
|
52
|
-
|
53
|
-
|
52
|
+
buf->head = buf->base;
|
53
|
+
buf->end = buf->base + sizeof(buf->base) - 1;
|
54
54
|
}
|
55
55
|
buf->tail = buf->head;
|
56
|
-
buf->fd
|
57
|
-
buf->err
|
56
|
+
buf->fd = fd;
|
57
|
+
buf->err = false;
|
58
58
|
}
|
59
59
|
|
60
|
-
inline static void
|
61
|
-
buf_reset(Buf buf) {
|
60
|
+
inline static void buf_reset(Buf buf) {
|
62
61
|
buf->head = buf->base;
|
63
62
|
buf->tail = buf->head;
|
64
63
|
}
|
65
64
|
|
66
|
-
inline static void
|
67
|
-
buf_cleanup(Buf buf) {
|
65
|
+
inline static void buf_cleanup(Buf buf) {
|
68
66
|
if (buf->base != buf->head) {
|
69
67
|
free(buf->head);
|
70
68
|
}
|
71
69
|
}
|
72
70
|
|
73
|
-
inline static size_t
|
74
|
-
buf_len(Buf buf) {
|
71
|
+
inline static size_t buf_len(Buf buf) {
|
75
72
|
return buf->tail - buf->head;
|
76
73
|
}
|
77
74
|
|
78
|
-
inline static void
|
79
|
-
buf_append_string(Buf buf, const char *s, size_t slen) {
|
75
|
+
inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
|
80
76
|
if (buf->err) {
|
81
|
-
|
77
|
+
return;
|
82
78
|
}
|
83
79
|
if (buf->end <= buf->tail + slen) {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
80
|
+
if (0 != buf->fd) {
|
81
|
+
size_t len = buf->tail - buf->head;
|
82
|
+
|
83
|
+
if (len != (size_t)write(buf->fd, buf->head, len)) {
|
84
|
+
buf->err = true;
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
buf->tail = buf->head;
|
88
|
+
if (sizeof(buf->base) <= slen) {
|
89
|
+
if (slen != (size_t)write(buf->fd, s, slen)) {
|
90
|
+
buf->err = true;
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
size_t len = buf->end - buf->head;
|
97
|
+
size_t toff = buf->tail - buf->head;
|
98
|
+
size_t new_len = len + slen + len / 2;
|
99
|
+
|
100
|
+
if (buf->base == buf->head) {
|
101
|
+
buf->head = ALLOC_N(char, new_len);
|
102
|
+
memcpy(buf->head, buf->base, len);
|
103
|
+
} else {
|
104
|
+
REALLOC_N(buf->head, char, new_len);
|
105
|
+
}
|
106
|
+
buf->tail = buf->head + toff;
|
107
|
+
buf->end = buf->head + new_len - 2;
|
108
|
+
}
|
113
109
|
}
|
114
110
|
if (0 < slen) {
|
115
|
-
|
111
|
+
memcpy(buf->tail, s, slen);
|
116
112
|
}
|
117
113
|
buf->tail += slen;
|
118
114
|
}
|
119
115
|
|
120
|
-
inline static void
|
121
|
-
buf_append(Buf buf, char c) {
|
116
|
+
inline static void buf_append(Buf buf, char c) {
|
122
117
|
if (buf->err) {
|
123
|
-
|
118
|
+
return;
|
124
119
|
}
|
125
120
|
if (buf->end <= buf->tail) {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
121
|
+
if (0 != buf->fd) {
|
122
|
+
size_t len = buf->tail - buf->head;
|
123
|
+
|
124
|
+
if (len != (size_t)write(buf->fd, buf->head, len)) {
|
125
|
+
buf->err = true;
|
126
|
+
}
|
127
|
+
buf->tail = buf->head;
|
128
|
+
} else {
|
129
|
+
size_t len = buf->end - buf->head;
|
130
|
+
size_t toff = buf->tail - buf->head;
|
131
|
+
size_t new_len = len + len / 2;
|
132
|
+
|
133
|
+
if (buf->base == buf->head) {
|
134
|
+
buf->head = ALLOC_N(char, new_len);
|
135
|
+
memcpy(buf->head, buf->base, len);
|
136
|
+
} else {
|
137
|
+
REALLOC_N(buf->head, char, new_len);
|
138
|
+
}
|
139
|
+
buf->tail = buf->head + toff;
|
140
|
+
buf->end = buf->head + new_len - 2;
|
141
|
+
}
|
147
142
|
}
|
148
143
|
*buf->tail++ = c;
|
149
144
|
//*buf->tail = '\0'; // for debugging
|
150
145
|
}
|
151
146
|
|
152
|
-
inline static void
|
153
|
-
buf_finish(Buf buf) {
|
147
|
+
inline static void buf_finish(Buf buf) {
|
154
148
|
if (buf->err) {
|
155
|
-
|
149
|
+
return;
|
156
150
|
}
|
157
151
|
if (0 != buf->fd) {
|
158
|
-
|
152
|
+
size_t len = buf->tail - buf->head;
|
159
153
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
154
|
+
if (0 < len && len != (size_t)write(buf->fd, buf->head, len)) {
|
155
|
+
buf->err = true;
|
156
|
+
}
|
157
|
+
fsync(buf->fd);
|
158
|
+
buf->tail = buf->head;
|
165
159
|
}
|
166
160
|
}
|
167
161
|
|