oj 2.0.0 → 3.0.0
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 +7 -0
- data/LICENSE +17 -23
- data/README.md +74 -425
- data/ext/oj/buf.h +103 -0
- data/ext/oj/cache8.c +4 -0
- data/ext/oj/circarray.c +68 -0
- data/ext/oj/circarray.h +23 -0
- data/ext/oj/code.c +227 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +243 -0
- data/ext/oj/custom.c +1097 -0
- data/ext/oj/dump.c +766 -1534
- data/ext/oj/dump.h +92 -0
- data/ext/oj/dump_compat.c +937 -0
- data/ext/oj/dump_leaf.c +254 -0
- data/ext/oj/dump_object.c +810 -0
- data/ext/oj/dump_rails.c +329 -0
- data/ext/oj/dump_strict.c +416 -0
- data/ext/oj/encode.h +51 -0
- data/ext/oj/err.c +57 -0
- data/ext/oj/err.h +70 -0
- data/ext/oj/extconf.rb +17 -7
- data/ext/oj/fast.c +213 -180
- data/ext/oj/hash.c +163 -0
- data/ext/oj/hash.h +46 -0
- data/ext/oj/hash_test.c +512 -0
- data/ext/oj/mimic_json.c +817 -0
- data/ext/oj/mimic_rails.c +806 -0
- data/ext/oj/mimic_rails.h +17 -0
- data/ext/oj/object.c +752 -0
- data/ext/oj/odd.c +230 -0
- data/ext/oj/odd.h +44 -0
- data/ext/oj/oj.c +1288 -929
- data/ext/oj/oj.h +240 -69
- data/ext/oj/parse.c +1014 -0
- data/ext/oj/parse.h +92 -0
- data/ext/oj/reader.c +223 -0
- data/ext/oj/reader.h +151 -0
- data/ext/oj/resolve.c +127 -0
- data/ext/oj/{cache.h → resolve.h} +6 -13
- data/ext/oj/rxclass.c +133 -0
- data/ext/oj/rxclass.h +27 -0
- data/ext/oj/saj.c +77 -175
- data/ext/oj/scp.c +224 -0
- data/ext/oj/sparse.c +911 -0
- data/ext/oj/stream_writer.c +301 -0
- data/ext/oj/strict.c +162 -0
- data/ext/oj/string_writer.c +480 -0
- data/ext/oj/val_stack.c +98 -0
- data/ext/oj/val_stack.h +188 -0
- data/lib/oj/active_support_helper.rb +41 -0
- data/lib/oj/bag.rb +6 -10
- data/lib/oj/easy_hash.rb +52 -0
- data/lib/oj/json.rb +172 -0
- data/lib/oj/mimic.rb +260 -5
- data/lib/oj/saj.rb +13 -10
- data/lib/oj/schandler.rb +142 -0
- data/lib/oj/state.rb +131 -0
- data/lib/oj/version.rb +1 -1
- data/lib/oj.rb +11 -23
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/JsonGem.md +79 -0
- data/pages/Modes.md +140 -0
- data/pages/Options.md +250 -0
- data/pages/Rails.md +60 -0
- data/pages/Security.md +20 -0
- data/test/_test_active.rb +76 -0
- data/test/_test_active_mimic.rb +96 -0
- data/test/_test_mimic_rails.rb +126 -0
- data/test/activesupport4/decoding_test.rb +105 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/decoding_test.rb +125 -0
- data/test/activesupport5/encoding_test.rb +483 -0
- data/test/activesupport5/encoding_test_cases.rb +90 -0
- data/test/activesupport5/test_helper.rb +50 -0
- data/test/activesupport5/time_zone_test_helpers.rb +24 -0
- data/test/helper.rb +27 -0
- data/test/isolated/shared.rb +310 -0
- data/test/isolated/test_mimic_after.rb +13 -0
- data/test/isolated/test_mimic_alone.rb +12 -0
- data/test/isolated/test_mimic_as_json.rb +45 -0
- data/test/isolated/test_mimic_before.rb +13 -0
- data/test/isolated/test_mimic_define.rb +28 -0
- data/test/isolated/test_mimic_rails_after.rb +22 -0
- data/test/isolated/test_mimic_rails_before.rb +21 -0
- data/test/isolated/test_mimic_redefine.rb +15 -0
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +143 -0
- data/test/json_gem/json_encoding_test.rb +109 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +383 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +18 -0
- data/test/perf_compat.rb +130 -0
- data/test/perf_fast.rb +9 -9
- data/test/perf_file.rb +64 -0
- data/test/{perf_obj.rb → perf_object.rb} +24 -10
- data/test/perf_scp.rb +151 -0
- data/test/perf_strict.rb +32 -113
- data/test/sample.rb +2 -3
- data/test/test_compat.rb +474 -0
- data/test/test_custom.rb +355 -0
- data/test/test_debian.rb +53 -0
- data/test/test_fast.rb +66 -16
- data/test/test_file.rb +237 -0
- data/test/test_gc.rb +49 -0
- data/test/test_hash.rb +29 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +1010 -0
- data/test/test_saj.rb +16 -16
- data/test/test_scp.rb +417 -0
- data/test/test_strict.rb +410 -0
- data/test/test_various.rb +815 -0
- data/test/test_writer.rb +308 -0
- data/test/tests.rb +9 -902
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- metadata +253 -38
- data/ext/oj/cache.c +0 -148
- data/ext/oj/foo.rb +0 -6
- data/ext/oj/load.c +0 -1049
- data/test/a.rb +0 -38
- data/test/perf1.rb +0 -64
- data/test/perf2.rb +0 -76
- data/test/perf_obj_old.rb +0 -213
- data/test/test_mimic.rb +0 -208
data/ext/oj/scp.c
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/* scp.c
|
|
2
|
+
* Copyright (c) 2012, Peter Ohler
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <stdio.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#include <math.h>
|
|
10
|
+
#include <sys/types.h>
|
|
11
|
+
#include <unistd.h>
|
|
12
|
+
|
|
13
|
+
#include "oj.h"
|
|
14
|
+
#include "parse.h"
|
|
15
|
+
#include "encode.h"
|
|
16
|
+
|
|
17
|
+
static VALUE
|
|
18
|
+
noop_start(ParseInfo pi) {
|
|
19
|
+
return Qnil;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static void
|
|
23
|
+
noop_end(ParseInfo pi) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static void
|
|
27
|
+
noop_add_value(ParseInfo pi, VALUE val) {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static void
|
|
31
|
+
noop_add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static void
|
|
35
|
+
noop_add_num(ParseInfo pi, NumInfo ni) {
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static VALUE
|
|
39
|
+
noop_hash_key(struct _ParseInfo *pi, const char *key, size_t klen) {
|
|
40
|
+
return Qundef;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static void
|
|
44
|
+
noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static void
|
|
48
|
+
noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static void
|
|
52
|
+
noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void
|
|
56
|
+
noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static void
|
|
60
|
+
noop_array_append_num(ParseInfo pi, NumInfo ni) {
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static void
|
|
64
|
+
noop_array_append_value(ParseInfo pi, VALUE value) {
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void
|
|
68
|
+
add_value(ParseInfo pi, VALUE val) {
|
|
69
|
+
rb_funcall(pi->handler, oj_add_value_id, 1, val);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static void
|
|
73
|
+
add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
74
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
|
75
|
+
|
|
76
|
+
rstr = oj_encode(rstr);
|
|
77
|
+
rb_funcall(pi->handler, oj_add_value_id, 1, rstr);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static void
|
|
81
|
+
add_num(ParseInfo pi, NumInfo ni) {
|
|
82
|
+
rb_funcall(pi->handler, oj_add_value_id, 1, oj_num_as_value(ni));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static VALUE
|
|
86
|
+
start_hash(ParseInfo pi) {
|
|
87
|
+
return rb_funcall(pi->handler, oj_hash_start_id, 0);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static void
|
|
91
|
+
end_hash(ParseInfo pi) {
|
|
92
|
+
rb_funcall(pi->handler, oj_hash_end_id, 0);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static VALUE
|
|
96
|
+
start_array(ParseInfo pi) {
|
|
97
|
+
return rb_funcall(pi->handler, oj_array_start_id, 0);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static void
|
|
101
|
+
end_array(ParseInfo pi) {
|
|
102
|
+
rb_funcall(pi->handler, oj_array_end_id, 0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static VALUE
|
|
106
|
+
calc_hash_key(ParseInfo pi, Val kval) {
|
|
107
|
+
volatile VALUE rkey = kval->key_val;
|
|
108
|
+
|
|
109
|
+
if (Qundef == rkey) {
|
|
110
|
+
rkey = rb_str_new(kval->key, kval->klen);
|
|
111
|
+
rkey = oj_encode(rkey);
|
|
112
|
+
if (Yes == pi->options.sym_key) {
|
|
113
|
+
rkey = rb_str_intern(rkey);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return rkey;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static VALUE
|
|
120
|
+
hash_key(struct _ParseInfo *pi, const char *key, size_t klen) {
|
|
121
|
+
return rb_funcall(pi->handler, oj_hash_key_id, 1, rb_str_new(key, klen));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static void
|
|
125
|
+
hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
|
126
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
|
127
|
+
|
|
128
|
+
rstr = oj_encode(rstr);
|
|
129
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), rstr);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static void
|
|
133
|
+
hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
134
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), oj_num_as_value(ni));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static void
|
|
138
|
+
hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
139
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static void
|
|
143
|
+
array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
144
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
|
145
|
+
|
|
146
|
+
rstr = oj_encode(rstr);
|
|
147
|
+
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static void
|
|
151
|
+
array_append_num(ParseInfo pi, NumInfo ni) {
|
|
152
|
+
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, oj_num_as_value(ni));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static void
|
|
156
|
+
array_append_value(ParseInfo pi, VALUE value) {
|
|
157
|
+
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, value);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
VALUE
|
|
161
|
+
oj_sc_parse(int argc, VALUE *argv, VALUE self) {
|
|
162
|
+
struct _ParseInfo pi;
|
|
163
|
+
VALUE input = argv[1];
|
|
164
|
+
|
|
165
|
+
parse_info_init(&pi);
|
|
166
|
+
pi.err_class = Qnil;
|
|
167
|
+
pi.max_depth = 0;
|
|
168
|
+
pi.options = oj_default_options;
|
|
169
|
+
if (3 == argc) {
|
|
170
|
+
oj_parse_options(argv[2], &pi.options);
|
|
171
|
+
}
|
|
172
|
+
if (rb_block_given_p()) {
|
|
173
|
+
pi.proc = Qnil;
|
|
174
|
+
} else {
|
|
175
|
+
pi.proc = Qundef;
|
|
176
|
+
}
|
|
177
|
+
pi.handler = *argv;
|
|
178
|
+
|
|
179
|
+
pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
|
|
180
|
+
pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
|
|
181
|
+
pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
|
|
182
|
+
pi.start_array = rb_respond_to(pi.handler, oj_array_start_id) ? start_array : noop_start;
|
|
183
|
+
pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
|
|
184
|
+
if (rb_respond_to(pi.handler, oj_hash_set_id)) {
|
|
185
|
+
pi.hash_set_value = hash_set_value;
|
|
186
|
+
pi.hash_set_cstr = hash_set_cstr;
|
|
187
|
+
pi.hash_set_num = hash_set_num;
|
|
188
|
+
pi.expect_value = 1;
|
|
189
|
+
} else {
|
|
190
|
+
pi.hash_set_value = noop_hash_set_value;
|
|
191
|
+
pi.hash_set_cstr = noop_hash_set_cstr;
|
|
192
|
+
pi.hash_set_num = noop_hash_set_num;
|
|
193
|
+
pi.expect_value = 0;
|
|
194
|
+
}
|
|
195
|
+
if (rb_respond_to(pi.handler, oj_array_append_id)) {
|
|
196
|
+
pi.array_append_value = array_append_value;
|
|
197
|
+
pi.array_append_cstr = array_append_cstr;
|
|
198
|
+
pi.array_append_num = array_append_num;
|
|
199
|
+
pi.expect_value = 1;
|
|
200
|
+
} else {
|
|
201
|
+
pi.array_append_value = noop_array_append_value;
|
|
202
|
+
pi.array_append_cstr = noop_array_append_cstr;
|
|
203
|
+
pi.array_append_num = noop_array_append_num;
|
|
204
|
+
pi.expect_value = 0;
|
|
205
|
+
}
|
|
206
|
+
if (rb_respond_to(pi.handler, oj_add_value_id)) {
|
|
207
|
+
pi.add_cstr = add_cstr;
|
|
208
|
+
pi.add_num = add_num;
|
|
209
|
+
pi.add_value = add_value;
|
|
210
|
+
pi.expect_value = 1;
|
|
211
|
+
} else {
|
|
212
|
+
pi.add_cstr = noop_add_cstr;
|
|
213
|
+
pi.add_num = noop_add_num;
|
|
214
|
+
pi.add_value = noop_add_value;
|
|
215
|
+
pi.expect_value = 0;
|
|
216
|
+
}
|
|
217
|
+
pi.has_callbacks = true;
|
|
218
|
+
|
|
219
|
+
if (T_STRING == rb_type(input)) {
|
|
220
|
+
return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
|
|
221
|
+
} else {
|
|
222
|
+
return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
|
|
223
|
+
}
|
|
224
|
+
}
|