oj 3.14.2 → 3.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +0 -1
- data/ext/oj/buf.h +2 -2
- data/ext/oj/cache.c +16 -16
- data/ext/oj/cache8.c +7 -7
- data/ext/oj/circarray.c +2 -1
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +2 -2
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +6 -14
- data/ext/oj/custom.c +1 -1
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +16 -16
- data/ext/oj/dump_compat.c +551 -576
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +35 -36
- data/ext/oj/dump_strict.c +2 -4
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +1 -1
- data/ext/oj/fast.c +24 -38
- data/ext/oj/intern.c +38 -42
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +211 -217
- data/ext/oj/mem.h +10 -10
- data/ext/oj/mimic_json.c +18 -24
- data/ext/oj/object.c +5 -5
- data/ext/oj/odd.c +2 -1
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +60 -81
- data/ext/oj/oj.h +53 -54
- data/ext/oj/parse.c +55 -118
- data/ext/oj/parse.h +5 -10
- data/ext/oj/parser.c +7 -8
- data/ext/oj/parser.h +7 -8
- data/ext/oj/rails.c +28 -59
- data/ext/oj/reader.c +5 -9
- data/ext/oj/reader.h +1 -1
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +4 -4
- data/ext/oj/saj2.c +32 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +18 -67
- data/ext/oj/stream_writer.c +5 -18
- data/ext/oj/strict.c +7 -13
- data/ext/oj/string_writer.c +6 -14
- data/ext/oj/trace.h +27 -16
- data/ext/oj/usual.c +62 -61
- data/ext/oj/usual.h +6 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.h +4 -4
- data/ext/oj/wab.c +7 -9
- data/lib/oj/active_support_helper.rb +0 -1
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +4 -2
- data/lib/oj/mimic.rb +4 -2
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +0 -1
- data/test/_test_active.rb +0 -1
- data/test/_test_active_mimic.rb +0 -1
- data/test/_test_mimic_rails.rb +0 -1
- data/test/activerecord/result_test.rb +5 -6
- data/test/bar.rb +3 -3
- data/test/files.rb +1 -1
- data/test/foo.rb +5 -48
- data/test/helper.rb +1 -4
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +4 -4
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +43 -32
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +46 -46
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/mem.rb +7 -7
- data/test/perf.rb +2 -2
- data/test/perf_compat.rb +1 -1
- data/test/perf_fast.rb +1 -1
- data/test/perf_file.rb +2 -2
- data/test/perf_object.rb +1 -2
- data/test/perf_once.rb +4 -4
- data/test/perf_parser.rb +1 -2
- data/test/perf_saj.rb +1 -2
- data/test/perf_scp.rb +1 -1
- data/test/perf_simple.rb +3 -3
- data/test/perf_strict.rb +1 -1
- data/test/perf_wab.rb +1 -1
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +2 -3
- data/test/sample_json.rb +0 -1
- data/test/test_compat.rb +11 -9
- data/test/test_custom.rb +5 -9
- data/test/test_debian.rb +1 -1
- data/test/test_fast.rb +10 -20
- data/test/test_file.rb +8 -8
- data/test/test_integer_range.rb +2 -2
- data/test/test_null.rb +5 -3
- data/test/test_object.rb +6 -5
- data/test/test_parser_saj.rb +23 -21
- data/test/test_parser_usual.rb +3 -3
- data/test/test_saj.rb +2 -0
- data/test/test_scp.rb +6 -6
- data/test/test_strict.rb +6 -4
- data/test/test_various.rb +21 -24
- data/test/test_wab.rb +6 -5
- data/test/test_writer.rb +1 -1
- metadata +17 -26
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
data/ext/oj/parser.h
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
#ifndef OJ_PARSER_H
|
5
5
|
#define OJ_PARSER_H
|
6
6
|
|
7
|
-
#include <stdbool.h>
|
8
7
|
#include <ruby.h>
|
8
|
+
#include <stdbool.h>
|
9
9
|
|
10
10
|
#include "buf.h"
|
11
11
|
|
@@ -38,7 +38,7 @@ typedef struct _num {
|
|
38
38
|
bool neg;
|
39
39
|
bool exp_neg;
|
40
40
|
// for numbers as strings, reuse buf
|
41
|
-
} *
|
41
|
+
} *Num;
|
42
42
|
|
43
43
|
struct _ojParser;
|
44
44
|
|
@@ -54,11 +54,11 @@ typedef struct _funcs {
|
|
54
54
|
void (*close_array)(struct _ojParser *p);
|
55
55
|
void (*open_object)(struct _ojParser *p);
|
56
56
|
void (*close_object)(struct _ojParser *p);
|
57
|
-
} *
|
57
|
+
} *Funcs;
|
58
58
|
|
59
59
|
typedef struct _ojParser {
|
60
|
-
const char
|
61
|
-
const char
|
60
|
+
const char *map;
|
61
|
+
const char *next_map;
|
62
62
|
int depth;
|
63
63
|
unsigned char stack[1024];
|
64
64
|
|
@@ -67,7 +67,7 @@ typedef struct _ojParser {
|
|
67
67
|
struct _buf key;
|
68
68
|
struct _buf buf;
|
69
69
|
|
70
|
-
struct _funcs funcs[3];
|
70
|
+
struct _funcs funcs[3]; // indexed by XXX_FUN defines
|
71
71
|
|
72
72
|
void (*start)(struct _ojParser *p);
|
73
73
|
VALUE (*option)(struct _ojParser *p, const char *key, VALUE value);
|
@@ -86,7 +86,7 @@ typedef struct _ojParser {
|
|
86
86
|
uint32_t ucode;
|
87
87
|
ojType type; // valType
|
88
88
|
bool just_one;
|
89
|
-
} *
|
89
|
+
} *ojParser;
|
90
90
|
|
91
91
|
// Create a new parser without setting the delegate. The parser is
|
92
92
|
// wrapped. The parser is (ojParser)DATA_PTR(value) where value is the return
|
@@ -98,5 +98,4 @@ extern VALUE oj_parser_new();
|
|
98
98
|
// Set set the options from a hash (ropts).
|
99
99
|
extern void oj_parser_set_option(ojParser p, VALUE ropts);
|
100
100
|
|
101
|
-
|
102
101
|
#endif /* OJ_PARSER_H */
|
data/ext/oj/rails.c
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
|
4
4
|
#include "rails.h"
|
5
5
|
|
6
|
-
#include "mem.h"
|
7
6
|
#include "code.h"
|
8
7
|
#include "encode.h"
|
8
|
+
#include "mem.h"
|
9
9
|
#include "trace.h"
|
10
10
|
#include "util.h"
|
11
11
|
|
@@ -16,7 +16,7 @@ typedef struct _encoder {
|
|
16
16
|
struct _rOptTable ropts;
|
17
17
|
struct _options opts;
|
18
18
|
VALUE arg;
|
19
|
-
} *
|
19
|
+
} *Encoder;
|
20
20
|
|
21
21
|
bool oj_rails_hash_opt = false;
|
22
22
|
bool oj_rails_array_opt = false;
|
@@ -141,7 +141,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
|
|
141
141
|
int cnt;
|
142
142
|
int i;
|
143
143
|
int len;
|
144
|
-
const char
|
144
|
+
const char *name;
|
145
145
|
|
146
146
|
#ifdef RSTRUCT_LEN
|
147
147
|
#if RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
|
@@ -200,7 +200,7 @@ static void dump_enumerable(VALUE obj, int depth, Out out, bool as_ok) {
|
|
200
200
|
|
201
201
|
static void dump_bigdecimal(VALUE obj, int depth, Out out, bool as_ok) {
|
202
202
|
volatile VALUE rstr = oj_safe_string_convert(obj);
|
203
|
-
const char
|
203
|
+
const char *str = RSTRING_PTR(rstr);
|
204
204
|
|
205
205
|
if ('I' == *str || 'N' == *str || ('-' == *str && 'I' == str[1])) {
|
206
206
|
oj_dump_nil(Qnil, depth, out, false);
|
@@ -263,14 +263,7 @@ static void dump_sec_nano(VALUE obj, int64_t sec, long nsec, Out out) {
|
|
263
263
|
tzmin);
|
264
264
|
} else if (0 == out->opts->sec_prec) {
|
265
265
|
if (0 == tzsecs && rb_funcall2(obj, oj_utcq_id, 0, 0)) {
|
266
|
-
len = sprintf(buf,
|
267
|
-
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
268
|
-
ti.year,
|
269
|
-
ti.mon,
|
270
|
-
ti.day,
|
271
|
-
ti.hour,
|
272
|
-
ti.min,
|
273
|
-
ti.sec);
|
266
|
+
len = sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02dZ", ti.year, ti.mon, ti.day, ti.hour, ti.min, ti.sec);
|
274
267
|
} else {
|
275
268
|
len = sprintf(buf,
|
276
269
|
"%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
|
@@ -301,18 +294,7 @@ static void dump_sec_nano(VALUE obj, int64_t sec, long nsec, Out out) {
|
|
301
294
|
format[32] = '0' + out->opts->sec_prec;
|
302
295
|
len -= 9 - out->opts->sec_prec;
|
303
296
|
}
|
304
|
-
len = sprintf(buf,
|
305
|
-
format,
|
306
|
-
ti.year,
|
307
|
-
ti.mon,
|
308
|
-
ti.day,
|
309
|
-
ti.hour,
|
310
|
-
ti.min,
|
311
|
-
ti.sec,
|
312
|
-
nsec,
|
313
|
-
tzsign,
|
314
|
-
tzhour,
|
315
|
-
tzmin);
|
297
|
+
len = sprintf(buf, format, ti.year, ti.mon, ti.day, ti.hour, ti.min, ti.sec, nsec, tzsign, tzhour, tzmin);
|
316
298
|
}
|
317
299
|
oj_dump_cstr(buf, len, 0, 0, out);
|
318
300
|
}
|
@@ -356,7 +338,7 @@ static ID parameters_id = 0;
|
|
356
338
|
typedef struct _strLen {
|
357
339
|
const char *str;
|
358
340
|
int len;
|
359
|
-
} *
|
341
|
+
} *StrLen;
|
360
342
|
|
361
343
|
static void dump_actioncontroller_parameters(VALUE obj, int depth, Out out, bool as_ok) {
|
362
344
|
if (0 == parameters_id) {
|
@@ -505,7 +487,7 @@ static void dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok)
|
|
505
487
|
typedef struct _namedFunc {
|
506
488
|
const char *name;
|
507
489
|
DumpFunc func;
|
508
|
-
} *
|
490
|
+
} *NamedFunc;
|
509
491
|
|
510
492
|
static void dump_as_string(VALUE obj, int depth, Out out, bool as_ok) {
|
511
493
|
if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
|
@@ -680,8 +662,8 @@ static VALUE encoder_new(int argc, VALUE *argv, VALUE self) {
|
|
680
662
|
static VALUE resolve_classpath(const char *name) {
|
681
663
|
char class_name[1024];
|
682
664
|
VALUE clas;
|
683
|
-
char
|
684
|
-
char
|
665
|
+
char *end = class_name + sizeof(class_name) - 1;
|
666
|
+
char *s;
|
685
667
|
const char *n = name;
|
686
668
|
ID cid;
|
687
669
|
|
@@ -747,8 +729,7 @@ static void optimize(int argc, VALUE *argv, ROptTable rot, bool on) {
|
|
747
729
|
oj_rails_float_opt = on;
|
748
730
|
} else if (oj_string_writer_class == *argv) {
|
749
731
|
string_writer_optimized = on;
|
750
|
-
} else if (NULL != (ro = oj_rails_get_opt(rot, *argv)) ||
|
751
|
-
NULL != (ro = create_opt(rot, *argv))) {
|
732
|
+
} else if (NULL != (ro = oj_rails_get_opt(rot, *argv)) || NULL != (ro = create_opt(rot, *argv))) {
|
752
733
|
ro->on = on;
|
753
734
|
}
|
754
735
|
}
|
@@ -810,7 +791,7 @@ rails_mimic_json(VALUE self) {
|
|
810
791
|
}
|
811
792
|
oj_mimic_json_methods(json);
|
812
793
|
// Setting the default mode breaks the prmoise in the docs not to.
|
813
|
-
//oj_default_options.mode = RailsMode;
|
794
|
+
// oj_default_options.mode = RailsMode;
|
814
795
|
|
815
796
|
return Qnil;
|
816
797
|
}
|
@@ -878,7 +859,7 @@ static VALUE rails_optimized(VALUE self, VALUE clas) {
|
|
878
859
|
typedef struct _oo {
|
879
860
|
Out out;
|
880
861
|
VALUE obj;
|
881
|
-
} *
|
862
|
+
} *OO;
|
882
863
|
|
883
864
|
static VALUE protect_dump(VALUE ov) {
|
884
865
|
OO oo = (OO)ov;
|
@@ -908,16 +889,16 @@ static VALUE encode(VALUE obj, ROptTable ropts, Options opts, int argc, VALUE *a
|
|
908
889
|
|
909
890
|
oj_out_init(&out);
|
910
891
|
|
911
|
-
out.omit_nil
|
912
|
-
out.caller
|
913
|
-
out.cur
|
914
|
-
out.circ_cnt
|
915
|
-
out.opts
|
916
|
-
out.hash_cnt
|
917
|
-
out.indent
|
918
|
-
out.argc
|
919
|
-
out.argv
|
920
|
-
out.ropts
|
892
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
893
|
+
out.caller = 0;
|
894
|
+
out.cur = out.buf;
|
895
|
+
out.circ_cnt = 0;
|
896
|
+
out.opts = &copts;
|
897
|
+
out.hash_cnt = 0;
|
898
|
+
out.indent = copts.indent;
|
899
|
+
out.argc = argc;
|
900
|
+
out.argv = argv;
|
901
|
+
out.ropts = ropts;
|
921
902
|
if (Yes == copts.circular) {
|
922
903
|
oj_cache8_new(&out.circ_cache);
|
923
904
|
}
|
@@ -1062,28 +1043,16 @@ static VALUE rails_set_encoder(VALUE self) {
|
|
1062
1043
|
verbose = rb_gv_get("$VERBOSE");
|
1063
1044
|
rb_gv_set("$VERBOSE", Qfalse);
|
1064
1045
|
rb_undef_method(encoding, "use_standard_json_time_format=");
|
1065
|
-
rb_define_module_function(encoding,
|
1066
|
-
"use_standard_json_time_format=",
|
1067
|
-
rails_use_standard_json_time_format,
|
1068
|
-
1);
|
1046
|
+
rb_define_module_function(encoding, "use_standard_json_time_format=", rails_use_standard_json_time_format, 1);
|
1069
1047
|
rb_undef_method(encoding, "use_standard_json_time_format");
|
1070
|
-
rb_define_module_function(encoding,
|
1071
|
-
"use_standard_json_time_format",
|
1072
|
-
rails_use_standard_json_time_format_get,
|
1073
|
-
0);
|
1048
|
+
rb_define_module_function(encoding, "use_standard_json_time_format", rails_use_standard_json_time_format_get, 0);
|
1074
1049
|
|
1075
1050
|
pv = rb_iv_get(encoding, "@escape_html_entities_in_json");
|
1076
1051
|
escape_html = Qtrue == pv;
|
1077
1052
|
rb_undef_method(encoding, "escape_html_entities_in_json=");
|
1078
|
-
rb_define_module_function(encoding,
|
1079
|
-
"escape_html_entities_in_json=",
|
1080
|
-
rails_escape_html_entities_in_json,
|
1081
|
-
1);
|
1053
|
+
rb_define_module_function(encoding, "escape_html_entities_in_json=", rails_escape_html_entities_in_json, 1);
|
1082
1054
|
rb_undef_method(encoding, "escape_html_entities_in_json");
|
1083
|
-
rb_define_module_function(encoding,
|
1084
|
-
"escape_html_entities_in_json",
|
1085
|
-
rails_escape_html_entities_in_json_get,
|
1086
|
-
0);
|
1055
|
+
rb_define_module_function(encoding, "escape_html_entities_in_json", rails_escape_html_entities_in_json_get, 0);
|
1087
1056
|
|
1088
1057
|
pv = rb_iv_get(encoding, "@time_precision");
|
1089
1058
|
oj_default_options.sec_prec = NUM2INT(pv);
|
@@ -1185,7 +1154,7 @@ static void dump_to_hash(VALUE obj, int depth, Out out) {
|
|
1185
1154
|
|
1186
1155
|
static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
1187
1156
|
char buf[64];
|
1188
|
-
char
|
1157
|
+
char *b;
|
1189
1158
|
double d = rb_num2dbl(obj);
|
1190
1159
|
int cnt = 0;
|
1191
1160
|
|
data/ext/oj/reader.c
CHANGED
@@ -64,8 +64,7 @@ void oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
|
|
64
64
|
reader->tail = reader->head;
|
65
65
|
reader->read_end = reader->head + RSTRING_LEN(s);
|
66
66
|
} else if (rb_cFile == io_class && Qnil != (stat = rb_funcall(io, oj_stat_id, 0)) &&
|
67
|
-
Qnil != (ftype = rb_funcall(stat, oj_ftype_id, 0)) &&
|
68
|
-
0 == strcmp("file", StringValuePtr(ftype)) &&
|
67
|
+
Qnil != (ftype = rb_funcall(stat, oj_ftype_id, 0)) && 0 == strcmp("file", StringValuePtr(ftype)) &&
|
69
68
|
0 == FIX2INT(rb_funcall(io, oj_pos_id, 0))) {
|
70
69
|
reader->read_func = read_from_fd;
|
71
70
|
reader->fd = FIX2INT(rb_funcall(io, oj_fileno_id, 0));
|
@@ -84,8 +83,7 @@ void oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
|
|
84
83
|
reader->tail = reader->head;
|
85
84
|
reader->read_end = reader->head + RSTRING_LEN(rstr);
|
86
85
|
} else {
|
87
|
-
rb_raise(rb_eArgError,
|
88
|
-
"parser io argument must be a String or respond to readpartial() or read().\n");
|
86
|
+
rb_raise(rb_eArgError, "parser io argument must be a String or respond to readpartial() or read().\n");
|
89
87
|
}
|
90
88
|
}
|
91
89
|
|
@@ -124,9 +122,7 @@ int oj_reader_read(Reader reader) {
|
|
124
122
|
reader->str = reader->head + (reader->str - old);
|
125
123
|
}
|
126
124
|
} else {
|
127
|
-
memmove((char *)reader->head,
|
128
|
-
reader->head + shift,
|
129
|
-
reader->read_end - (reader->head + shift));
|
125
|
+
memmove((char *)reader->head, reader->head + shift, reader->read_end - (reader->head + shift));
|
130
126
|
reader->tail -= shift;
|
131
127
|
reader->read_end -= shift;
|
132
128
|
if (0 != reader->pro) {
|
@@ -158,7 +154,7 @@ static VALUE partial_io_cb(VALUE rbuf) {
|
|
158
154
|
Reader reader = (Reader)rbuf;
|
159
155
|
VALUE args[1];
|
160
156
|
VALUE rstr;
|
161
|
-
char
|
157
|
+
char *str;
|
162
158
|
size_t cnt;
|
163
159
|
|
164
160
|
args[0] = ULONG2NUM(reader->end - reader->tail);
|
@@ -179,7 +175,7 @@ static VALUE io_cb(VALUE rbuf) {
|
|
179
175
|
Reader reader = (Reader)rbuf;
|
180
176
|
VALUE args[1];
|
181
177
|
VALUE rstr;
|
182
|
-
char
|
178
|
+
char *str;
|
183
179
|
size_t cnt;
|
184
180
|
|
185
181
|
args[0] = ULONG2NUM(reader->end - reader->tail);
|
data/ext/oj/reader.h
CHANGED
data/ext/oj/resolve.c
CHANGED
@@ -27,12 +27,11 @@ inline static VALUE resolve_classname(VALUE mod, const char *classname, int auto
|
|
27
27
|
return clas;
|
28
28
|
}
|
29
29
|
|
30
|
-
static VALUE
|
31
|
-
resolve_classpath(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class) {
|
30
|
+
static VALUE resolve_classpath(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class) {
|
32
31
|
char class_name[1024];
|
33
32
|
VALUE clas;
|
34
|
-
char
|
35
|
-
char
|
33
|
+
char *end = class_name + sizeof(class_name) - 1;
|
34
|
+
char *s;
|
36
35
|
const char *n = name;
|
37
36
|
|
38
37
|
clas = rb_cObject;
|
data/ext/oj/rxclass.c
CHANGED
data/ext/oj/rxclass.h
CHANGED
data/ext/oj/saj.c
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
// Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
|
15
15
|
#define OJ_INFINITY (1.0 / 0.0)
|
16
16
|
|
17
|
-
#include "mem.h"
|
18
17
|
#include "encode.h"
|
18
|
+
#include "mem.h"
|
19
19
|
#include "oj.h"
|
20
20
|
|
21
21
|
typedef struct _parseInfo {
|
@@ -29,7 +29,7 @@ typedef struct _parseInfo {
|
|
29
29
|
int has_array_end;
|
30
30
|
int has_add_value;
|
31
31
|
int has_error;
|
32
|
-
} *
|
32
|
+
} *ParseInfo;
|
33
33
|
|
34
34
|
static void read_next(ParseInfo pi, const char *key);
|
35
35
|
static void read_hash(ParseInfo pi, const char *key);
|
@@ -642,7 +642,7 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
|
|
642
642
|
s = rb_funcall2(input, oj_string_id, 0, 0);
|
643
643
|
len = RSTRING_LEN(s) + 1;
|
644
644
|
json = OJ_R_ALLOC_N(char, len);
|
645
|
-
strcpy(json,
|
645
|
+
strcpy(json, StringValueCStr(s));
|
646
646
|
#if !IS_WINDOWS
|
647
647
|
} else if (rb_cFile == clas && 0 == FIX2INT(rb_funcall(input, oj_pos_id, 0))) {
|
648
648
|
int fd = FIX2INT(rb_funcall(input, oj_fileno_id, 0));
|
@@ -660,7 +660,7 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
|
|
660
660
|
s = rb_funcall2(input, oj_read_id, 0, 0);
|
661
661
|
len = RSTRING_LEN(s) + 1;
|
662
662
|
json = OJ_R_ALLOC_N(char, len);
|
663
|
-
strcpy(json,
|
663
|
+
strcpy(json, StringValueCStr(s));
|
664
664
|
} else {
|
665
665
|
rb_raise(rb_eArgError, "saj_parse() expected a String or IO Object.");
|
666
666
|
}
|
data/ext/oj/saj2.c
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
// Copyright (c) 2021, Peter Ohler, All rights reserved.
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "saj2.h"
|
4
|
+
|
4
5
|
#include "cache.h"
|
6
|
+
#include "mem.h"
|
5
7
|
#include "oj.h"
|
6
8
|
#include "parser.h"
|
7
|
-
#include "saj2.h"
|
8
9
|
|
9
10
|
static VALUE get_key(ojParser p) {
|
10
|
-
Saj
|
11
|
+
Saj d = (Saj)p->ctx;
|
11
12
|
const char *key = buf_str(&p->key);
|
12
13
|
size_t len = buf_len(&p->key);
|
13
14
|
volatile VALUE rkey;
|
@@ -44,7 +45,7 @@ static void open_object_loc(ojParser p) {
|
|
44
45
|
}
|
45
46
|
|
46
47
|
static void open_object_key(ojParser p) {
|
47
|
-
Saj
|
48
|
+
Saj d = (Saj)p->ctx;
|
48
49
|
volatile VALUE key = get_key(p);
|
49
50
|
|
50
51
|
push_key(d, key);
|
@@ -52,7 +53,7 @@ static void open_object_key(ojParser p) {
|
|
52
53
|
}
|
53
54
|
|
54
55
|
static void open_object_loc_key(ojParser p) {
|
55
|
-
Saj
|
56
|
+
Saj d = (Saj)p->ctx;
|
56
57
|
volatile VALUE key = get_key(p);
|
57
58
|
|
58
59
|
push_key(d, key);
|
@@ -68,7 +69,7 @@ static void open_array_loc(ojParser p) {
|
|
68
69
|
}
|
69
70
|
|
70
71
|
static void open_array_key(ojParser p) {
|
71
|
-
Saj
|
72
|
+
Saj d = (Saj)p->ctx;
|
72
73
|
volatile VALUE key = get_key(p);
|
73
74
|
|
74
75
|
push_key(d, key);
|
@@ -76,7 +77,7 @@ static void open_array_key(ojParser p) {
|
|
76
77
|
}
|
77
78
|
|
78
79
|
static void open_array_loc_key(ojParser p) {
|
79
|
-
Saj
|
80
|
+
Saj d = (Saj)p->ctx;
|
80
81
|
volatile VALUE key = get_key(p);
|
81
82
|
|
82
83
|
push_key(d, key);
|
@@ -84,8 +85,8 @@ static void open_array_loc_key(ojParser p) {
|
|
84
85
|
}
|
85
86
|
|
86
87
|
static void close_object(ojParser p) {
|
87
|
-
Saj
|
88
|
-
VALUE
|
88
|
+
Saj d = (Saj)p->ctx;
|
89
|
+
VALUE key = Qnil;
|
89
90
|
|
90
91
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
91
92
|
d->tail--;
|
@@ -98,8 +99,8 @@ static void close_object(ojParser p) {
|
|
98
99
|
}
|
99
100
|
|
100
101
|
static void close_object_loc(ojParser p) {
|
101
|
-
Saj
|
102
|
-
VALUE
|
102
|
+
Saj d = (Saj)p->ctx;
|
103
|
+
VALUE key = Qnil;
|
103
104
|
|
104
105
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
105
106
|
d->tail--;
|
@@ -112,8 +113,8 @@ static void close_object_loc(ojParser p) {
|
|
112
113
|
}
|
113
114
|
|
114
115
|
static void close_array(ojParser p) {
|
115
|
-
Saj
|
116
|
-
VALUE
|
116
|
+
Saj d = (Saj)p->ctx;
|
117
|
+
VALUE key = Qnil;
|
117
118
|
|
118
119
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
119
120
|
d->tail--;
|
@@ -126,8 +127,8 @@ static void close_array(ojParser p) {
|
|
126
127
|
}
|
127
128
|
|
128
129
|
static void close_array_loc(ojParser p) {
|
129
|
-
Saj
|
130
|
-
VALUE
|
130
|
+
Saj d = (Saj)p->ctx;
|
131
|
+
VALUE key = Qnil;
|
131
132
|
|
132
133
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
133
134
|
d->tail--;
|
@@ -144,13 +145,7 @@ static void add_null(ojParser p) {
|
|
144
145
|
}
|
145
146
|
|
146
147
|
static void add_null_loc(ojParser p) {
|
147
|
-
rb_funcall(((Saj)p->ctx)->handler,
|
148
|
-
oj_add_value_id,
|
149
|
-
4,
|
150
|
-
Qnil,
|
151
|
-
Qnil,
|
152
|
-
LONG2FIX(p->line),
|
153
|
-
LONG2FIX(p->cur - p->col));
|
148
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 4, Qnil, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
154
149
|
}
|
155
150
|
|
156
151
|
static void add_null_key(ojParser p) {
|
@@ -172,13 +167,7 @@ static void add_true(ojParser p) {
|
|
172
167
|
}
|
173
168
|
|
174
169
|
static void add_true_loc(ojParser p) {
|
175
|
-
rb_funcall(((Saj)p->ctx)->handler,
|
176
|
-
oj_add_value_id,
|
177
|
-
4,
|
178
|
-
Qtrue,
|
179
|
-
Qnil,
|
180
|
-
LONG2FIX(p->line),
|
181
|
-
LONG2FIX(p->cur - p->col));
|
170
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 4, Qtrue, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
182
171
|
}
|
183
172
|
|
184
173
|
static void add_true_key(ojParser p) {
|
@@ -200,13 +189,7 @@ static void add_false(ojParser p) {
|
|
200
189
|
}
|
201
190
|
|
202
191
|
static void add_false_loc(ojParser p) {
|
203
|
-
rb_funcall(((Saj)p->ctx)->handler,
|
204
|
-
oj_add_value_id,
|
205
|
-
4,
|
206
|
-
Qfalse,
|
207
|
-
Qnil,
|
208
|
-
LONG2FIX(p->line),
|
209
|
-
LONG2FIX(p->cur - p->col));
|
192
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 4, Qfalse, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
210
193
|
}
|
211
194
|
|
212
195
|
static void add_false_key(ojParser p) {
|
@@ -316,7 +299,7 @@ static void add_big_key_loc(ojParser p) {
|
|
316
299
|
}
|
317
300
|
|
318
301
|
static void add_str(ojParser p) {
|
319
|
-
Saj
|
302
|
+
Saj d = (Saj)p->ctx;
|
320
303
|
volatile VALUE rstr;
|
321
304
|
const char *str = buf_str(&p->buf);
|
322
305
|
size_t len = buf_len(&p->buf);
|
@@ -330,7 +313,7 @@ static void add_str(ojParser p) {
|
|
330
313
|
}
|
331
314
|
|
332
315
|
static void add_str_loc(ojParser p) {
|
333
|
-
Saj
|
316
|
+
Saj d = (Saj)p->ctx;
|
334
317
|
volatile VALUE rstr;
|
335
318
|
const char *str = buf_str(&p->buf);
|
336
319
|
size_t len = buf_len(&p->buf);
|
@@ -344,7 +327,7 @@ static void add_str_loc(ojParser p) {
|
|
344
327
|
}
|
345
328
|
|
346
329
|
static void add_str_key(ojParser p) {
|
347
|
-
Saj
|
330
|
+
Saj d = (Saj)p->ctx;
|
348
331
|
volatile VALUE rstr;
|
349
332
|
const char *str = buf_str(&p->buf);
|
350
333
|
size_t len = buf_len(&p->buf);
|
@@ -358,7 +341,7 @@ static void add_str_key(ojParser p) {
|
|
358
341
|
}
|
359
342
|
|
360
343
|
static void add_str_key_loc(ojParser p) {
|
361
|
-
Saj
|
344
|
+
Saj d = (Saj)p->ctx;
|
362
345
|
volatile VALUE rstr;
|
363
346
|
const char *str = buf_str(&p->buf);
|
364
347
|
size_t len = buf_len(&p->buf);
|
@@ -557,8 +540,8 @@ static void mark(ojParser p) {
|
|
557
540
|
if (NULL == p || NULL == p->ctx) {
|
558
541
|
return;
|
559
542
|
}
|
560
|
-
Saj
|
561
|
-
VALUE
|
543
|
+
Saj d = (Saj)p->ctx;
|
544
|
+
VALUE *kp;
|
562
545
|
|
563
546
|
cache_mark(d->str_cache);
|
564
547
|
if (Qnil != d->handler) {
|
@@ -576,13 +559,13 @@ static VALUE form_str(const char *str, size_t len) {
|
|
576
559
|
}
|
577
560
|
|
578
561
|
void oj_init_saj(ojParser p, Saj d) {
|
579
|
-
d->klen
|
580
|
-
d->keys
|
581
|
-
d->tail
|
582
|
-
d->handler
|
583
|
-
d->str_cache
|
584
|
-
d->cache_str
|
585
|
-
d->cache_keys
|
562
|
+
d->klen = 256;
|
563
|
+
d->keys = OJ_R_ALLOC_N(VALUE, d->klen);
|
564
|
+
d->tail = d->keys;
|
565
|
+
d->handler = Qnil;
|
566
|
+
d->str_cache = cache_create(0, form_str, true, false);
|
567
|
+
d->cache_str = 16;
|
568
|
+
d->cache_keys = true;
|
586
569
|
d->thread_safe = false;
|
587
570
|
|
588
571
|
p->ctx = (void *)d;
|
data/ext/oj/saj2.h
CHANGED
@@ -15,7 +15,7 @@ typedef struct _saj {
|
|
15
15
|
uint8_t cache_str;
|
16
16
|
bool cache_keys;
|
17
17
|
bool thread_safe;
|
18
|
-
} *
|
18
|
+
} *Saj;
|
19
19
|
|
20
20
|
// Initialize the parser with the SAJ delegate. If the SAJ delegate is wrapped
|
21
21
|
// then this function is called first and then the parser functions can be
|
data/ext/oj/scp.c
CHANGED
@@ -33,8 +33,7 @@ static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
|
33
33
|
return Qundef;
|
34
34
|
}
|
35
35
|
|
36
|
-
static void
|
37
|
-
noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
36
|
+
static void noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
38
37
|
}
|
39
38
|
|
40
39
|
static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
@@ -91,12 +90,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
91
90
|
volatile VALUE rstr = rb_str_new(str, len);
|
92
91
|
|
93
92
|
rstr = oj_encode(rstr);
|
94
|
-
rb_funcall(pi->handler,
|
95
|
-
oj_hash_set_id,
|
96
|
-
3,
|
97
|
-
stack_peek(&pi->stack)->val,
|
98
|
-
oj_calc_hash_key(pi, kval),
|
99
|
-
rstr);
|
93
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), rstr);
|
100
94
|
}
|
101
95
|
|
102
96
|
static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
@@ -109,12 +103,7 @@ static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
109
103
|
}
|
110
104
|
|
111
105
|
static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
112
|
-
rb_funcall(pi->handler,
|
113
|
-
oj_hash_set_id,
|
114
|
-
3,
|
115
|
-
stack_peek(&pi->stack)->val,
|
116
|
-
oj_calc_hash_key(pi, kval),
|
117
|
-
value);
|
106
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), value);
|
118
107
|
}
|
119
108
|
|
120
109
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|