oj 3.10.6 → 3.12.1
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/README.md +6 -1
- data/ext/oj/buf.h +36 -68
- data/ext/oj/cache8.c +59 -62
- data/ext/oj/cache8.h +9 -36
- data/ext/oj/circarray.c +36 -42
- data/ext/oj/circarray.h +12 -13
- data/ext/oj/code.c +172 -179
- data/ext/oj/code.h +22 -24
- data/ext/oj/compat.c +176 -181
- data/ext/oj/custom.c +800 -864
- data/ext/oj/dump.c +774 -776
- data/ext/oj/dump.h +50 -55
- data/ext/oj/dump_compat.c +2 -4
- data/ext/oj/dump_leaf.c +118 -162
- data/ext/oj/dump_object.c +610 -632
- data/ext/oj/dump_strict.c +319 -331
- data/ext/oj/encode.h +4 -33
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +25 -44
- data/ext/oj/extconf.rb +2 -1
- data/ext/oj/fast.c +1054 -1081
- data/ext/oj/hash.c +102 -97
- data/ext/oj/hash.h +10 -35
- data/ext/oj/hash_test.c +451 -472
- data/ext/oj/mimic_json.c +415 -402
- data/ext/oj/object.c +588 -532
- data/ext/oj/odd.c +124 -132
- data/ext/oj/odd.h +28 -29
- data/ext/oj/oj.c +1186 -906
- data/ext/oj/oj.h +289 -298
- data/ext/oj/parse.c +946 -870
- data/ext/oj/parse.h +81 -79
- data/ext/oj/rails.c +837 -842
- data/ext/oj/rails.h +8 -11
- data/ext/oj/reader.c +139 -147
- data/ext/oj/reader.h +68 -84
- data/ext/oj/resolve.c +44 -47
- data/ext/oj/resolve.h +4 -6
- data/ext/oj/rxclass.c +69 -73
- data/ext/oj/rxclass.h +13 -14
- data/ext/oj/saj.c +453 -484
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +783 -714
- data/ext/oj/stream_writer.c +123 -157
- data/ext/oj/strict.c +133 -106
- data/ext/oj/string_writer.c +199 -247
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +15 -15
- data/ext/oj/util.c +104 -104
- data/ext/oj/util.h +4 -3
- data/ext/oj/val_stack.c +48 -76
- data/ext/oj/val_stack.h +80 -115
- data/ext/oj/wab.c +321 -325
- data/lib/oj.rb +0 -8
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/mimic.rb +47 -13
- data/lib/oj/version.rb +1 -1
- data/pages/Modes.md +1 -0
- data/pages/Options.md +23 -11
- data/test/activerecord/result_test.rb +7 -2
- data/test/foo.rb +8 -40
- data/test/helper.rb +10 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +15 -3
- data/test/json_gem/test_helper.rb +8 -0
- data/test/perf.rb +1 -1
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +16 -3
- data/test/test_custom.rb +11 -0
- data/test/test_fast.rb +32 -2
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +10 -0
- data/test/test_rails.rb +9 -0
- data/test/test_scp.rb +1 -1
- data/test/test_various.rb +4 -2
- metadata +89 -85
data/ext/oj/trace.c
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2018 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
5
3
|
|
6
|
-
#include "parse.h"
|
7
4
|
#include "trace.h"
|
8
5
|
|
9
|
-
#
|
6
|
+
#include "parse.h"
|
7
|
+
|
8
|
+
#define MAX_INDENT 256
|
10
9
|
|
11
|
-
static void
|
12
|
-
fill_indent(char *indent, int depth) {
|
10
|
+
static void fill_indent(char *indent, int depth) {
|
13
11
|
if (MAX_INDENT <= depth) {
|
14
|
-
|
12
|
+
depth = MAX_INDENT - 1;
|
15
13
|
} else if (depth < 0) {
|
16
|
-
|
14
|
+
depth = 0;
|
17
15
|
}
|
18
16
|
if (0 < depth) {
|
19
|
-
|
17
|
+
memset(indent, ' ', depth);
|
20
18
|
}
|
21
19
|
indent[depth] = '\0';
|
22
20
|
}
|
23
21
|
|
24
|
-
void
|
25
|
-
|
26
|
-
char
|
27
|
-
char indent[MAX_INDENT];
|
22
|
+
void oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where) {
|
23
|
+
char fmt[64];
|
24
|
+
char indent[MAX_INDENT];
|
28
25
|
|
29
26
|
depth *= 2;
|
30
27
|
fill_indent(indent, depth);
|
@@ -32,47 +29,43 @@ oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, Tra
|
|
32
29
|
printf(fmt, file, line, indent, func, rb_obj_classname(obj));
|
33
30
|
}
|
34
31
|
|
35
|
-
void
|
36
|
-
|
37
|
-
char
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
void oj_trace_parse_call(const char *func, ParseInfo pi, const char *file, int line, VALUE obj) {
|
33
|
+
char fmt[64];
|
34
|
+
char indent[MAX_INDENT];
|
35
|
+
int depth = (int)(stack_size(&pi->stack) * 2);
|
36
|
+
|
41
37
|
fill_indent(indent, depth);
|
42
38
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:-:%%%ds %%s %%s\n", depth);
|
43
39
|
printf(fmt, file, line, indent, func, rb_obj_classname(obj));
|
44
40
|
}
|
45
41
|
|
46
|
-
void
|
47
|
-
|
48
|
-
char
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
void oj_trace_parse_in(const char *func, ParseInfo pi, const char *file, int line) {
|
43
|
+
char fmt[64];
|
44
|
+
char indent[MAX_INDENT];
|
45
|
+
int depth = (int)(stack_size(&pi->stack) * 2);
|
46
|
+
|
52
47
|
fill_indent(indent, depth);
|
53
48
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:}:%%%ds %%s\n", depth);
|
54
49
|
printf(fmt, file, line, indent, func);
|
55
50
|
}
|
56
51
|
|
57
|
-
void
|
58
|
-
|
59
|
-
char
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
52
|
+
void oj_trace_parse_hash_end(ParseInfo pi, const char *file, int line) {
|
53
|
+
char fmt[64];
|
54
|
+
char indent[MAX_INDENT];
|
55
|
+
int depth = (int)(stack_size(&pi->stack) * 2 - 2);
|
56
|
+
Val v = stack_peek(&pi->stack);
|
57
|
+
VALUE obj = v->val;
|
58
|
+
|
65
59
|
fill_indent(indent, depth);
|
66
60
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds hash_end %%s\n", depth);
|
67
61
|
printf(fmt, file, line, indent, rb_obj_classname(obj));
|
68
62
|
}
|
69
63
|
|
70
|
-
void
|
71
|
-
|
72
|
-
char
|
73
|
-
|
74
|
-
|
75
|
-
|
64
|
+
void oj_trace_parse_array_end(ParseInfo pi, const char *file, int line) {
|
65
|
+
char fmt[64];
|
66
|
+
char indent[MAX_INDENT];
|
67
|
+
int depth = (int)(stack_size(&pi->stack) * 2);
|
68
|
+
|
76
69
|
fill_indent(indent, depth);
|
77
70
|
sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds array_ned\n", depth);
|
78
71
|
printf(fmt, file, line, indent);
|
data/ext/oj/trace.h
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2018 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
5
3
|
|
6
4
|
#ifndef OJ_TRACE_H
|
7
5
|
#define OJ_TRACE_H
|
8
6
|
|
9
|
-
#include <stdbool.h>
|
10
7
|
#include <ruby.h>
|
8
|
+
#include <stdbool.h>
|
11
9
|
|
12
10
|
typedef enum {
|
13
|
-
TraceIn
|
14
|
-
TraceOut
|
15
|
-
TraceCall
|
16
|
-
TraceRubyIn
|
17
|
-
TraceRubyOut
|
11
|
+
TraceIn = '}',
|
12
|
+
TraceOut = '{',
|
13
|
+
TraceCall = '-',
|
14
|
+
TraceRubyIn = '>',
|
15
|
+
TraceRubyOut = '<',
|
18
16
|
} TraceWhere;
|
19
17
|
|
20
18
|
struct _parseInfo;
|
21
19
|
|
22
|
-
extern void
|
23
|
-
|
24
|
-
extern void
|
25
|
-
extern void
|
26
|
-
|
20
|
+
extern void
|
21
|
+
oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where);
|
22
|
+
extern void oj_trace_parse_in(const char *func, struct _parseInfo *pi, const char *file, int line);
|
23
|
+
extern void
|
24
|
+
oj_trace_parse_call(const char *func, struct _parseInfo *pi, const char *file, int line, VALUE obj);
|
25
|
+
extern void oj_trace_parse_hash_end(struct _parseInfo *pi, const char *file, int line);
|
26
|
+
extern void oj_trace_parse_array_end(struct _parseInfo *pi, const char *file, int line);
|
27
27
|
|
28
28
|
#endif /* OJ_TRACE_H */
|
data/ext/oj/util.c
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
// Copyright (c) 2019
|
1
|
+
// Copyright (c) 2019 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
4
|
#include "util.h"
|
4
5
|
|
@@ -8,129 +9,128 @@
|
|
8
9
|
#include <string.h>
|
9
10
|
#include <time.h>
|
10
11
|
|
11
|
-
#define SECS_PER_DAY
|
12
|
-
#define SECS_PER_YEAR
|
13
|
-
#define SECS_PER_LEAP
|
14
|
-
#define SECS_PER_QUAD_YEAR
|
15
|
-
#define SECS_PER_CENT
|
16
|
-
#define SECS_PER_LEAP_CENT
|
17
|
-
#define SECS_PER_QUAD_CENT
|
12
|
+
#define SECS_PER_DAY 86400LL
|
13
|
+
#define SECS_PER_YEAR 31536000LL
|
14
|
+
#define SECS_PER_LEAP 31622400LL
|
15
|
+
#define SECS_PER_QUAD_YEAR (SECS_PER_YEAR * 3 + SECS_PER_LEAP)
|
16
|
+
#define SECS_PER_CENT (SECS_PER_QUAD_YEAR * 24 + SECS_PER_YEAR * 4)
|
17
|
+
#define SECS_PER_LEAP_CENT (SECS_PER_CENT + SECS_PER_DAY)
|
18
|
+
#define SECS_PER_QUAD_CENT (SECS_PER_CENT * 4 + SECS_PER_DAY)
|
18
19
|
|
19
|
-
static int64_t
|
20
|
-
2678400,
|
21
|
-
5097600,
|
22
|
-
7776000,
|
23
|
-
10368000,
|
24
|
-
13046400,
|
25
|
-
15638400,
|
26
|
-
18316800,
|
27
|
-
20995200,
|
28
|
-
23587200,
|
29
|
-
26265600,
|
30
|
-
28857600,
|
31
|
-
31536000,
|
20
|
+
static int64_t eom_secs[] = {
|
21
|
+
2678400, // January (31)
|
22
|
+
5097600, // February (28) 2419200 2505600
|
23
|
+
7776000, // March (31)
|
24
|
+
10368000, // April (30 2592000
|
25
|
+
13046400, // May (31)
|
26
|
+
15638400, // June (30)
|
27
|
+
18316800, // July (31)
|
28
|
+
20995200, // August (31)
|
29
|
+
23587200, // September (30)
|
30
|
+
26265600, // October (31)
|
31
|
+
28857600, // November (30)
|
32
|
+
31536000, // December (31)
|
32
33
|
};
|
33
34
|
|
34
|
-
static int64_t
|
35
|
-
2678400,
|
36
|
-
5184000,
|
37
|
-
7862400,
|
38
|
-
10454400,
|
39
|
-
13132800,
|
40
|
-
15724800,
|
41
|
-
18403200,
|
42
|
-
21081600,
|
43
|
-
23673600,
|
44
|
-
26352000,
|
45
|
-
28944000,
|
46
|
-
31622400,
|
35
|
+
static int64_t eom_leap_secs[] = {
|
36
|
+
2678400, // January (31)
|
37
|
+
5184000, // February (28) 2419200 2505600
|
38
|
+
7862400, // March (31)
|
39
|
+
10454400, // April (30 2592000
|
40
|
+
13132800, // May (31)
|
41
|
+
15724800, // June (30)
|
42
|
+
18403200, // July (31)
|
43
|
+
21081600, // August (31)
|
44
|
+
23673600, // September (30)
|
45
|
+
26352000, // October (31)
|
46
|
+
28944000, // November (30)
|
47
|
+
31622400, // December (31)
|
47
48
|
};
|
48
49
|
|
50
|
+
void sec_as_time(int64_t secs, TimeInfo ti) {
|
51
|
+
int64_t qc = 0;
|
52
|
+
int64_t c = 0;
|
53
|
+
int64_t qy = 0;
|
54
|
+
int64_t y = 0;
|
55
|
+
bool leap = false;
|
56
|
+
int64_t *ms;
|
57
|
+
int m;
|
58
|
+
int shift = 0;
|
49
59
|
|
50
|
-
|
51
|
-
sec_as_time(int64_t secs, TimeInfo ti) {
|
52
|
-
int64_t qc = 0;
|
53
|
-
int64_t c = 0;
|
54
|
-
int64_t qy = 0;
|
55
|
-
int64_t y = 0;
|
56
|
-
bool leap = false;
|
57
|
-
int64_t *ms;
|
58
|
-
int m;
|
59
|
-
int shift = 0;
|
60
|
-
|
61
|
-
secs += 62167219200LL; // normalize to first day of the year 0
|
60
|
+
secs += 62167219200LL; // normalize to first day of the year 0
|
62
61
|
if (secs < 0) {
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
shift = -secs / SECS_PER_QUAD_CENT;
|
63
|
+
shift++;
|
64
|
+
secs += shift * SECS_PER_QUAD_CENT;
|
66
65
|
}
|
67
|
-
qc
|
66
|
+
qc = secs / SECS_PER_QUAD_CENT;
|
68
67
|
secs = secs - qc * SECS_PER_QUAD_CENT;
|
69
68
|
if (secs < SECS_PER_LEAP) {
|
70
|
-
|
69
|
+
leap = true;
|
71
70
|
} else if (secs < SECS_PER_QUAD_YEAR) {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
} else if (secs < SECS_PER_LEAP_CENT) {
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
if (SECS_PER_LEAP <= secs) {
|
72
|
+
secs -= SECS_PER_LEAP;
|
73
|
+
y = secs / SECS_PER_YEAR;
|
74
|
+
secs = secs - y * SECS_PER_YEAR;
|
75
|
+
y++;
|
76
|
+
leap = false;
|
77
|
+
}
|
78
|
+
} else if (secs < SECS_PER_LEAP_CENT) { // first century in 400 years is a leap century (one
|
79
|
+
// extra day)
|
80
|
+
qy = secs / SECS_PER_QUAD_YEAR;
|
81
|
+
secs = secs - qy * SECS_PER_QUAD_YEAR;
|
82
|
+
if (secs < SECS_PER_LEAP) {
|
83
|
+
leap = true;
|
84
|
+
} else {
|
85
|
+
secs -= SECS_PER_LEAP;
|
86
|
+
y = secs / SECS_PER_YEAR;
|
87
|
+
secs = secs - y * SECS_PER_YEAR;
|
88
|
+
y++;
|
89
|
+
}
|
90
90
|
} else {
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
91
|
+
secs -= SECS_PER_LEAP_CENT;
|
92
|
+
c = secs / SECS_PER_CENT;
|
93
|
+
secs = secs - c * SECS_PER_CENT;
|
94
|
+
c++;
|
95
|
+
if (secs < SECS_PER_YEAR * 4) {
|
96
|
+
y = secs / SECS_PER_YEAR;
|
97
|
+
secs = secs - y * SECS_PER_YEAR;
|
98
|
+
} else {
|
99
|
+
secs -= SECS_PER_YEAR * 4;
|
100
|
+
qy = secs / SECS_PER_QUAD_YEAR;
|
101
|
+
secs = secs - qy * SECS_PER_QUAD_YEAR;
|
102
|
+
qy++;
|
103
|
+
if (secs < SECS_PER_LEAP) {
|
104
|
+
leap = true;
|
105
|
+
} else {
|
106
|
+
secs -= SECS_PER_LEAP;
|
107
|
+
y = secs / SECS_PER_YEAR;
|
108
|
+
secs = secs - y * SECS_PER_YEAR;
|
109
|
+
y++;
|
110
|
+
}
|
111
|
+
}
|
112
112
|
}
|
113
113
|
ti->year = (int)((qc - (int64_t)shift) * 400 + c * 100 + qy * 4 + y);
|
114
114
|
if (leap) {
|
115
|
-
|
115
|
+
ms = eom_leap_secs;
|
116
116
|
} else {
|
117
|
-
|
117
|
+
ms = eom_secs;
|
118
118
|
}
|
119
119
|
for (m = 1; m <= 12; m++, ms++) {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
if (secs < *ms) {
|
121
|
+
if (1 < m) {
|
122
|
+
secs -= *(ms - 1);
|
123
|
+
}
|
124
|
+
ti->mon = m;
|
125
|
+
break;
|
126
|
+
}
|
127
127
|
}
|
128
128
|
ti->day = (int)(secs / 86400LL);
|
129
|
-
secs
|
129
|
+
secs = secs - (int64_t)ti->day * 86400LL;
|
130
130
|
ti->day++;
|
131
131
|
ti->hour = (int)(secs / 3600LL);
|
132
|
-
secs
|
133
|
-
ti->min
|
134
|
-
secs
|
135
|
-
ti->sec
|
132
|
+
secs = secs - (int64_t)ti->hour * 3600LL;
|
133
|
+
ti->min = (int)(secs / 60LL);
|
134
|
+
secs = secs - (int64_t)ti->min * 60LL;
|
135
|
+
ti->sec = (int)secs;
|
136
136
|
}
|
data/ext/oj/util.h
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
// Copyright (c) 2019
|
1
|
+
// Copyright (c) 2019 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
4
|
#ifndef OJ_UTIL_H
|
4
5
|
#define OJ_UTIL_H
|
@@ -12,8 +13,8 @@ typedef struct _timeInfo {
|
|
12
13
|
int day;
|
13
14
|
int mon;
|
14
15
|
int year;
|
15
|
-
} *TimeInfo;
|
16
|
+
} * TimeInfo;
|
16
17
|
|
17
|
-
extern void
|
18
|
+
extern void sec_as_time(int64_t secs, TimeInfo ti);
|
18
19
|
|
19
20
|
#endif /* OJ_UTIL_H */
|
data/ext/oj/val_stack.c
CHANGED
@@ -1,46 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
3
|
+
|
4
|
+
#include "val_stack.h"
|
30
5
|
|
31
6
|
#include <string.h>
|
32
7
|
|
33
|
-
#include "oj.h"
|
34
8
|
#include "odd.h"
|
35
|
-
#include "
|
9
|
+
#include "oj.h"
|
36
10
|
|
37
|
-
static void
|
38
|
-
|
39
|
-
|
40
|
-
Val v;
|
11
|
+
static void mark(void *ptr) {
|
12
|
+
ValStack stack = (ValStack)ptr;
|
13
|
+
Val v;
|
41
14
|
|
42
15
|
if (0 == ptr) {
|
43
|
-
|
16
|
+
return;
|
44
17
|
}
|
45
18
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
46
19
|
pthread_mutex_lock(&stack->mutex);
|
@@ -49,22 +22,22 @@ mark(void *ptr) {
|
|
49
22
|
rb_gc_mark(stack->mutex);
|
50
23
|
#endif
|
51
24
|
for (v = stack->head; v < stack->tail; v++) {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
25
|
+
if (Qnil != v->val && Qundef != v->val) {
|
26
|
+
rb_gc_mark(v->val);
|
27
|
+
}
|
28
|
+
if (Qnil != v->key_val && Qundef != v->key_val) {
|
29
|
+
rb_gc_mark(v->key_val);
|
30
|
+
}
|
31
|
+
if (NULL != v->odd_args) {
|
32
|
+
VALUE *a;
|
33
|
+
int i;
|
61
34
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
35
|
+
for (i = v->odd_args->odd->attr_cnt, a = v->odd_args->args; 0 < i; i--, a++) {
|
36
|
+
if (Qnil != *a) {
|
37
|
+
rb_gc_mark(*a);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
68
41
|
}
|
69
42
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
70
43
|
pthread_mutex_unlock(&stack->mutex);
|
@@ -76,43 +49,42 @@ mark(void *ptr) {
|
|
76
49
|
VALUE
|
77
50
|
oj_stack_init(ValStack stack) {
|
78
51
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
79
|
-
int
|
52
|
+
int err;
|
80
53
|
|
81
54
|
if (0 != (err = pthread_mutex_init(&stack->mutex, 0))) {
|
82
|
-
|
55
|
+
rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
|
83
56
|
}
|
84
57
|
#else
|
85
58
|
stack->mutex = rb_mutex_new();
|
86
59
|
#endif
|
87
|
-
stack->head
|
88
|
-
stack->end
|
89
|
-
stack->tail
|
90
|
-
stack->head->val
|
91
|
-
stack->head->key
|
92
|
-
stack->head->key_val
|
60
|
+
stack->head = stack->base;
|
61
|
+
stack->end = stack->base + sizeof(stack->base) / sizeof(struct _val);
|
62
|
+
stack->tail = stack->head;
|
63
|
+
stack->head->val = Qundef;
|
64
|
+
stack->head->key = NULL;
|
65
|
+
stack->head->key_val = Qundef;
|
93
66
|
stack->head->classname = NULL;
|
94
|
-
stack->head->odd_args
|
95
|
-
stack->head->clas
|
96
|
-
stack->head->klen
|
97
|
-
stack->head->clen
|
98
|
-
stack->head->next
|
67
|
+
stack->head->odd_args = NULL;
|
68
|
+
stack->head->clas = Qundef;
|
69
|
+
stack->head->klen = 0;
|
70
|
+
stack->head->clen = 0;
|
71
|
+
stack->head->next = NEXT_NONE;
|
99
72
|
|
100
73
|
return Data_Wrap_Struct(oj_cstack_class, mark, 0, stack);
|
101
74
|
}
|
102
75
|
|
103
|
-
const char*
|
104
|
-
oj_stack_next_string(ValNext n) {
|
76
|
+
const char *oj_stack_next_string(ValNext n) {
|
105
77
|
switch (n) {
|
106
|
-
case NEXT_ARRAY_NEW:
|
107
|
-
case NEXT_ARRAY_ELEMENT:
|
108
|
-
case NEXT_ARRAY_COMMA:
|
109
|
-
case NEXT_HASH_NEW:
|
110
|
-
case NEXT_HASH_KEY:
|
111
|
-
case NEXT_HASH_COLON:
|
112
|
-
case NEXT_HASH_VALUE:
|
113
|
-
case NEXT_HASH_COMMA:
|
114
|
-
case NEXT_NONE:
|
115
|
-
default:
|
78
|
+
case NEXT_ARRAY_NEW: return "array element or close";
|
79
|
+
case NEXT_ARRAY_ELEMENT: return "array element";
|
80
|
+
case NEXT_ARRAY_COMMA: return "comma";
|
81
|
+
case NEXT_HASH_NEW: return "hash pair or close";
|
82
|
+
case NEXT_HASH_KEY: return "hash key";
|
83
|
+
case NEXT_HASH_COLON: return "colon";
|
84
|
+
case NEXT_HASH_VALUE: return "hash value";
|
85
|
+
case NEXT_HASH_COMMA: return "comma";
|
86
|
+
case NEXT_NONE: break;
|
87
|
+
default: break;
|
116
88
|
}
|
117
89
|
return "nothing";
|
118
90
|
}
|