ox 2.14.29 → 2.14.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/ext/ox/builder.c +6 -4
- data/ext/ox/cache.c +54 -45
- data/ext/ox/dump.c +39 -23
- data/ext/ox/extconf.rb +0 -3
- data/ext/ox/hash_load.c +42 -59
- data/ext/ox/intern.c +1 -1
- data/ext/ox/obj_load.c +78 -14
- data/ext/ox/ox.c +24 -17
- data/ext/ox/ox.h +2 -3
- data/ext/ox/parse.c +41 -9
- data/ext/ox/sax.c +47 -3
- data/ext/ox/sax_as.c +55 -21
- data/ext/ox/sax_buf.c +53 -22
- data/ext/ox/sax_buf.h +1 -0
- data/ext/ox/special.c +24 -0
- data/ext/ox/special.h +2 -0
- data/ext/ox/time_conv.h +57 -0
- data/lib/ox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3cc57e4626ab0b4e7a04bf5143c7f82830a3a901e2dd1266f4f8d3a269a30252
|
|
4
|
+
data.tar.gz: d3dfce324cb136e623faab1cf24e9304adadea01fa4aebbf11680cfdc6662a3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d318fb77496faa6993b5e70357c582ef015a051a7476f257fcfbb747e1b892446a7d5bcef8a7b082aaea484b60b56866aa999feb166ef3e8e029f5990cea959d
|
|
7
|
+
data.tar.gz: 540a460ad876d0b18493298d175f91c660e726a1a11a3c4a2a99ff0f081344282788f073d7bb4936b33a86d005be0932455887a907d04d61f4f333ff2261ae31
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
All changes to the Ox gem are documented here. Releases follow semantic versioning.
|
|
4
4
|
|
|
5
|
+
## [2.14.30] - 2026-11-25
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Speed up Ox.sax_parse by not rescanning the String on each refill. See PR #472.
|
|
10
|
+
- Speed up Ox.load in hash mode by keeping the marked arrays in a table. See PR #473.
|
|
11
|
+
- Speed up hash_no_attrs mode by interning element names directly. See PR #474.
|
|
12
|
+
- Speed up hash mode by interning element names directly. See PR #475.
|
|
13
|
+
- Added Ruby 4.0 and ARM64 runners to the CI test matrix. See PR #492.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Skip the Ruby 2.7, 3.0 and 3.1 CI jobs on Ubuntu. See PR #477.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Fix an exception from the SAX input IO coming back as a TypeError. See PR #476.
|
|
22
|
+
- Fix slow parsing of names built to collide in the name cache. See PR #478.
|
|
23
|
+
- Fix object mode dumps of raised exceptions and Range subclasses. See PR #479.
|
|
24
|
+
- Fix out-of-bounds read in structname2obj on a trailing colon. See PR #480.
|
|
25
|
+
- Fix signed overflow reading long digit strings in as_i, `<i>` and `<t>`. See PR #481.
|
|
26
|
+
- Fix use-after-free of element names deeper than 32 in ox_sax_parse. See PR #482.
|
|
27
|
+
- Fix the circular reference table not being marked in mark_pi_cb. See PR #483.
|
|
28
|
+
- Fix a leak of the document copy in Ox.load when the parse raises. See PR #484.
|
|
29
|
+
- Fix use-after-free of the SAX drive through a kept Ox::Sax::Value. See PR #485.
|
|
30
|
+
- Fix stack buffer overflow in add_element :trace output. See PR #486.
|
|
31
|
+
- Fix a character reference to NUL cutting off the rest of the value. See PR #487.
|
|
32
|
+
- Fix read_element over-read on a tolerant unquoted attribute value. See PR #488.
|
|
33
|
+
- Fix a leak of the name of an empty element in Ox::Builder pop. See PR #489.
|
|
34
|
+
- Fix Ox::Sax::Value#as_s decoding the value again on each call. See PR #490.
|
|
35
|
+
- Fix Time conversion on 32-bit time_t builds. See PR #493.
|
|
36
|
+
- Fix use-after-free of a popped element in hash mode end_element. See PR #494.
|
|
37
|
+
- Fix out-of-bounds read in form_attr interning the stack buffer. See PR #495.
|
|
38
|
+
- Fix read_element over-read on a tolerant end tag cut off before its '>'. See PR #496.
|
|
39
|
+
- Fix read_instruction over-read on an instruction ending in '?' with no '>'. See PR #497.
|
|
40
|
+
|
|
5
41
|
## [2.14.29] - 2026-07-08
|
|
6
42
|
|
|
7
43
|
### Added
|
data/ext/ox/builder.c
CHANGED
|
@@ -403,15 +403,17 @@ static void pop(Builder b) {
|
|
|
403
403
|
// and the ">".
|
|
404
404
|
b->col += 3;
|
|
405
405
|
b->pos += 3;
|
|
406
|
-
if (e->buf != e->name) {
|
|
407
|
-
free(e->name);
|
|
408
|
-
e->name = 0;
|
|
409
|
-
}
|
|
410
406
|
} else {
|
|
411
407
|
buf_append_string(&b->buf, "/>", 2);
|
|
412
408
|
b->col += 2;
|
|
413
409
|
b->pos += 2;
|
|
414
410
|
}
|
|
411
|
+
// A name too long for the inline buffer was strdup'd, and an element closed
|
|
412
|
+
// with "/>" owns that copy just as much as one with children.
|
|
413
|
+
if (e->buf != e->name) {
|
|
414
|
+
free(e->name);
|
|
415
|
+
e->name = 0;
|
|
416
|
+
}
|
|
415
417
|
}
|
|
416
418
|
|
|
417
419
|
static void bclose(Builder b) {
|
data/ext/ox/cache.c
CHANGED
|
@@ -24,24 +24,34 @@
|
|
|
24
24
|
#define CACHE_UNLOCK(c) rb_mutex_unlock((c)->mutex)
|
|
25
25
|
#endif
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
#define
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
|
|
28
|
+
#define SIPROUND \
|
|
29
|
+
do { \
|
|
30
|
+
v0 += v1; \
|
|
31
|
+
v1 = ROTL(v1, 13); \
|
|
32
|
+
v1 ^= v0; \
|
|
33
|
+
v0 = ROTL(v0, 32); \
|
|
34
|
+
v2 += v3; \
|
|
35
|
+
v3 = ROTL(v3, 16); \
|
|
36
|
+
v3 ^= v2; \
|
|
37
|
+
v0 += v3; \
|
|
38
|
+
v3 = ROTL(v3, 21); \
|
|
39
|
+
v3 ^= v0; \
|
|
40
|
+
v2 += v1; \
|
|
41
|
+
v1 = ROTL(v1, 17); \
|
|
42
|
+
v1 ^= v2; \
|
|
43
|
+
v2 = ROTL(v2, 32); \
|
|
44
|
+
} while (0)
|
|
45
|
+
|
|
46
|
+
static uint64_t hash_key[2];
|
|
35
47
|
|
|
36
48
|
void ox_hash_seed_init(void) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
hash_seed = (uint64_t)(int64_t)NUM2LL(rb_funcall(rb_str_new_literal("ox"), rb_intern("hash"), 0));
|
|
44
|
-
#endif
|
|
49
|
+
VALUE seed = rb_funcall(rb_cRandom, rb_intern("new_seed"), 0);
|
|
50
|
+
VALUE mask = ULL2NUM(UINT64_MAX);
|
|
51
|
+
|
|
52
|
+
hash_key[0] = NUM2ULL(rb_funcall(seed, rb_intern("&"), 1, mask)) ^ (uint64_t)rb_memhash("ox0", 3);
|
|
53
|
+
hash_key[1] = NUM2ULL(rb_funcall(rb_funcall(seed, rb_intern(">>"), 1, INT2FIX(64)), rb_intern("&"), 1, mask)) ^
|
|
54
|
+
(uint64_t)rb_memhash("ox1", 3);
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
typedef struct _slot {
|
|
@@ -83,37 +93,36 @@ const rb_data_type_t ox_cache_type = {
|
|
|
83
93
|
};
|
|
84
94
|
|
|
85
95
|
static uint64_t hash_calc(const uint8_t *key, size_t len) {
|
|
86
|
-
const uint8_t *end
|
|
87
|
-
|
|
88
|
-
uint64_t
|
|
89
|
-
uint64_t
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
uint16_t k16 = (uint16_t)*key++;
|
|
104
|
-
|
|
105
|
-
k16 |= (uint16_t)*key++ << 8;
|
|
106
|
-
h ^= k16 << 8;
|
|
96
|
+
const uint8_t *end = key + (len & ~(size_t)7);
|
|
97
|
+
uint64_t v0 = 0x736f6d6570736575ULL ^ hash_key[0];
|
|
98
|
+
uint64_t v1 = 0x646f72616e646f6dULL ^ hash_key[1];
|
|
99
|
+
uint64_t v2 = 0x6c7967656e657261ULL ^ hash_key[0];
|
|
100
|
+
uint64_t v3 = 0x7465646279746573ULL ^ hash_key[1];
|
|
101
|
+
uint64_t b = (uint64_t)len << 56;
|
|
102
|
+
uint64_t m;
|
|
103
|
+
size_t i;
|
|
104
|
+
|
|
105
|
+
for (; key < end; key += 8) {
|
|
106
|
+
m = 0;
|
|
107
|
+
for (i = 0; i < 8; i++) {
|
|
108
|
+
m |= (uint64_t)key[i] << (8 * i);
|
|
109
|
+
}
|
|
110
|
+
v3 ^= m;
|
|
111
|
+
SIPROUND;
|
|
112
|
+
v0 ^= m;
|
|
107
113
|
}
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
for (i = 0; i < (len & 7); i++) {
|
|
115
|
+
b |= (uint64_t)key[i] << (8 * i);
|
|
110
116
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
v3 ^= b;
|
|
118
|
+
SIPROUND;
|
|
119
|
+
v0 ^= b;
|
|
120
|
+
v2 ^= 0xff;
|
|
121
|
+
SIPROUND;
|
|
122
|
+
SIPROUND;
|
|
123
|
+
SIPROUND;
|
|
124
|
+
|
|
125
|
+
return v0 ^ v1 ^ v2 ^ v3;
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
static void rehash(Cache c) {
|
data/ext/ox/dump.c
CHANGED
|
@@ -477,16 +477,18 @@ inline static void dump_num(Out out, VALUE obj) {
|
|
|
477
477
|
}
|
|
478
478
|
|
|
479
479
|
static void dump_time_thin(Out out, VALUE obj) {
|
|
480
|
-
char
|
|
481
|
-
char
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
480
|
+
char buf[64];
|
|
481
|
+
char *b = buf + sizeof(buf) - 1;
|
|
482
|
+
ox_time_t sec;
|
|
483
|
+
long nsec;
|
|
484
|
+
char *dot = b - 10;
|
|
485
|
+
long size;
|
|
486
|
+
bool neg;
|
|
487
|
+
|
|
488
|
+
ox_time_split(obj, &sec, &nsec);
|
|
489
|
+
neg = 0 > sec;
|
|
490
|
+
|
|
491
|
+
// nsec is never negative, so a time before the epoch is a negative
|
|
490
492
|
// second count carrying a positive fraction. Writing those two out as they
|
|
491
493
|
// are would read as -1.5 for what is really -0.5, so move the fraction over
|
|
492
494
|
// and write the magnitude with a sign in front of it.
|
|
@@ -503,7 +505,7 @@ static void dump_time_thin(Out out, VALUE obj) {
|
|
|
503
505
|
*b-- = '0';
|
|
504
506
|
} else if (neg) {
|
|
505
507
|
// sec is left negative instead of negated so that the most negative
|
|
506
|
-
//
|
|
508
|
+
// ox_time_t does not overflow. C truncates the quotient toward zero, so
|
|
507
509
|
// the remainder carries the sign with it.
|
|
508
510
|
for (; 0 != sec; b--, sec /= 10) {
|
|
509
511
|
*b = (char)('0' - sec % 10);
|
|
@@ -552,17 +554,17 @@ static void dump_date(Out out, VALUE obj) {
|
|
|
552
554
|
}
|
|
553
555
|
|
|
554
556
|
static void dump_time_xsd(Out out, VALUE obj) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
long
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
557
|
+
ox_time_t sec;
|
|
558
|
+
long nsec;
|
|
559
|
+
long offset = NUM2LONG(rb_funcall2(obj, ox_utc_offset_id, 0, 0));
|
|
560
|
+
int tzhour, tzmin;
|
|
561
|
+
char tzsign = '+';
|
|
562
|
+
long long year;
|
|
563
|
+
int mon, day, hour, min, tsec;
|
|
564
|
+
char buf[64];
|
|
565
|
+
int cnt;
|
|
566
|
+
|
|
567
|
+
ox_time_split(obj, &sec, &nsec);
|
|
566
568
|
/* 2010-07-09T10:47:45.895826+09:00 */
|
|
567
569
|
// The offset comes from the Time rather than from localtime(), which has no
|
|
568
570
|
// tm_gmtoff in the Microsoft CRT and so wrote +00:00 next to a local wall
|
|
@@ -586,7 +588,7 @@ static void dump_time_xsd(Out out, VALUE obj) {
|
|
|
586
588
|
/* TBD replace with more efficient printer */
|
|
587
589
|
// A year outside four digits is longer than the sample above, so reserve
|
|
588
590
|
// what was actually formatted instead of a fixed 33. buf can not overflow:
|
|
589
|
-
// the largest
|
|
591
|
+
// the largest ox_time_t puts the year at 12 digits, and the rest of the format
|
|
590
592
|
// is a fixed 28 characters.
|
|
591
593
|
cnt = snprintf(buf,
|
|
592
594
|
sizeof(buf),
|
|
@@ -900,6 +902,14 @@ static void dump_obj(ID aid, VALUE obj, int depth, Out out) {
|
|
|
900
902
|
VALUE v = RSTRUCT_GET(obj, (int)(i));
|
|
901
903
|
dump_obj(rb_intern(ulong2str(i, num_buf + sizeof(num_buf) - 1)), v, d2, out);
|
|
902
904
|
}
|
|
905
|
+
if (2 == cnt && Qtrue == rb_obj_is_kind_of(obj, rb_cRange)) {
|
|
906
|
+
VALUE beg;
|
|
907
|
+
VALUE end;
|
|
908
|
+
int excl;
|
|
909
|
+
|
|
910
|
+
rb_range_values(obj, &beg, &end, &excl);
|
|
911
|
+
dump_obj(rb_intern(ulong2str(i, num_buf + sizeof(num_buf) - 1)), excl ? Qtrue : Qfalse, d2, out);
|
|
912
|
+
}
|
|
903
913
|
out->w_end(out, &e);
|
|
904
914
|
}
|
|
905
915
|
#else
|
|
@@ -1032,6 +1042,12 @@ static int dump_var(ID key, VALUE value, VALUE ov) {
|
|
|
1032
1042
|
* time.
|
|
1033
1043
|
*/
|
|
1034
1044
|
value = rb_funcall(out->obj, ox_message_id, 0);
|
|
1045
|
+
} else if (T_DATA == rb_type(value) && key == rb_intern("bt")) {
|
|
1046
|
+
VALUE m = rb_funcall(rb_eException, rb_intern("instance_method"), 1, ID2SYM(rb_intern("backtrace")));
|
|
1047
|
+
|
|
1048
|
+
value = rb_funcall(m, rb_intern("bind_call"), 1, out->obj);
|
|
1049
|
+
} else if (key == rb_intern("bt_locations")) {
|
|
1050
|
+
return ST_CONTINUE;
|
|
1035
1051
|
}
|
|
1036
1052
|
dump_obj(key, value, out->depth, out);
|
|
1037
1053
|
|
data/ext/ox/extconf.rb
CHANGED
|
@@ -46,9 +46,6 @@ have_func('rb_ext_ractor_safe', 'ruby.h')
|
|
|
46
46
|
have_func('pthread_mutex_init')
|
|
47
47
|
have_func('rb_enc_interned_str')
|
|
48
48
|
have_func('index')
|
|
49
|
-
# Seeds the name cache hash. Not on every implementation, so cache.c falls back
|
|
50
|
-
# to String#hash, which is per process randomized everywhere it matters.
|
|
51
|
-
have_func('rb_hash_start', 'ruby.h')
|
|
52
49
|
|
|
53
50
|
have_header('ruby/st.h')
|
|
54
51
|
have_header('sys/uio.h')
|
data/ext/ox/hash_load.c
CHANGED
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
#include "ox.h"
|
|
14
14
|
#include "ruby.h"
|
|
15
15
|
|
|
16
|
-
#define MARK_INC 256
|
|
17
|
-
|
|
18
16
|
// The approach taken for the hash and has_no_attrs parsing is to push just
|
|
19
17
|
// the key on to the stack and then decide what to do on the way up/out.
|
|
20
18
|
|
|
@@ -27,45 +25,26 @@ static VALUE create_top(PInfo pi) {
|
|
|
27
25
|
return top;
|
|
28
26
|
}
|
|
29
27
|
|
|
28
|
+
// Only membership is ever asked of these. As a list they were walked end to
|
|
29
|
+
// end on every close, which is quadratic in the number of repeated elements
|
|
30
|
+
// that carry attributes, since each of those adds a mark and only one is
|
|
31
|
+
// ever taken back.
|
|
30
32
|
static void mark_value(PInfo pi, VALUE val) {
|
|
31
33
|
if (NULL == pi->marked) {
|
|
32
|
-
pi->marked
|
|
33
|
-
pi->mark_size = MARK_INC;
|
|
34
|
-
} else if (pi->mark_size <= pi->mark_cnt) {
|
|
35
|
-
pi->mark_size += MARK_INC;
|
|
36
|
-
REALLOC_N(pi->marked, VALUE, pi->mark_size);
|
|
34
|
+
pi->marked = st_init_numtable();
|
|
37
35
|
}
|
|
38
|
-
pi->marked
|
|
39
|
-
pi->mark_cnt++;
|
|
36
|
+
st_insert(pi->marked, (st_data_t)val, (st_data_t)1);
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
static bool marked(PInfo pi, VALUE val) {
|
|
43
|
-
|
|
44
|
-
VALUE *vp = pi->marked + pi->mark_cnt - 1;
|
|
45
|
-
|
|
46
|
-
for (; pi->marked <= vp; vp--) {
|
|
47
|
-
if (val == *vp) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
40
|
+
return NULL != pi->marked && 0 != st_lookup(pi->marked, (st_data_t)val, NULL);
|
|
53
41
|
}
|
|
54
42
|
|
|
55
43
|
static void unmark(PInfo pi, VALUE val) {
|
|
56
44
|
if (NULL != pi->marked) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
for (i = 0; pi->marked <= vp; vp--, i++) {
|
|
61
|
-
if (val == *vp) {
|
|
62
|
-
for (; 0 < i; i--, vp++) {
|
|
63
|
-
*vp = *(vp + 1);
|
|
64
|
-
}
|
|
65
|
-
pi->mark_cnt--;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
45
|
+
st_data_t key = (st_data_t)val;
|
|
46
|
+
|
|
47
|
+
st_delete(pi->marked, &key, NULL);
|
|
69
48
|
}
|
|
70
49
|
}
|
|
71
50
|
|
|
@@ -109,10 +88,10 @@ static void add_cdata(PInfo pi, const char *text, size_t len) {
|
|
|
109
88
|
}
|
|
110
89
|
|
|
111
90
|
static void add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
// Keep the name's encoding without allocating a temporary String. Intern
|
|
92
|
+
// after the attributes as before, including any key modifier callbacks.
|
|
93
|
+
rb_encoding *enc = NULL == pi->options->rb_enc ? rb_ascii8bit_encoding() : pi->options->rb_enc;
|
|
94
|
+
|
|
116
95
|
if (helper_stack_empty(&pi->helpers)) {
|
|
117
96
|
create_top(pi);
|
|
118
97
|
}
|
|
@@ -141,21 +120,24 @@ static void add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren
|
|
|
141
120
|
a = rb_ary_new();
|
|
142
121
|
rb_ary_push(a, h);
|
|
143
122
|
mark_value(pi, a);
|
|
144
|
-
helper_stack_push(&pi->helpers,
|
|
123
|
+
helper_stack_push(&pi->helpers, rb_intern3(ename, strlen(ename), enc), a, ArrayCode);
|
|
145
124
|
} else {
|
|
146
|
-
helper_stack_push(&pi->helpers,
|
|
125
|
+
helper_stack_push(&pi->helpers, rb_intern3(ename, strlen(ename), enc), Qnil, NoCode);
|
|
147
126
|
}
|
|
148
127
|
}
|
|
149
128
|
|
|
150
129
|
static void add_element_no_attrs(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
rb_enc_associate(s, pi->options->rb_enc);
|
|
154
|
-
}
|
|
130
|
+
rb_encoding *enc = pi->options->rb_enc;
|
|
131
|
+
|
|
155
132
|
if (helper_stack_empty(&pi->helpers)) {
|
|
156
133
|
create_top(pi);
|
|
157
134
|
}
|
|
158
|
-
|
|
135
|
+
// Intern the name without a temporary String, preserving rb_str_new2's
|
|
136
|
+
// binary encoding when the parser has no encoding set.
|
|
137
|
+
helper_stack_push(&pi->helpers,
|
|
138
|
+
rb_intern3(ename, strlen(ename), NULL == enc ? rb_ascii8bit_encoding() : enc),
|
|
139
|
+
Qnil,
|
|
140
|
+
NoCode);
|
|
159
141
|
}
|
|
160
142
|
|
|
161
143
|
static int umark_hash_cb(VALUE key, VALUE value, VALUE x) {
|
|
@@ -171,10 +153,11 @@ static void end_element_core(PInfo pi, const char *ename, bool check_marked) {
|
|
|
171
153
|
volatile VALUE found = Qundef;
|
|
172
154
|
volatile VALUE key;
|
|
173
155
|
volatile VALUE a;
|
|
156
|
+
// The popped slot is past the tail mark_pi_cb walks, and on the heap once
|
|
157
|
+
// the stack outgrows its base, so hold the value where the GC can see it
|
|
158
|
+
// before anything below allocates.
|
|
159
|
+
volatile VALUE obj = (NoCode == e->type) ? Qnil : e->obj;
|
|
174
160
|
|
|
175
|
-
if (NoCode == e->type) {
|
|
176
|
-
e->obj = Qnil;
|
|
177
|
-
}
|
|
178
161
|
if (Qnil != pi->options->element_key_mod) {
|
|
179
162
|
key = rb_funcall(pi->options->element_key_mod, ox_call_id, 1, rb_id2str(e->var));
|
|
180
163
|
} else if (Yes == pi->options->sym_keys) {
|
|
@@ -205,28 +188,28 @@ static void end_element_core(PInfo pi, const char *ename, bool check_marked) {
|
|
|
205
188
|
break;
|
|
206
189
|
}
|
|
207
190
|
if (Qundef == found) {
|
|
208
|
-
rb_hash_aset(pobj, key,
|
|
191
|
+
rb_hash_aset(pobj, key, obj);
|
|
209
192
|
} else if (RUBY_T_ARRAY == rb_type(found)) {
|
|
210
193
|
if (check_marked && marked(pi, found)) {
|
|
211
194
|
unmark(pi, found);
|
|
212
195
|
a = rb_ary_new();
|
|
213
196
|
rb_ary_push(a, found);
|
|
214
|
-
rb_ary_push(a,
|
|
197
|
+
rb_ary_push(a, obj);
|
|
215
198
|
rb_hash_aset(pobj, key, a);
|
|
216
199
|
} else {
|
|
217
|
-
rb_ary_push(found,
|
|
200
|
+
rb_ary_push(found, obj);
|
|
218
201
|
}
|
|
219
202
|
} else { // something there other than an array
|
|
220
|
-
if (check_marked && marked(pi,
|
|
221
|
-
unmark(pi,
|
|
203
|
+
if (check_marked && marked(pi, obj)) {
|
|
204
|
+
unmark(pi, obj);
|
|
222
205
|
}
|
|
223
206
|
a = rb_ary_new();
|
|
224
207
|
rb_ary_push(a, found);
|
|
225
|
-
rb_ary_push(a,
|
|
208
|
+
rb_ary_push(a, obj);
|
|
226
209
|
rb_hash_aset(pobj, key, a);
|
|
227
210
|
}
|
|
228
|
-
if (check_marked && NULL != pi->marked && RUBY_T_HASH == rb_type(
|
|
229
|
-
rb_hash_foreach(
|
|
211
|
+
if (check_marked && NULL != pi->marked && RUBY_T_HASH == rb_type(obj)) {
|
|
212
|
+
rb_hash_foreach(obj, umark_hash_cb, (VALUE)pi);
|
|
230
213
|
}
|
|
231
214
|
}
|
|
232
215
|
|
|
@@ -239,12 +222,12 @@ static void end_element_no_attrs(PInfo pi, const char *ename) {
|
|
|
239
222
|
}
|
|
240
223
|
|
|
241
224
|
static void finish(PInfo pi) {
|
|
242
|
-
// Called once per yielded entity and once after the loop, so the
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
225
|
+
// Called once per yielded entity and once after the loop, so the table has
|
|
226
|
+
// to go with the block.
|
|
227
|
+
if (NULL != pi->marked) {
|
|
228
|
+
st_free_table(pi->marked);
|
|
229
|
+
pi->marked = NULL;
|
|
230
|
+
}
|
|
248
231
|
}
|
|
249
232
|
|
|
250
233
|
static void set_encoding_from_instruct(PInfo pi, Attr attrs) {
|
data/ext/ox/intern.c
CHANGED