oj 3.14.2 → 3.14.3
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 +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/usual.c
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
// Copyright (c) 2021, Peter Ohler, All rights reserved.
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "usual.h"
|
4
|
+
|
4
5
|
#include "cache.h"
|
6
|
+
#include "mem.h"
|
5
7
|
#include "oj.h"
|
6
8
|
#include "parser.h"
|
7
|
-
#include "usual.h"
|
8
9
|
|
9
10
|
// The Usual delegate builds Ruby objects during parsing. It makes use of
|
10
11
|
// three stacks. The first is the value stack. This is where parsed values are
|
@@ -90,8 +91,8 @@ static VALUE resolve_classname(VALUE mod, const char *classname, bool auto_defin
|
|
90
91
|
static VALUE resolve_classpath(const char *name, size_t len, bool auto_define) {
|
91
92
|
char class_name[1024];
|
92
93
|
VALUE clas;
|
93
|
-
char
|
94
|
-
char
|
94
|
+
char *end = class_name + sizeof(class_name) - 1;
|
95
|
+
char *s;
|
95
96
|
const char *n = name;
|
96
97
|
|
97
98
|
clas = rb_cObject;
|
@@ -186,7 +187,7 @@ static ID get_attr_id(ojParser p, Key kp) {
|
|
186
187
|
}
|
187
188
|
|
188
189
|
static void push_key(ojParser p) {
|
189
|
-
Usual
|
190
|
+
Usual d = (Usual)p->ctx;
|
190
191
|
size_t klen = buf_len(&p->key);
|
191
192
|
const char *key = buf_str(&p->key);
|
192
193
|
|
@@ -270,14 +271,14 @@ static void open_array_key(ojParser p) {
|
|
270
271
|
}
|
271
272
|
|
272
273
|
static void close_object(ojParser p) {
|
273
|
-
VALUE *
|
274
|
-
Usual
|
274
|
+
VALUE *vp;
|
275
|
+
Usual d = (Usual)p->ctx;
|
275
276
|
|
276
277
|
d->ctail--;
|
277
278
|
|
278
279
|
Col c = d->ctail;
|
279
280
|
Key kp = d->khead + c->ki;
|
280
|
-
VALUE
|
281
|
+
VALUE *head = d->vhead + c->vi + 1;
|
281
282
|
volatile VALUE obj = rb_hash_new();
|
282
283
|
|
283
284
|
#if HAVE_RB_HASH_BULK_INSERT
|
@@ -303,14 +304,14 @@ static void close_object(ojParser p) {
|
|
303
304
|
}
|
304
305
|
|
305
306
|
static void close_object_class(ojParser p) {
|
306
|
-
VALUE *
|
307
|
-
Usual
|
307
|
+
VALUE *vp;
|
308
|
+
Usual d = (Usual)p->ctx;
|
308
309
|
|
309
310
|
d->ctail--;
|
310
311
|
|
311
312
|
Col c = d->ctail;
|
312
313
|
Key kp = d->khead + c->ki;
|
313
|
-
VALUE
|
314
|
+
VALUE *head = d->vhead + c->vi + 1;
|
314
315
|
volatile VALUE obj = rb_class_new_instance(0, NULL, d->hash_class);
|
315
316
|
|
316
317
|
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
@@ -326,14 +327,14 @@ static void close_object_class(ojParser p) {
|
|
326
327
|
}
|
327
328
|
|
328
329
|
static void close_object_create(ojParser p) {
|
329
|
-
VALUE *
|
330
|
-
Usual
|
330
|
+
VALUE *vp;
|
331
|
+
Usual d = (Usual)p->ctx;
|
331
332
|
|
332
333
|
d->ctail--;
|
333
334
|
|
334
335
|
Col c = d->ctail;
|
335
336
|
Key kp = d->khead + c->ki;
|
336
|
-
VALUE
|
337
|
+
VALUE *head = d->vhead + c->vi;
|
337
338
|
volatile VALUE obj;
|
338
339
|
|
339
340
|
if (Qundef == *head) {
|
@@ -409,7 +410,7 @@ static void close_array(ojParser p) {
|
|
409
410
|
Usual d = (Usual)p->ctx;
|
410
411
|
|
411
412
|
d->ctail--;
|
412
|
-
VALUE
|
413
|
+
VALUE *head = d->vhead + d->ctail->vi + 1;
|
413
414
|
volatile VALUE a = rb_ary_new_from_values(d->vtail - head, head);
|
414
415
|
|
415
416
|
d->vtail = head;
|
@@ -418,11 +419,11 @@ static void close_array(ojParser p) {
|
|
418
419
|
}
|
419
420
|
|
420
421
|
static void close_array_class(ojParser p) {
|
421
|
-
VALUE *
|
422
|
-
Usual
|
422
|
+
VALUE *vp;
|
423
|
+
Usual d = (Usual)p->ctx;
|
423
424
|
|
424
425
|
d->ctail--;
|
425
|
-
VALUE
|
426
|
+
VALUE *head = d->vhead + d->ctail->vi + 1;
|
426
427
|
volatile VALUE a = rb_class_new_instance(0, NULL, d->array_class);
|
427
428
|
|
428
429
|
for (vp = head; vp < d->vtail; vp++) {
|
@@ -532,9 +533,9 @@ static void add_big_as_ruby_key(ojParser p) {
|
|
532
533
|
}
|
533
534
|
|
534
535
|
static void add_str(ojParser p) {
|
535
|
-
Usual
|
536
|
+
Usual d = (Usual)p->ctx;
|
536
537
|
volatile VALUE rstr;
|
537
|
-
const char
|
538
|
+
const char *str = buf_str(&p->buf);
|
538
539
|
size_t len = buf_len(&p->buf);
|
539
540
|
|
540
541
|
if (len < d->cache_str) {
|
@@ -546,9 +547,9 @@ static void add_str(ojParser p) {
|
|
546
547
|
}
|
547
548
|
|
548
549
|
static void add_str_key(ojParser p) {
|
549
|
-
Usual
|
550
|
+
Usual d = (Usual)p->ctx;
|
550
551
|
volatile VALUE rstr;
|
551
|
-
const char
|
552
|
+
const char *str = buf_str(&p->buf);
|
552
553
|
size_t len = buf_len(&p->buf);
|
553
554
|
|
554
555
|
if (len < d->cache_str) {
|
@@ -561,11 +562,11 @@ static void add_str_key(ojParser p) {
|
|
561
562
|
}
|
562
563
|
|
563
564
|
static void add_str_key_create(ojParser p) {
|
564
|
-
Usual
|
565
|
+
Usual d = (Usual)p->ctx;
|
565
566
|
volatile VALUE rstr;
|
566
|
-
const char
|
567
|
+
const char *str = buf_str(&p->buf);
|
567
568
|
size_t len = buf_len(&p->buf);
|
568
|
-
const char
|
569
|
+
const char *key = buf_str(&p->key);
|
569
570
|
size_t klen = buf_len(&p->key);
|
570
571
|
|
571
572
|
if (klen == (size_t)d->create_id_len && 0 == strncmp(d->create_id, key, klen)) {
|
@@ -634,8 +635,8 @@ static void mark(ojParser p) {
|
|
634
635
|
if (NULL == p || NULL == p->ctx) {
|
635
636
|
return;
|
636
637
|
}
|
637
|
-
Usual
|
638
|
-
VALUE *
|
638
|
+
Usual d = (Usual)p->ctx;
|
639
|
+
VALUE *vp;
|
639
640
|
|
640
641
|
if (NULL == d) {
|
641
642
|
return;
|
@@ -729,7 +730,7 @@ static VALUE opt_cache_strings(ojParser p, VALUE value) {
|
|
729
730
|
|
730
731
|
static VALUE opt_cache_strings_set(ojParser p, VALUE value) {
|
731
732
|
Usual d = (Usual)p->ctx;
|
732
|
-
int
|
733
|
+
int limit = NUM2INT(value);
|
733
734
|
|
734
735
|
if (CACHE_MAX_KEY < limit) {
|
735
736
|
limit = CACHE_MAX_KEY;
|
@@ -749,7 +750,7 @@ static VALUE opt_cache_expunge(ojParser p, VALUE value) {
|
|
749
750
|
|
750
751
|
static VALUE opt_cache_expunge_set(ojParser p, VALUE value) {
|
751
752
|
Usual d = (Usual)p->ctx;
|
752
|
-
int
|
753
|
+
int rate = NUM2INT(value);
|
753
754
|
|
754
755
|
if (rate < 0) {
|
755
756
|
rate = 0;
|
@@ -773,7 +774,7 @@ static VALUE opt_capacity(ojParser p, VALUE value) {
|
|
773
774
|
|
774
775
|
static VALUE opt_capacity_set(ojParser p, VALUE value) {
|
775
776
|
Usual d = (Usual)p->ctx;
|
776
|
-
long
|
777
|
+
long cap = NUM2LONG(value);
|
777
778
|
|
778
779
|
if (d->vend - d->vhead < cap) {
|
779
780
|
long pos = d->vtail - d->vhead;
|
@@ -871,7 +872,7 @@ static VALUE opt_decimal(ojParser p, VALUE value) {
|
|
871
872
|
}
|
872
873
|
|
873
874
|
static VALUE opt_decimal_set(ojParser p, VALUE value) {
|
874
|
-
const char
|
875
|
+
const char *mode;
|
875
876
|
volatile VALUE s;
|
876
877
|
|
877
878
|
switch (rb_type(value)) {
|
@@ -987,8 +988,8 @@ static VALUE opt_missing_class(ojParser p, VALUE value) {
|
|
987
988
|
}
|
988
989
|
|
989
990
|
static VALUE opt_missing_class_set(ojParser p, VALUE value) {
|
990
|
-
Usual
|
991
|
-
const char
|
991
|
+
Usual d = (Usual)p->ctx;
|
992
|
+
const char *mode;
|
992
993
|
volatile VALUE s;
|
993
994
|
|
994
995
|
switch (rb_type(value)) {
|
@@ -1068,33 +1069,33 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
|
|
1068
1069
|
static VALUE option(ojParser p, const char *key, VALUE value) {
|
1069
1070
|
struct opt *op;
|
1070
1071
|
struct opt opts[] = {
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1072
|
+
{.name = "array_class", .func = opt_array_class},
|
1073
|
+
{.name = "array_class=", .func = opt_array_class_set},
|
1074
|
+
{.name = "cache_keys", .func = opt_cache_keys},
|
1075
|
+
{.name = "cache_keys=", .func = opt_cache_keys_set},
|
1076
|
+
{.name = "cache_strings", .func = opt_cache_strings},
|
1077
|
+
{.name = "cache_strings=", .func = opt_cache_strings_set},
|
1078
|
+
{.name = "cache_expunge", .func = opt_cache_expunge},
|
1079
|
+
{.name = "cache_expunge=", .func = opt_cache_expunge_set},
|
1080
|
+
{.name = "capacity", .func = opt_capacity},
|
1081
|
+
{.name = "capacity=", .func = opt_capacity_set},
|
1082
|
+
{.name = "class_cache", .func = opt_class_cache},
|
1083
|
+
{.name = "class_cache=", .func = opt_class_cache_set},
|
1084
|
+
{.name = "create_id", .func = opt_create_id},
|
1085
|
+
{.name = "create_id=", .func = opt_create_id_set},
|
1086
|
+
{.name = "decimal", .func = opt_decimal},
|
1087
|
+
{.name = "decimal=", .func = opt_decimal_set},
|
1088
|
+
{.name = "hash_class", .func = opt_hash_class},
|
1089
|
+
{.name = "hash_class=", .func = opt_hash_class_set},
|
1090
|
+
{.name = "ignore_json_create", .func = opt_ignore_json_create},
|
1091
|
+
{.name = "ignore_json_create=", .func = opt_ignore_json_create_set},
|
1092
|
+
{.name = "missing_class", .func = opt_missing_class},
|
1093
|
+
{.name = "missing_class=", .func = opt_missing_class_set},
|
1094
|
+
{.name = "omit_null", .func = opt_omit_null},
|
1095
|
+
{.name = "omit_null=", .func = opt_omit_null_set},
|
1096
|
+
{.name = "symbol_keys", .func = opt_symbol_keys},
|
1097
|
+
{.name = "symbol_keys=", .func = opt_symbol_keys_set},
|
1098
|
+
{.name = NULL},
|
1098
1099
|
};
|
1099
1100
|
|
1100
1101
|
for (op = opts; NULL != op->name; op++) {
|
@@ -1110,7 +1111,7 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
|
|
1110
1111
|
///// the set up //////////////////////////////////////////////////////////////
|
1111
1112
|
|
1112
1113
|
void oj_init_usual(ojParser p, Usual d) {
|
1113
|
-
int
|
1114
|
+
int cap = 4096;
|
1114
1115
|
|
1115
1116
|
d->vhead = OJ_R_ALLOC_N(VALUE, cap);
|
1116
1117
|
d->vend = d->vhead + cap;
|
data/ext/oj/usual.h
CHANGED
@@ -13,7 +13,7 @@ struct _ojParser;
|
|
13
13
|
typedef struct _col {
|
14
14
|
long vi; // value stack index
|
15
15
|
long ki; // key stack index if an hash else -1 for an array
|
16
|
-
} *
|
16
|
+
} *Col;
|
17
17
|
|
18
18
|
typedef union _key {
|
19
19
|
struct {
|
@@ -22,9 +22,9 @@ typedef union _key {
|
|
22
22
|
};
|
23
23
|
struct {
|
24
24
|
int16_t xlen; // should be the same as len
|
25
|
-
char
|
25
|
+
char *key;
|
26
26
|
};
|
27
|
-
} *
|
27
|
+
} *Key;
|
28
28
|
|
29
29
|
#define MISS_AUTO 'A'
|
30
30
|
#define MISS_RAISE 'R'
|
@@ -43,7 +43,7 @@ typedef struct _usual {
|
|
43
43
|
Key ktail;
|
44
44
|
Key kend;
|
45
45
|
|
46
|
-
VALUE (*get_key)(
|
46
|
+
VALUE (*get_key)(struct _ojParser *p, Key kp);
|
47
47
|
struct _cache *key_cache; // same as str_cache or sym_cache
|
48
48
|
struct _cache *str_cache;
|
49
49
|
struct _cache *sym_cache;
|
@@ -53,14 +53,14 @@ typedef struct _usual {
|
|
53
53
|
VALUE array_class;
|
54
54
|
VALUE hash_class;
|
55
55
|
|
56
|
-
char
|
56
|
+
char *create_id;
|
57
57
|
uint8_t create_id_len;
|
58
58
|
uint8_t cache_str;
|
59
59
|
uint8_t cache_xrate;
|
60
60
|
uint8_t miss_class;
|
61
61
|
bool cache_keys;
|
62
62
|
bool ignore_json_create;
|
63
|
-
} *
|
63
|
+
} *Usual;
|
64
64
|
|
65
65
|
// Initialize the parser with the usual delegate. If the usual delegate is
|
66
66
|
// wrapped then this function is called first and then the parser functions
|
data/ext/oj/util.h
CHANGED
data/ext/oj/val_stack.h
CHANGED
@@ -29,10 +29,10 @@ typedef enum {
|
|
29
29
|
|
30
30
|
typedef struct _val {
|
31
31
|
volatile VALUE val;
|
32
|
-
const char
|
32
|
+
const char *key;
|
33
33
|
char karray[32];
|
34
34
|
volatile VALUE key_val;
|
35
|
-
const char
|
35
|
+
const char *classname;
|
36
36
|
VALUE clas;
|
37
37
|
OddArgs odd_args;
|
38
38
|
uint16_t klen;
|
@@ -40,7 +40,7 @@ typedef struct _val {
|
|
40
40
|
char next; // ValNext
|
41
41
|
char k1; // first original character in the key
|
42
42
|
char kalloc;
|
43
|
-
} *
|
43
|
+
} *Val;
|
44
44
|
|
45
45
|
typedef struct _valStack {
|
46
46
|
struct _val base[STACK_INC];
|
@@ -53,7 +53,7 @@ typedef struct _valStack {
|
|
53
53
|
VALUE mutex;
|
54
54
|
#endif
|
55
55
|
|
56
|
-
} *
|
56
|
+
} *ValStack;
|
57
57
|
|
58
58
|
extern VALUE oj_stack_init(ValStack stack);
|
59
59
|
|
data/ext/oj/wab.c
CHANGED
@@ -76,15 +76,13 @@ static VALUE resolve_uri_http_class(void) {
|
|
76
76
|
}
|
77
77
|
|
78
78
|
static void raise_wab(VALUE obj) {
|
79
|
-
rb_raise(rb_eTypeError,
|
80
|
-
"Failed to dump %s Object to JSON in wab mode.\n",
|
81
|
-
rb_class2name(rb_obj_class(obj)));
|
79
|
+
rb_raise(rb_eTypeError, "Failed to dump %s Object to JSON in wab mode.\n", rb_class2name(rb_obj_class(obj)));
|
82
80
|
}
|
83
81
|
|
84
82
|
// Removed dependencies on math due to problems with CentOS 5.4.
|
85
83
|
static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
86
84
|
char buf[64];
|
87
|
-
char
|
85
|
+
char *b;
|
88
86
|
double d = rb_num2dbl(obj);
|
89
87
|
int cnt = 0;
|
90
88
|
|
@@ -299,7 +297,7 @@ static VALUE calc_hash_key(ParseInfo pi, Val parent) {
|
|
299
297
|
#if HAVE_RB_ENC_INTERNED_STR
|
300
298
|
rkey = rb_enc_interned_str(parent->key, parent->klen, oj_utf8_encoding);
|
301
299
|
#else
|
302
|
-
|
300
|
+
rkey = rb_utf8_str_new(parent->key, parent->klen);
|
303
301
|
rkey = rb_str_intern(rkey);
|
304
302
|
OBJ_FREEZE(rkey);
|
305
303
|
#endif
|
@@ -446,14 +444,14 @@ static VALUE protect_uri(VALUE rstr) {
|
|
446
444
|
static VALUE cstr_to_rstr(ParseInfo pi, const char *str, size_t len) {
|
447
445
|
volatile VALUE v = Qnil;
|
448
446
|
|
449
|
-
if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] &&
|
450
|
-
'
|
447
|
+
if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] && ':' == str[16] &&
|
448
|
+
'.' == str[19] && 'Z' == str[29]) {
|
451
449
|
if (Qnil != (v = time_parse(str, (int)len))) {
|
452
450
|
return v;
|
453
451
|
}
|
454
452
|
}
|
455
|
-
if (36 == len && '-' == str[8] && '-' == str[13] && '-' == str[18] && '-' == str[23] &&
|
456
|
-
|
453
|
+
if (36 == len && '-' == str[8] && '-' == str[13] && '-' == str[18] && '-' == str[23] && uuid_check(str, (int)len) &&
|
454
|
+
Qnil != resolve_wab_uuid_class()) {
|
457
455
|
return rb_funcall(wab_uuid_clas, oj_new_id, 1, rb_str_new(str, len));
|
458
456
|
}
|
459
457
|
if (7 < len && 0 == strncasecmp("http://", str, 7)) {
|
data/lib/oj/bag.rb
CHANGED
@@ -15,7 +15,7 @@ module Oj
|
|
15
15
|
# @example Oj::Bag.new(:@x => 42, :@y => 57)
|
16
16
|
# @param [Hash] args instance variable symbols and their values
|
17
17
|
def initialize(args = {})
|
18
|
-
args.each do |k,v|
|
18
|
+
args.each do |k, v|
|
19
19
|
self.instance_variable_set(k, v)
|
20
20
|
end
|
21
21
|
end
|
@@ -26,6 +26,7 @@ module Oj
|
|
26
26
|
# variable reader, otherwise false.
|
27
27
|
def respond_to?(m)
|
28
28
|
return true if super
|
29
|
+
|
29
30
|
instance_variables.include?(:"@#{m}")
|
30
31
|
end
|
31
32
|
|
@@ -37,8 +38,10 @@ module Oj
|
|
37
38
|
# @raise [NoMethodError] if the instance variable is not defined.
|
38
39
|
def method_missing(m, *args, &block)
|
39
40
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0) to method #{m}") unless args.nil? or args.empty?
|
41
|
+
|
40
42
|
at_m = :"@#{m}"
|
41
43
|
raise NoMethodError.new("undefined method #{m}", m) unless instance_variable_defined?(at_m)
|
44
|
+
|
42
45
|
instance_variable_get(at_m)
|
43
46
|
end
|
44
47
|
|
@@ -47,9 +50,11 @@ module Oj
|
|
47
50
|
# @return [Boolean] true if each variable and value are the same, otherwise false.
|
48
51
|
def eql?(other)
|
49
52
|
return false if (other.nil? or self.class != other.class)
|
53
|
+
|
50
54
|
ova = other.instance_variables
|
51
55
|
iv = instance_variables
|
52
56
|
return false if ova.size != iv.size
|
57
|
+
|
53
58
|
iv.all? { |vid| instance_variable_get(vid) != other.instance_variable_get(vid) }
|
54
59
|
end
|
55
60
|
alias == eql?
|
@@ -65,6 +70,7 @@ module Oj
|
|
65
70
|
classname = classname.to_s unless classname.is_a?(String)
|
66
71
|
tokens = classname.split('::').map(&:to_sym)
|
67
72
|
raise NameError.new("Invalid classname '#{classname}") if tokens.empty?
|
73
|
+
|
68
74
|
m = Object
|
69
75
|
tokens[0..-2].each do |sym|
|
70
76
|
if m.const_defined?(sym)
|
data/lib/oj/easy_hash.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Oj
|
3
2
|
|
4
3
|
# A Hash subclass that normalizes the hash keys to allow lookup by the
|
@@ -6,10 +5,6 @@ module Oj
|
|
6
5
|
# that match the keys.
|
7
6
|
class EasyHash < Hash
|
8
7
|
|
9
|
-
# Initializes the instance to an empty Hash.
|
10
|
-
def initialize()
|
11
|
-
end
|
12
|
-
|
13
8
|
# Replaces the Object.respond_to?() method.
|
14
9
|
# @param [Symbol] m method symbol
|
15
10
|
# @param [Boolean] include_all whether to include private and protected methods in the search
|
@@ -19,12 +14,14 @@ module Oj
|
|
19
14
|
return true if super
|
20
15
|
return true if has_key?(m)
|
21
16
|
return true if has_key?(m.to_s)
|
17
|
+
|
22
18
|
has_key?(m.to_sym)
|
23
19
|
end
|
24
20
|
|
25
21
|
def [](key)
|
26
22
|
return fetch(key, nil) if has_key?(key)
|
27
23
|
return fetch(key.to_s, nil) if has_key?(key.to_s)
|
24
|
+
|
28
25
|
fetch(key.to_sym, nil)
|
29
26
|
end
|
30
27
|
|
@@ -36,9 +33,11 @@ module Oj
|
|
36
33
|
def method_missing(m, *args, &block)
|
37
34
|
if m.to_s.end_with?('=')
|
38
35
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length
|
36
|
+
|
39
37
|
m = m[0..-2]
|
40
38
|
return store(m.to_s, args[0]) if has_key?(m.to_s)
|
41
39
|
return store(m.to_sym, args[0]) if has_key?(m.to_sym)
|
40
|
+
|
42
41
|
return store(m, args[0])
|
43
42
|
else
|
44
43
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
|
data/lib/oj/error.rb
CHANGED
data/lib/oj/json.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'ostruct'
|
3
2
|
require 'oj/state'
|
4
3
|
|
@@ -51,7 +50,7 @@ module JSON
|
|
51
50
|
|
52
51
|
def self.dump_default_options=(h)
|
53
52
|
m = Oj::MimicDumpOption.new
|
54
|
-
h.each do |k,v|
|
53
|
+
h.each do |k, v|
|
55
54
|
m[k] = v
|
56
55
|
end
|
57
56
|
end
|
@@ -76,16 +75,19 @@ module JSON
|
|
76
75
|
class Parser
|
77
76
|
def initialize(src)
|
78
77
|
raise TypeError.new("already initialized") unless @source.nil?
|
78
|
+
|
79
79
|
@source = src
|
80
80
|
end
|
81
81
|
|
82
82
|
def source()
|
83
83
|
raise TypeError.new("already initialized") if @source.nil?
|
84
|
+
|
84
85
|
@source
|
85
86
|
end
|
86
87
|
|
87
88
|
def parse()
|
88
89
|
raise TypeError.new("already initialized") if @source.nil?
|
90
|
+
|
89
91
|
JSON.parse(@source)
|
90
92
|
end
|
91
93
|
|
data/lib/oj/mimic.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'bigdecimal'
|
3
2
|
begin
|
4
3
|
require 'ostruct'
|
@@ -64,6 +63,8 @@ module Oj
|
|
64
63
|
self.store(:allow_nan, true)
|
65
64
|
self.store(:quirks_mode, oo[:quirks_mode])
|
66
65
|
self.store(:ascii_only, (:ascii == oo[:escape_mode]))
|
66
|
+
|
67
|
+
super
|
67
68
|
end
|
68
69
|
|
69
70
|
def []=(key, value)
|
@@ -102,6 +103,7 @@ module Oj
|
|
102
103
|
def as_json(*)
|
103
104
|
name = self.class.name.to_s
|
104
105
|
raise JSON::JSONError, "Only named structs are supported!" if 0 == name.length
|
106
|
+
|
105
107
|
{ JSON.create_id => name, 't' => table }
|
106
108
|
end
|
107
109
|
end
|
@@ -232,6 +234,7 @@ module Oj
|
|
232
234
|
def as_json(*)
|
233
235
|
name = self.class.name.to_s
|
234
236
|
raise JSON::JSONError, "Only named structs are supported!" if 0 == name.length
|
237
|
+
|
235
238
|
{ JSON.create_id => name, 'v' => values }
|
236
239
|
end
|
237
240
|
end
|
@@ -273,7 +276,6 @@ module Oj
|
|
273
276
|
end
|
274
277
|
end
|
275
278
|
end
|
276
|
-
|
277
279
|
end # self.mimic_loaded
|
278
280
|
|
279
281
|
end # Oj
|
data/lib/oj/state.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module JSON
|
3
2
|
module Ext
|
4
3
|
module Generator
|
@@ -59,6 +58,7 @@ module JSON
|
|
59
58
|
|
60
59
|
def configure(opts)
|
61
60
|
raise TypeError.new('expected a Hash') unless opts.respond_to?(:to_h)
|
61
|
+
|
62
62
|
@attrs.merge!(opts.to_h)
|
63
63
|
end
|
64
64
|
|
@@ -84,6 +84,7 @@ module JSON
|
|
84
84
|
return true if super
|
85
85
|
return true if has_key?(key)
|
86
86
|
return true if has_key?(key.to_s)
|
87
|
+
|
87
88
|
has_key?(key.to_sym)
|
88
89
|
end
|
89
90
|
|
@@ -113,15 +114,17 @@ module JSON
|
|
113
114
|
def method_missing(m, *args, &block)
|
114
115
|
if m.to_s.end_with?('=')
|
115
116
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length
|
117
|
+
|
116
118
|
m = m.to_s[0..-2]
|
117
119
|
m = m.to_sym
|
118
120
|
return @attrs.store(m, args[0])
|
119
|
-
|
120
|
-
|
121
|
+
end
|
122
|
+
if @attrs.has_key?(m.to_sym)
|
121
123
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
|
124
|
+
|
122
125
|
return @attrs[m.to_sym]
|
123
|
-
|
124
|
-
|
126
|
+
end
|
127
|
+
return @attrs.send(m, *args, &block)
|
125
128
|
end
|
126
129
|
|
127
130
|
end # State
|
data/lib/oj/version.rb
CHANGED
data/lib/oj.rb
CHANGED
data/test/_test_active.rb
CHANGED
@@ -71,6 +71,5 @@ class ActiveTest < Minitest::Test
|
|
71
71
|
|
72
72
|
# Array of instances as json. (not Oj)
|
73
73
|
assert_equal(%|[{"id":1,"first_name":"John","last_name":"Smith","email":"john@example.com"},{"id":2,"first_name":"Joan","last_name":"Smith","email":"joan@example.com"}]|, User.all.to_json)
|
74
|
-
|
75
74
|
end
|
76
75
|
end
|
data/test/_test_active_mimic.rb
CHANGED
data/test/_test_mimic_rails.rb
CHANGED