oj 3.13.1 → 3.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/oj/cache.c +17 -11
- data/ext/oj/custom.c +1 -1
- data/ext/oj/debug.c +2 -1
- data/ext/oj/fast.c +1 -1
- data/ext/oj/object.c +1 -1
- data/ext/oj/oj.c +3 -3
- data/ext/oj/parse.c +1 -1
- data/ext/oj/parser.c +6 -5
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/saj.c +1 -1
- data/ext/oj/saj2.c +4 -2
- data/ext/oj/sparse.c +1 -1
- data/ext/oj/stream_writer.c +1 -1
- data/ext/oj/string_writer.c +2 -2
- data/ext/oj/usual.c +18 -12
- data/ext/oj/validate.c +2 -1
- data/lib/oj/error.rb +1 -1
- data/lib/oj/version.rb +1 -1
- data/pages/Options.md +1 -1
- data/pages/Parser.md +3 -3
- data/pages/Rails.md +2 -2
- data/test/json_gem/json_generator_test.rb +1 -1
- data/test/test_hash.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6371eea98925c8d16b816b991404d643051c566f3d36e2c4cf2c69cd29ffd816
|
4
|
+
data.tar.gz: 9373b88d98493ddf677e5f72fd1a16f155f5a9c773f007452b1e5810c586e057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb0fb2e41354e3f96804aa2d74f546e87f2df9076b1e3ec3815b271b0cf4b84ac4dc3ed6d49f59a11cb845c3675de84b4ac8a3b27dc3f80fd310f196437a34b4
|
7
|
+
data.tar.gz: ca2efef1c0e3f1e3fb36c7bf0ba5fdffcc596680f2d28923efd8a8cd7cf472178a364a3a93370f5bbefb404e9d0b338754905ed9eb4183eaa9fe0061af41bc93
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ For more details on options, modes, advanced features, and more follow these
|
|
53
53
|
links.
|
54
54
|
|
55
55
|
- [{file:Options.md}](pages/Options.md) for parse and dump options.
|
56
|
-
- [{file:Modes.md}](pages/Modes.md) for details on modes for strict JSON compliance,
|
56
|
+
- [{file:Modes.md}](pages/Modes.md) for details on modes for strict JSON compliance, mimicking the JSON gem, and mimicking Rails and ActiveSupport behavior.
|
57
57
|
- [{file:JsonGem.md}](pages/JsonGem.md) includes more details on json gem compatibility and use.
|
58
58
|
- [{file:Rails.md}](pages/Rails.md) includes more details on Rails and ActiveSupport compatibility and use.
|
59
59
|
- [{file:Custom.md}](pages/Custom.md) includes more details on Custom mode.
|
data/ext/oj/cache.c
CHANGED
@@ -98,31 +98,30 @@ Cache cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool
|
|
98
98
|
memset(c->slots, 0, sizeof(Slot) * c->size);
|
99
99
|
c->form = form;
|
100
100
|
c->cnt = 0;
|
101
|
-
c->mark
|
101
|
+
c->mark = mark;
|
102
102
|
|
103
103
|
return c;
|
104
104
|
}
|
105
105
|
|
106
106
|
static void rehash(Cache c) {
|
107
107
|
uint32_t osize = c->size;
|
108
|
+
Slot * end = c->slots + osize;
|
109
|
+
Slot * sp;
|
108
110
|
|
109
111
|
c->size = osize * 4;
|
110
112
|
c->mask = c->size - 1;
|
111
113
|
REALLOC_N(c->slots, Slot, c->size);
|
112
114
|
memset(c->slots + osize, 0, sizeof(Slot) * osize * 3);
|
113
|
-
|
114
|
-
Slot *end = c->slots + osize;
|
115
|
-
for (Slot *sp = c->slots; sp < end; sp++) {
|
115
|
+
for (sp = c->slots; sp < end; sp++) {
|
116
116
|
Slot s = *sp;
|
117
117
|
Slot next = NULL;
|
118
118
|
|
119
119
|
*sp = NULL;
|
120
120
|
for (; NULL != s; s = next) {
|
121
|
-
next = s->next;
|
122
|
-
|
123
121
|
uint32_t h = s->hash & c->mask;
|
124
122
|
Slot * bucket = c->slots + h;
|
125
123
|
|
124
|
+
next = s->next;
|
126
125
|
s->next = *bucket;
|
127
126
|
*bucket = s;
|
128
127
|
}
|
@@ -130,9 +129,13 @@ static void rehash(Cache c) {
|
|
130
129
|
}
|
131
130
|
|
132
131
|
void cache_free(Cache c) {
|
133
|
-
|
132
|
+
uint32_t i;
|
133
|
+
|
134
|
+
for (i = 0; i < c->size; i++) {
|
134
135
|
Slot next;
|
135
|
-
|
136
|
+
Slot s;
|
137
|
+
|
138
|
+
for (s = c->slots[i]; NULL != s; s = next) {
|
136
139
|
next = s->next;
|
137
140
|
xfree(s);
|
138
141
|
}
|
@@ -143,9 +146,12 @@ void cache_free(Cache c) {
|
|
143
146
|
|
144
147
|
void cache_mark(Cache c) {
|
145
148
|
if (c->mark) {
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
+
uint32_t i;
|
150
|
+
|
151
|
+
for (i = 0; i < c->size; i++) {
|
152
|
+
Slot s;
|
153
|
+
for (s = c->slots[i]; NULL != s; s = s->next) {
|
154
|
+
rb_gc_mark(s->val);
|
149
155
|
}
|
150
156
|
}
|
151
157
|
}
|
data/ext/oj/custom.c
CHANGED
@@ -1032,7 +1032,7 @@ static void hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
|
1032
1032
|
}
|
1033
1033
|
if (86400 == ni->exp) { // UTC time
|
1034
1034
|
parent->val = rb_time_nano_new(ni->i, (long)nsec);
|
1035
|
-
// Since the ruby C routines
|
1035
|
+
// Since the ruby C routines always create local time, the
|
1036
1036
|
// offset and then a conversion to UTC keeps makes the time
|
1037
1037
|
// match the expected value.
|
1038
1038
|
parent->val = rb_funcall2(parent->val, oj_utc_id, 0, 0);
|
data/ext/oj/debug.c
CHANGED
@@ -109,8 +109,9 @@ static void mark(struct _ojParser *p) {
|
|
109
109
|
|
110
110
|
void oj_set_parser_debug(ojParser p) {
|
111
111
|
Funcs end = p->funcs + 3;
|
112
|
+
Funcs f;
|
112
113
|
|
113
|
-
for (
|
114
|
+
for (f = p->funcs; f < end; f++) {
|
114
115
|
f->add_null = add_null;
|
115
116
|
f->add_true = add_true;
|
116
117
|
f->add_false = add_false;
|
data/ext/oj/fast.c
CHANGED
@@ -1472,7 +1472,7 @@ static VALUE doc_move(VALUE self, VALUE str) {
|
|
1472
1472
|
* to the block on yield is the Doc instance after moving to the child
|
1473
1473
|
* location.
|
1474
1474
|
* @param [String] path if provided it identified the top of the branch to
|
1475
|
-
* process the
|
1475
|
+
* process the children of
|
1476
1476
|
* @yieldparam [Doc] Doc at the child location
|
1477
1477
|
* @example
|
1478
1478
|
* Oj::Doc.open('[3,[2,1]]') { |doc|
|
data/ext/oj/object.c
CHANGED
@@ -301,7 +301,7 @@ static int hat_num(ParseInfo pi, Val parent, Val kval, NumInfo ni) {
|
|
301
301
|
}
|
302
302
|
if (86400 == ni->exp) { // UTC time
|
303
303
|
parent->val = rb_time_nano_new(ni->i, (long)nsec);
|
304
|
-
// Since the ruby C routines
|
304
|
+
// Since the ruby C routines always create local time, the
|
305
305
|
// offset and then a conversion to UTC keeps makes the time
|
306
306
|
// match the expected value.
|
307
307
|
parent->val = rb_funcall2(parent->val, oj_utc_id, 0, 0);
|
data/ext/oj/oj.c
CHANGED
@@ -509,7 +509,7 @@ static VALUE get_def_opts(VALUE self) {
|
|
509
509
|
* Sets the default options for load and dump.
|
510
510
|
* - *opts* [_Hash_] options to change
|
511
511
|
* - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in a JSON
|
512
|
-
*document or the String to use for
|
512
|
+
*document or the String to use for indentation.
|
513
513
|
* - :circular [_Boolean_|_nil_] support circular references while dumping.
|
514
514
|
* - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist.
|
515
515
|
* - *:symbol_keys* [_Boolean_|_nil_] convert hash keys to symbols.
|
@@ -1398,7 +1398,7 @@ static VALUE to_json(int argc, VALUE *argv, VALUE self) {
|
|
1398
1398
|
* Dumps an Object to the specified file.
|
1399
1399
|
* - *file* [_String_] _path file path to write the JSON document to
|
1400
1400
|
* - *obj* [_Object_] Object to serialize as an JSON document String
|
1401
|
-
* - *options* [_Hash_]
|
1401
|
+
* - *options* [_Hash_] formatting options
|
1402
1402
|
* - *:indent* [_Fixnum_] format expected
|
1403
1403
|
* - *:circular* [_Boolean_] allow circular references, default: false
|
1404
1404
|
*/
|
@@ -1420,7 +1420,7 @@ static VALUE to_file(int argc, VALUE *argv, VALUE self) {
|
|
1420
1420
|
* Dumps an Object to the specified IO stream.
|
1421
1421
|
* - *io* [_IO_] IO stream to write the JSON document to
|
1422
1422
|
* - *obj* [_Object_] Object to serialize as an JSON document String
|
1423
|
-
* - *options* [_Hash_]
|
1423
|
+
* - *options* [_Hash_] formatting options
|
1424
1424
|
* - *:indent* [_Fixnum_] format expected
|
1425
1425
|
* - *:circular* [_Boolean_] allow circular references, default: false
|
1426
1426
|
*/
|
data/ext/oj/parse.c
CHANGED
@@ -489,7 +489,7 @@ static void read_num(ParseInfo pi) {
|
|
489
489
|
if ('.' == *pi->cur) {
|
490
490
|
pi->cur++;
|
491
491
|
// A trailing . is not a valid decimal but if encountered allow it
|
492
|
-
// except when
|
492
|
+
// except when mimicking the JSON gem or in strict mode.
|
493
493
|
if (StrictMode == pi->options.mode || CompatMode == pi->options.mode) {
|
494
494
|
int pos = (int)(pi->cur - ni.str);
|
495
495
|
|
data/ext/oj/parser.c
CHANGED
@@ -622,14 +622,14 @@ static void big_change(ojParser p) {
|
|
622
622
|
buf_append_string(&p->buf, buf + len + 1, sizeof(buf) - len - 1);
|
623
623
|
if (0 < p->num.exp) {
|
624
624
|
int x = p->num.exp;
|
625
|
-
int d;
|
625
|
+
int d, div;
|
626
626
|
bool started = false;
|
627
627
|
|
628
628
|
buf_append(&p->buf, 'e');
|
629
629
|
if (0 < p->num.exp_neg) {
|
630
630
|
buf_append(&p->buf, '-');
|
631
631
|
}
|
632
|
-
for (
|
632
|
+
for (div = 1000; 0 < div; div /= 10) {
|
633
633
|
d = x / div % 10;
|
634
634
|
if (started || 0 < d) {
|
635
635
|
buf_append(&p->buf, '0' + d);
|
@@ -646,6 +646,7 @@ static void big_change(ojParser p) {
|
|
646
646
|
static void parse(ojParser p, const byte *json) {
|
647
647
|
const byte *start;
|
648
648
|
const byte *b = json;
|
649
|
+
int i;
|
649
650
|
|
650
651
|
#if DEBUG
|
651
652
|
printf("*** parse - mode: %c %s\n", p->map[256], (const char *)json);
|
@@ -1015,7 +1016,7 @@ static void parse(ojParser p, const byte *json) {
|
|
1015
1016
|
}
|
1016
1017
|
p->ri = 0;
|
1017
1018
|
*p->token = *b++;
|
1018
|
-
for (
|
1019
|
+
for (i = 1; i < 4; i++) {
|
1019
1020
|
if ('\0' == *b) {
|
1020
1021
|
p->ri = i;
|
1021
1022
|
break;
|
@@ -1040,7 +1041,7 @@ static void parse(ojParser p, const byte *json) {
|
|
1040
1041
|
}
|
1041
1042
|
p->ri = 0;
|
1042
1043
|
*p->token = *b++;
|
1043
|
-
for (
|
1044
|
+
for (i = 1; i < 4; i++) {
|
1044
1045
|
if ('\0' == *b) {
|
1045
1046
|
p->ri = i;
|
1046
1047
|
break;
|
@@ -1065,7 +1066,7 @@ static void parse(ojParser p, const byte *json) {
|
|
1065
1066
|
}
|
1066
1067
|
p->ri = 0;
|
1067
1068
|
*p->token = *b++;
|
1068
|
-
for (
|
1069
|
+
for (i = 1; i < 5; i++) {
|
1069
1070
|
if ('\0' == *b) {
|
1070
1071
|
p->ri = i;
|
1071
1072
|
break;
|
data/ext/oj/rxclass.c
CHANGED
@@ -110,7 +110,7 @@ oj_rxclass_match(RxClass rc, const char *str, int len) {
|
|
110
110
|
}
|
111
111
|
} else if (len < (int)sizeof(buf)) {
|
112
112
|
#if !IS_WINDOWS
|
113
|
-
// string is not \0 terminated so copy and
|
113
|
+
// string is not \0 terminated so copy and attempt a match
|
114
114
|
memcpy(buf, str, len);
|
115
115
|
buf[len] = '\0';
|
116
116
|
if (0 == regexec(&rxc->rx, buf, 0, NULL, 0)) { // match
|
data/ext/oj/saj.c
CHANGED
@@ -628,7 +628,7 @@ static void saj_parse(VALUE handler, char *json) {
|
|
628
628
|
* @param [IO|String] io IO Object to read from
|
629
629
|
* @deprecated The sc_parse() method along with the ScHandler is the preferred
|
630
630
|
* callback parser. It is slightly faster and handles streams while the
|
631
|
-
* saj_parse()
|
631
|
+
* saj_parse() method requires a complete read before parsing.
|
632
632
|
* @see sc_parse
|
633
633
|
*/
|
634
634
|
VALUE
|
data/ext/oj/saj2.c
CHANGED
@@ -182,8 +182,9 @@ static void add_str_key(ojParser p) {
|
|
182
182
|
|
183
183
|
static void reset(ojParser p) {
|
184
184
|
Funcs end = p->funcs + 3;
|
185
|
+
Funcs f;
|
185
186
|
|
186
|
-
for (
|
187
|
+
for (f = p->funcs; f < end; f++) {
|
187
188
|
f->add_null = noop;
|
188
189
|
f->add_true = noop;
|
189
190
|
f->add_false = noop;
|
@@ -312,13 +313,14 @@ static void mark(ojParser p) {
|
|
312
313
|
return;
|
313
314
|
}
|
314
315
|
Delegate d = (Delegate)p->ctx;
|
316
|
+
VALUE *kp;
|
315
317
|
|
316
318
|
cache_mark(d->str_cache);
|
317
319
|
if (Qnil != d->handler) {
|
318
320
|
rb_gc_mark(d->handler);
|
319
321
|
}
|
320
322
|
if (!d->cache_keys) {
|
321
|
-
for (
|
323
|
+
for (kp = d->keys; kp < d->tail; kp++) {
|
322
324
|
rb_gc_mark(*kp);
|
323
325
|
}
|
324
326
|
}
|
data/ext/oj/sparse.c
CHANGED
@@ -494,7 +494,7 @@ static void read_num(ParseInfo pi) {
|
|
494
494
|
if ('.' == c) {
|
495
495
|
c = reader_get(&pi->rd);
|
496
496
|
// A trailing . is not a valid decimal but if encountered allow it
|
497
|
-
// except when
|
497
|
+
// except when mimicking the JSON gem.
|
498
498
|
if (CompatMode == pi->options.mode) {
|
499
499
|
if (c < '0' || '9' < c) {
|
500
500
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number");
|
data/ext/oj/stream_writer.c
CHANGED
@@ -67,7 +67,7 @@ static VALUE buffer_size_sym = Qundef;
|
|
67
67
|
* should be and also a hint on when to flush.
|
68
68
|
*
|
69
69
|
* - *io* [_IO_] stream to write to
|
70
|
-
* - *options* [_Hash_]
|
70
|
+
* - *options* [_Hash_] formatting options
|
71
71
|
*/
|
72
72
|
static VALUE stream_writer_new(int argc, VALUE *argv, VALUE self) {
|
73
73
|
StreamWriterType type = STREAM_IO;
|
data/ext/oj/string_writer.c
CHANGED
@@ -248,7 +248,7 @@ static void str_writer_free(void *ptr) {
|
|
248
248
|
* should be.
|
249
249
|
*
|
250
250
|
* - *io* [_IO_] stream to write to
|
251
|
-
* - *options* [_Hash_]
|
251
|
+
* - *options* [_Hash_] formatting options
|
252
252
|
*/
|
253
253
|
static VALUE str_writer_new(int argc, VALUE *argv, VALUE self) {
|
254
254
|
StrWriter sw = ALLOC(struct _strWriter);
|
@@ -466,7 +466,7 @@ static VALUE str_writer_as_json(VALUE self) {
|
|
466
466
|
* by pushing values into the document. Pushing an array or an object will
|
467
467
|
* create that element in the JSON document and subsequent pushes will add the
|
468
468
|
* elements to that array or object until a pop() is called. When complete
|
469
|
-
* calling to_s() will return the JSON document. Note
|
469
|
+
* calling to_s() will return the JSON document. Note that calling to_s() before
|
470
470
|
* construction is complete will return the document in it's current state.
|
471
471
|
*/
|
472
472
|
void oj_string_writer_init() {
|
data/ext/oj/usual.c
CHANGED
@@ -323,6 +323,7 @@ static void open_array_key(ojParser p) {
|
|
323
323
|
}
|
324
324
|
|
325
325
|
static void close_object(ojParser p) {
|
326
|
+
VALUE *vp;
|
326
327
|
Delegate d = (Delegate)p->ctx;
|
327
328
|
|
328
329
|
d->ctail--;
|
@@ -333,7 +334,7 @@ static void close_object(ojParser p) {
|
|
333
334
|
volatile VALUE obj = rb_hash_new();
|
334
335
|
|
335
336
|
#if HAVE_RB_HASH_BULK_INSERT
|
336
|
-
for (
|
337
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
337
338
|
*vp = d->get_key(p, kp);
|
338
339
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
339
340
|
xfree(kp->key);
|
@@ -341,7 +342,7 @@ static void close_object(ojParser p) {
|
|
341
342
|
}
|
342
343
|
rb_hash_bulk_insert(d->vtail - head, head, obj);
|
343
344
|
#else
|
344
|
-
for (
|
345
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
345
346
|
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
|
346
347
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
347
348
|
xfree(kp->key);
|
@@ -355,6 +356,7 @@ static void close_object(ojParser p) {
|
|
355
356
|
}
|
356
357
|
|
357
358
|
static void close_object_class(ojParser p) {
|
359
|
+
VALUE *vp;
|
358
360
|
Delegate d = (Delegate)p->ctx;
|
359
361
|
|
360
362
|
d->ctail--;
|
@@ -364,7 +366,7 @@ static void close_object_class(ojParser p) {
|
|
364
366
|
VALUE * head = d->vhead + c->vi + 1;
|
365
367
|
volatile VALUE obj = rb_class_new_instance(0, NULL, d->hash_class);
|
366
368
|
|
367
|
-
for (
|
369
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
368
370
|
rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
|
369
371
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
370
372
|
xfree(kp->key);
|
@@ -377,6 +379,7 @@ static void close_object_class(ojParser p) {
|
|
377
379
|
}
|
378
380
|
|
379
381
|
static void close_object_create(ojParser p) {
|
382
|
+
VALUE *vp;
|
380
383
|
Delegate d = (Delegate)p->ctx;
|
381
384
|
|
382
385
|
d->ctail--;
|
@@ -391,7 +394,7 @@ static void close_object_create(ojParser p) {
|
|
391
394
|
if (Qnil == d->hash_class) {
|
392
395
|
obj = rb_hash_new();
|
393
396
|
#if HAVE_RB_HASH_BULK_INSERT
|
394
|
-
for (
|
397
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
395
398
|
*vp = d->get_key(p, kp);
|
396
399
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
397
400
|
xfree(kp->key);
|
@@ -399,7 +402,7 @@ static void close_object_create(ojParser p) {
|
|
399
402
|
}
|
400
403
|
rb_hash_bulk_insert(d->vtail - head, head, obj);
|
401
404
|
#else
|
402
|
-
for (
|
405
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
403
406
|
rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
|
404
407
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
405
408
|
xfree(kp->key);
|
@@ -408,7 +411,7 @@ static void close_object_create(ojParser p) {
|
|
408
411
|
#endif
|
409
412
|
} else {
|
410
413
|
obj = rb_class_new_instance(0, NULL, d->hash_class);
|
411
|
-
for (
|
414
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
412
415
|
rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
|
413
416
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
414
417
|
xfree(kp->key);
|
@@ -423,7 +426,7 @@ static void close_object_create(ojParser p) {
|
|
423
426
|
volatile VALUE arg = rb_hash_new();
|
424
427
|
|
425
428
|
#if HAVE_RB_HASH_BULK_INSERT
|
426
|
-
for (
|
429
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
427
430
|
*vp = d->get_key(p, kp);
|
428
431
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
429
432
|
xfree(kp->key);
|
@@ -431,7 +434,7 @@ static void close_object_create(ojParser p) {
|
|
431
434
|
}
|
432
435
|
rb_hash_bulk_insert(d->vtail - head, head, arg);
|
433
436
|
#else
|
434
|
-
for (
|
437
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
435
438
|
rb_hash_aset(arg, d->get_key(p, kp), *(vp + 1));
|
436
439
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
437
440
|
xfree(kp->key);
|
@@ -441,7 +444,7 @@ static void close_object_create(ojParser p) {
|
|
441
444
|
obj = rb_funcall(clas, oj_json_create_id, 1, arg);
|
442
445
|
} else {
|
443
446
|
obj = rb_class_new_instance(0, NULL, clas);
|
444
|
-
for (
|
447
|
+
for (vp = head; kp < d->ktail; kp++, vp += 2) {
|
445
448
|
rb_ivar_set(obj, get_attr_id(p, kp), *(vp + 1));
|
446
449
|
if (sizeof(kp->buf) - 1 < (size_t)kp->len) {
|
447
450
|
xfree(kp->key);
|
@@ -468,13 +471,14 @@ static void close_array(ojParser p) {
|
|
468
471
|
}
|
469
472
|
|
470
473
|
static void close_array_class(ojParser p) {
|
474
|
+
VALUE *vp;
|
471
475
|
Delegate d = (Delegate)p->ctx;
|
472
476
|
|
473
477
|
d->ctail--;
|
474
478
|
VALUE * head = d->vhead + d->ctail->vi + 1;
|
475
479
|
volatile VALUE a = rb_class_new_instance(0, NULL, d->array_class);
|
476
480
|
|
477
|
-
for (
|
481
|
+
for (vp = head; vp < d->vtail; vp++) {
|
478
482
|
rb_funcall(a, ltlt_id, 1, *vp);
|
479
483
|
}
|
480
484
|
d->vtail = head;
|
@@ -682,6 +686,7 @@ static void mark(ojParser p) {
|
|
682
686
|
return;
|
683
687
|
}
|
684
688
|
Delegate d = (Delegate)p->ctx;
|
689
|
+
VALUE *vp;
|
685
690
|
|
686
691
|
if (NULL == d) {
|
687
692
|
return;
|
@@ -693,7 +698,7 @@ static void mark(ojParser p) {
|
|
693
698
|
if (NULL != d->class_cache) {
|
694
699
|
cache_mark(d->class_cache);
|
695
700
|
}
|
696
|
-
for (
|
701
|
+
for (vp = d->vhead; vp < d->vtail; vp++) {
|
697
702
|
if (Qundef != *vp) {
|
698
703
|
rb_gc_mark(*vp);
|
699
704
|
}
|
@@ -1091,6 +1096,7 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
|
|
1091
1096
|
}
|
1092
1097
|
|
1093
1098
|
static VALUE option(ojParser p, const char *key, VALUE value) {
|
1099
|
+
struct opt *op;
|
1094
1100
|
struct opt opts[] = {
|
1095
1101
|
{.name = "array_class", .func = opt_array_class},
|
1096
1102
|
{.name = "array_class=", .func = opt_array_class_set},
|
@@ -1119,7 +1125,7 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
|
|
1119
1125
|
{.name = NULL},
|
1120
1126
|
};
|
1121
1127
|
|
1122
|
-
for (
|
1128
|
+
for (op = opts; NULL != op->name; op++) {
|
1123
1129
|
if (0 == strcmp(key, op->name)) {
|
1124
1130
|
return op->func(p, value);
|
1125
1131
|
}
|
data/ext/oj/validate.c
CHANGED
@@ -28,8 +28,9 @@ mark(ojParser p) {
|
|
28
28
|
void oj_set_parser_validator(ojParser p) {
|
29
29
|
p->ctx = NULL;
|
30
30
|
Funcs end = p->funcs + 3;
|
31
|
+
Funcs f;
|
31
32
|
|
32
|
-
for (
|
33
|
+
for (f = p->funcs; f < end; f++) {
|
33
34
|
f->add_null = noop;
|
34
35
|
f->add_true = noop;
|
35
36
|
f->add_false = noop;
|
data/lib/oj/error.rb
CHANGED
@@ -16,7 +16,7 @@ module Oj
|
|
16
16
|
# An Exception that is raised if a file fails to load.
|
17
17
|
LoadError = Class.new(Error)
|
18
18
|
|
19
|
-
# An Exception that is raised if there is a conflict with
|
19
|
+
# An Exception that is raised if there is a conflict with mimicking JSON
|
20
20
|
MimicError = Class.new(Error)
|
21
21
|
|
22
22
|
end # Oj
|
data/lib/oj/version.rb
CHANGED
data/pages/Options.md
CHANGED
@@ -268,7 +268,7 @@ Use symbols instead of strings for hash keys.
|
|
268
268
|
### :symbolize_names [Boolean]
|
269
269
|
|
270
270
|
Like :symbol_keys has keys are made into symbols but only when
|
271
|
-
|
271
|
+
mimicking the JSON gem and then only as the JSON gem honors it so
|
272
272
|
JSON.parse honors the option but JSON.load does not.
|
273
273
|
|
274
274
|
### :trace
|
data/pages/Parser.md
CHANGED
@@ -42,12 +42,12 @@ bleed over to other instances.
|
|
42
42
|
|
43
43
|
## How
|
44
44
|
|
45
|
-
It's
|
45
|
+
It's wonderful to wish for a faster parser that solves all the
|
46
46
|
annoyances of the previous parser but how was it done is a much more
|
47
47
|
interesting question to answer.
|
48
48
|
|
49
49
|
At the core, the API for parsing was changed. Instead of a sinle
|
50
|
-
global parser any number of parsers can be created and each is
|
50
|
+
global parser any number of parsers can be created and each is separate
|
51
51
|
from the others. The parser itself is able to rip through a JSON
|
52
52
|
string, stream, or file and then make calls to a delegate to process
|
53
53
|
the JSON elements according to the delegate behavior. This is similar
|
@@ -206,7 +206,7 @@ in array creation.
|
|
206
206
|
|
207
207
|
For Hash the story is a little different. The bulk insert for Hash
|
208
208
|
alternates keys and values but there is a wrinkle to consider. Since
|
209
|
-
Ruby Object creation is triggered by the
|
209
|
+
Ruby Object creation is triggered by the occurrence of an element that
|
210
210
|
matches a creation identifier the creation of a collection is not just
|
211
211
|
for Array and Hash but also Object. Setting Object attributes uses an
|
212
212
|
ID and not a VALUE. For that reason the keys should not be created as
|
data/pages/Rails.md
CHANGED
@@ -41,7 +41,7 @@ The globals that ActiveSupport uses for encoding are:
|
|
41
41
|
|
42
42
|
Those globals are aliased to also be accessed from the ActiveSupport module
|
43
43
|
directly so `ActiveSupport::JSON::Encoding.time_precision` can also be accessed
|
44
|
-
from `ActiveSupport.time_precision`. Oj makes use of these globals in
|
44
|
+
from `ActiveSupport.time_precision`. Oj makes use of these globals in mimicking
|
45
45
|
Rails after the `Oj::Rails.set_encode()` method is called. That also sets the
|
46
46
|
`ActiveSupport.json_encoder` to the `Oj::Rails::Encoder` class.
|
47
47
|
|
@@ -125,7 +125,7 @@ gem 'oj', '3.7.12'
|
|
125
125
|
Ruby which is used by the json gem and by Rails. Ruby varies the
|
126
126
|
significant digits which can be either 16 or 17 depending on the value.
|
127
127
|
|
128
|
-
2. Optimized
|
128
|
+
2. Optimized Hashes do not collapse keys that become the same in the output. As
|
129
129
|
an example, a non-String object that has a `to_s()` method will become the
|
130
130
|
return value of the `to_s()` method in the output without checking to see if
|
131
131
|
that has already been used. This could occur is a mix of String and Symbols
|
@@ -113,7 +113,7 @@ EOT
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# TBD Implement JSON.state to return state class.
|
116
|
-
# set state
|
116
|
+
# set state attributes from defaults
|
117
117
|
# implement methods
|
118
118
|
# circular should use circular in defaults or maybe always set to true, allow changes with [:check_circular]=
|
119
119
|
def test_states
|
data/test/test_hash.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.13.
|
4
|
+
version: 3.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|