oj 3.7.4 → 3.13.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1352 -0
- data/README.md +29 -8
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +53 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -43
- data/ext/oj/circarray.h +16 -17
- data/ext/oj/code.c +165 -179
- data/ext/oj/code.h +27 -29
- data/ext/oj/compat.c +174 -194
- data/ext/oj/custom.c +809 -866
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +848 -863
- data/ext/oj/dump.h +81 -67
- data/ext/oj/dump_compat.c +85 -123
- data/ext/oj/dump_leaf.c +100 -188
- data/ext/oj/dump_object.c +527 -656
- data/ext/oj/dump_strict.c +315 -338
- data/ext/oj/encode.h +7 -34
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +48 -48
- data/ext/oj/extconf.rb +17 -4
- data/ext/oj/fast.c +1070 -1087
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +469 -436
- data/ext/oj/object.c +525 -593
- data/ext/oj/odd.c +154 -138
- data/ext/oj/odd.h +37 -38
- data/ext/oj/oj.c +1325 -986
- data/ext/oj/oj.h +333 -316
- data/ext/oj/parse.c +1002 -846
- data/ext/oj/parse.h +92 -87
- data/ext/oj/parser.c +1557 -0
- data/ext/oj/parser.h +91 -0
- data/ext/oj/rails.c +888 -878
- data/ext/oj/rails.h +11 -14
- data/ext/oj/reader.c +141 -147
- data/ext/oj/reader.h +73 -89
- data/ext/oj/resolve.c +41 -62
- data/ext/oj/resolve.h +7 -9
- data/ext/oj/rxclass.c +71 -75
- data/ext/oj/rxclass.h +18 -19
- data/ext/oj/saj.c +443 -486
- data/ext/oj/saj2.c +602 -0
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +787 -709
- data/ext/oj/stream_writer.c +133 -159
- data/ext/oj/strict.c +127 -118
- data/ext/oj/string_writer.c +230 -249
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +19 -19
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +59 -67
- data/ext/oj/val_stack.h +91 -129
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +342 -353
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/error.rb +1 -1
- data/lib/oj/json.rb +1 -1
- data/lib/oj/mimic.rb +48 -14
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/state.rb +8 -7
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +0 -8
- data/pages/Compatibility.md +1 -1
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +53 -46
- data/pages/Options.md +72 -11
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +73 -22
- data/pages/Security.md +1 -1
- data/test/activerecord/result_test.rb +7 -2
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +6 -12
- data/test/baz.rb +16 -0
- data/test/bug.rb +16 -0
- data/test/foo.rb +69 -75
- data/test/helper.rb +16 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +18 -4
- data/test/json_gem/json_parser_test.rb +9 -0
- data/test/json_gem/test_helper.rb +12 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_dump.rb +50 -0
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- 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 +46 -10
- data/test/test_custom.rb +147 -8
- data/test/test_fast.rb +62 -2
- data/test/test_file.rb +25 -2
- data/test/test_gc.rb +13 -0
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +7 -2
- data/test/test_object.rb +85 -9
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +335 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +5 -5
- data/test/test_strict.rb +26 -1
- data/test/test_various.rb +87 -65
- data/test/test_wab.rb +2 -0
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +1 -1
- data/test/zoo.rb +13 -0
- metadata +60 -110
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
data/ext/oj/resolve.c
CHANGED
@@ -1,102 +1,81 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012 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 <stdlib.h>
|
7
4
|
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
8
6
|
#include <string.h>
|
9
|
-
#
|
7
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
10
8
|
#include <pthread.h>
|
11
9
|
#endif
|
12
10
|
|
13
|
-
#include "oj.h"
|
14
11
|
#include "err.h"
|
12
|
+
#include "intern.h"
|
13
|
+
#include "oj.h"
|
15
14
|
#include "parse.h"
|
16
|
-
#include "hash.h"
|
17
15
|
|
18
|
-
inline static VALUE
|
19
|
-
|
20
|
-
|
21
|
-
ID ci = rb_intern(classname);
|
16
|
+
inline static VALUE resolve_classname(VALUE mod, const char *classname, int auto_define) {
|
17
|
+
VALUE clas;
|
18
|
+
ID ci = rb_intern(classname);
|
22
19
|
|
23
20
|
if (rb_const_defined_at(mod, ci)) {
|
24
|
-
|
21
|
+
clas = rb_const_get_at(mod, ci);
|
25
22
|
} else if (auto_define) {
|
26
|
-
|
23
|
+
clas = rb_define_class_under(mod, classname, oj_bag_class);
|
27
24
|
} else {
|
28
|
-
|
25
|
+
clas = Qundef;
|
29
26
|
}
|
30
27
|
return clas;
|
31
28
|
}
|
32
29
|
|
33
30
|
static VALUE
|
34
31
|
resolve_classpath(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class) {
|
35
|
-
char
|
36
|
-
VALUE
|
37
|
-
char
|
38
|
-
char
|
39
|
-
const char
|
32
|
+
char class_name[1024];
|
33
|
+
VALUE clas;
|
34
|
+
char * end = class_name + sizeof(class_name) - 1;
|
35
|
+
char * s;
|
36
|
+
const char *n = name;
|
40
37
|
|
41
38
|
clas = rb_cObject;
|
42
39
|
for (s = class_name; 0 < len; n++, len--) {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
if (':' == *n) {
|
41
|
+
*s = '\0';
|
42
|
+
n++;
|
43
|
+
len--;
|
44
|
+
if (':' != *n) {
|
45
|
+
return Qundef;
|
46
|
+
}
|
47
|
+
if (Qundef == (clas = resolve_classname(clas, class_name, auto_define))) {
|
48
|
+
return Qundef;
|
49
|
+
}
|
50
|
+
s = class_name;
|
51
|
+
} else if (end <= s) {
|
52
|
+
return Qundef;
|
53
|
+
} else {
|
54
|
+
*s++ = *n;
|
55
|
+
}
|
59
56
|
}
|
60
57
|
*s = '\0';
|
61
58
|
if (Qundef == (clas = resolve_classname(clas, class_name, auto_define))) {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
oj_set_error_at(pi, error_class, __FILE__, __LINE__, "class %s is not defined", name);
|
60
|
+
if (Qnil != error_class) {
|
61
|
+
pi->err_class = error_class;
|
62
|
+
}
|
66
63
|
}
|
67
64
|
return clas;
|
68
65
|
}
|
69
66
|
|
70
67
|
VALUE
|
71
68
|
oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class) {
|
72
|
-
VALUE clas;
|
73
|
-
VALUE *slot;
|
74
|
-
|
75
69
|
if (No == pi->options.class_cache) {
|
76
|
-
|
70
|
+
return resolve_classpath(pi, name, len, auto_define, error_class);
|
77
71
|
}
|
78
|
-
|
79
|
-
pthread_mutex_lock(&oj_cache_mutex);
|
80
|
-
#else
|
81
|
-
rb_mutex_lock(oj_cache_mutex);
|
82
|
-
#endif
|
83
|
-
if (Qnil == (clas = oj_class_hash_get(name, len, &slot))) {
|
84
|
-
if (Qundef != (clas = resolve_classpath(pi, name, len, auto_define, error_class))) {
|
85
|
-
*slot = clas;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
#if HAVE_LIBPTHREAD
|
89
|
-
pthread_mutex_unlock(&oj_cache_mutex);
|
90
|
-
#else
|
91
|
-
rb_mutex_unlock(oj_cache_mutex);
|
92
|
-
#endif
|
93
|
-
return clas;
|
72
|
+
return oj_class_intern(name, len, true, pi, auto_define, error_class);
|
94
73
|
}
|
95
74
|
|
96
75
|
VALUE
|
97
76
|
oj_name2struct(ParseInfo pi, VALUE nameVal, VALUE error_class) {
|
98
|
-
size_t
|
99
|
-
const char
|
77
|
+
size_t len = RSTRING_LEN(nameVal);
|
78
|
+
const char *str = StringValuePtr(nameVal);
|
100
79
|
|
101
80
|
return resolve_classpath(pi, str, len, 0, error_class);
|
102
81
|
}
|
data/ext/oj/resolve.h
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
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.
|
5
3
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
4
|
+
#ifndef OJ_RESOLVE_H
|
5
|
+
#define OJ_RESOLVE_H
|
8
6
|
|
9
7
|
#include "ruby.h"
|
10
8
|
|
11
|
-
extern VALUE
|
12
|
-
extern VALUE
|
9
|
+
extern VALUE oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class);
|
10
|
+
extern VALUE oj_name2struct(ParseInfo pi, VALUE nameVal, VALUE error_class);
|
13
11
|
|
14
|
-
#endif /*
|
12
|
+
#endif /* OJ_RESOLVE_H */
|
data/ext/oj/rxclass.c
CHANGED
@@ -1,79 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2017 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 <sys/types.h>
|
7
|
-
#include <stdlib.h>
|
8
4
|
#include <errno.h>
|
9
|
-
#include <string.h>
|
10
5
|
#include <stdio.h>
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <string.h>
|
8
|
+
#include <sys/types.h>
|
11
9
|
#if !IS_WINDOWS
|
12
10
|
#include <regex.h>
|
13
11
|
#endif
|
14
12
|
|
15
13
|
#include "rxclass.h"
|
16
14
|
|
17
|
-
typedef struct
|
18
|
-
struct
|
19
|
-
VALUE
|
15
|
+
typedef struct _rxC {
|
16
|
+
struct _rxC *next;
|
17
|
+
VALUE rrx;
|
20
18
|
#if !IS_WINDOWS
|
21
|
-
regex_t
|
19
|
+
regex_t rx;
|
22
20
|
#endif
|
23
|
-
VALUE
|
24
|
-
char
|
25
|
-
} *RxC;
|
21
|
+
VALUE clas;
|
22
|
+
char src[256];
|
23
|
+
} * RxC;
|
26
24
|
|
27
|
-
void
|
28
|
-
oj_rxclass_init(RxClass rc) {
|
25
|
+
void oj_rxclass_init(RxClass rc) {
|
29
26
|
*rc->err = '\0';
|
30
27
|
rc->head = NULL;
|
31
28
|
rc->tail = NULL;
|
32
29
|
}
|
33
30
|
|
34
|
-
void
|
35
|
-
|
36
|
-
RxC rxc;
|
31
|
+
void oj_rxclass_cleanup(RxClass rc) {
|
32
|
+
RxC rxc;
|
37
33
|
|
38
34
|
while (NULL != (rxc = rc->head)) {
|
39
|
-
|
35
|
+
rc->head = rc->head->next;
|
40
36
|
#if !IS_WINDOWS
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
if (Qnil == rxc->rrx) {
|
38
|
+
regfree(&rxc->rx);
|
39
|
+
}
|
40
|
+
xfree(rxc);
|
45
41
|
#endif
|
46
42
|
}
|
47
43
|
}
|
48
44
|
|
49
|
-
void
|
50
|
-
|
51
|
-
RxC rxc = ALLOC_N(struct _RxC, 1);
|
45
|
+
void oj_rxclass_rappend(RxClass rc, VALUE rx, VALUE clas) {
|
46
|
+
RxC rxc = ALLOC_N(struct _rxC, 1);
|
52
47
|
|
53
|
-
memset(rxc, 0, sizeof(struct
|
54
|
-
rxc->rrx
|
48
|
+
memset(rxc, 0, sizeof(struct _rxC));
|
49
|
+
rxc->rrx = rx;
|
55
50
|
rxc->clas = clas;
|
56
51
|
if (NULL == rc->tail) {
|
57
|
-
|
52
|
+
rc->head = rxc;
|
58
53
|
} else {
|
59
|
-
|
54
|
+
rc->tail->next = rxc;
|
60
55
|
}
|
61
56
|
rc->tail = rxc;
|
62
57
|
}
|
63
58
|
|
64
59
|
// Attempt to compile the expression. If it fails populate the error code..
|
65
|
-
int
|
66
|
-
|
67
|
-
RxC rxc;
|
60
|
+
int oj_rxclass_append(RxClass rc, const char *expr, VALUE clas) {
|
61
|
+
RxC rxc;
|
68
62
|
#if !IS_WINDOWS
|
69
|
-
int
|
70
|
-
int
|
63
|
+
int err;
|
64
|
+
int flags = 0;
|
71
65
|
#endif
|
72
66
|
if (sizeof(rxc->src) <= strlen(expr)) {
|
73
|
-
|
74
|
-
|
67
|
+
snprintf(rc->err,
|
68
|
+
sizeof(rc->err),
|
69
|
+
"expressions must be less than %lu characters",
|
70
|
+
(unsigned long)sizeof(rxc->src));
|
71
|
+
return EINVAL;
|
75
72
|
}
|
76
|
-
rxc
|
73
|
+
rxc = ALLOC_N(struct _rxC, 1);
|
77
74
|
rxc->next = 0;
|
78
75
|
rxc->clas = clas;
|
79
76
|
|
@@ -82,15 +79,15 @@ oj_rxclass_append(RxClass rc, const char *expr, VALUE clas) {
|
|
82
79
|
#else
|
83
80
|
rxc->rrx = Qnil;
|
84
81
|
if (0 != (err = regcomp(&rxc->rx, expr, flags))) {
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
regerror(err, &rxc->rx, rc->err, sizeof(rc->err));
|
83
|
+
free(rxc);
|
84
|
+
return err;
|
88
85
|
}
|
89
86
|
#endif
|
90
87
|
if (NULL == rc->tail) {
|
91
|
-
|
88
|
+
rc->head = rxc;
|
92
89
|
} else {
|
93
|
-
|
90
|
+
rc->tail->next = rxc;
|
94
91
|
}
|
95
92
|
rc->tail = rxc;
|
96
93
|
|
@@ -99,49 +96,48 @@ oj_rxclass_append(RxClass rc, const char *expr, VALUE clas) {
|
|
99
96
|
|
100
97
|
VALUE
|
101
98
|
oj_rxclass_match(RxClass rc, const char *str, int len) {
|
102
|
-
RxC
|
103
|
-
char
|
104
|
-
|
99
|
+
RxC rxc;
|
100
|
+
char buf[4096];
|
101
|
+
|
105
102
|
for (rxc = rc->head; NULL != rxc; rxc = rxc->next) {
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
103
|
+
if (Qnil != rxc->rrx) {
|
104
|
+
// Must use a valiabel for this to work.
|
105
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
106
|
+
|
107
|
+
// if (Qtrue == rb_funcall(rxc->rrx, rb_intern("match?"), 1, rstr)) {
|
108
|
+
if (Qnil != rb_funcall(rxc->rrx, rb_intern("match"), 1, rstr)) {
|
109
|
+
return rxc->clas;
|
110
|
+
}
|
111
|
+
} else if (len < (int)sizeof(buf)) {
|
115
112
|
#if !IS_WINDOWS
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
113
|
+
// string is not \0 terminated so copy and attempt a match
|
114
|
+
memcpy(buf, str, len);
|
115
|
+
buf[len] = '\0';
|
116
|
+
if (0 == regexec(&rxc->rx, buf, 0, NULL, 0)) { // match
|
117
|
+
return rxc->clas;
|
118
|
+
}
|
122
119
|
#endif
|
123
|
-
|
124
|
-
|
125
|
-
|
120
|
+
} else {
|
121
|
+
// TBD allocate a larger buffer and attempt
|
122
|
+
}
|
126
123
|
}
|
127
124
|
return Qnil;
|
128
125
|
}
|
129
126
|
|
130
|
-
void
|
131
|
-
oj_rxclass_copy(RxClass src, RxClass dest) {
|
127
|
+
void oj_rxclass_copy(RxClass src, RxClass dest) {
|
132
128
|
dest->head = NULL;
|
133
129
|
dest->tail = NULL;
|
134
130
|
if (NULL != src->head) {
|
135
|
-
|
131
|
+
RxC rxc;
|
136
132
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
133
|
+
for (rxc = src->head; NULL != rxc; rxc = rxc->next) {
|
134
|
+
if (Qnil != rxc->rrx) {
|
135
|
+
oj_rxclass_rappend(dest, rxc->rrx, rxc->clas);
|
136
|
+
} else {
|
141
137
|
#if !IS_WINDOWS
|
142
|
-
|
138
|
+
oj_rxclass_append(dest, rxc->src, rxc->clas);
|
143
139
|
#endif
|
144
|
-
|
145
|
-
|
140
|
+
}
|
141
|
+
}
|
146
142
|
}
|
147
143
|
}
|
data/ext/oj/rxclass.h
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2017 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
5
3
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
4
|
+
#ifndef OJ_RXCLASS_H
|
5
|
+
#define OJ_RXCLASS_H
|
8
6
|
|
9
7
|
#include <stdbool.h>
|
8
|
+
|
10
9
|
#include "ruby.h"
|
11
10
|
|
12
|
-
struct
|
11
|
+
struct _rxC;
|
13
12
|
|
14
|
-
typedef struct
|
15
|
-
struct
|
16
|
-
struct
|
17
|
-
char
|
18
|
-
} *RxClass;
|
13
|
+
typedef struct _rxClass {
|
14
|
+
struct _rxC *head;
|
15
|
+
struct _rxC *tail;
|
16
|
+
char err[128];
|
17
|
+
} * RxClass;
|
19
18
|
|
20
|
-
extern void
|
21
|
-
extern void
|
22
|
-
extern int
|
23
|
-
extern VALUE
|
24
|
-
extern void
|
25
|
-
extern void
|
19
|
+
extern void oj_rxclass_init(RxClass rc);
|
20
|
+
extern void oj_rxclass_cleanup(RxClass rc);
|
21
|
+
extern int oj_rxclass_append(RxClass rc, const char *expr, VALUE clas);
|
22
|
+
extern VALUE oj_rxclass_match(RxClass rc, const char *str, int len);
|
23
|
+
extern void oj_rxclass_copy(RxClass src, RxClass dest);
|
24
|
+
extern void oj_rxclass_rappend(RxClass rc, VALUE rx, VALUE clas);
|
26
25
|
|
27
|
-
#endif /*
|
26
|
+
#endif /* OJ_RXCLASS_H */
|