oj 3.14.2 → 3.15.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 +4 -4
- data/CHANGELOG.md +9 -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 +6 -16
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +43 -18
- 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 +39 -24
- data/ext/oj/object.c +12 -26
- data/ext/oj/odd.c +2 -1
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +80 -81
- data/ext/oj/oj.h +56 -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 +16 -40
- 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 +16 -36
- 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 +2 -0
- data/pages/Options.md +4 -0
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/files.rb +15 -15
- data/test/foo.rb +9 -52
- data/test/helper.rb +5 -8
- 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 +13 -12
- data/test/perf.rb +21 -26
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +25 -25
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +12 -11
- data/test/perf_parser.rb +41 -48
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +57 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +68 -70
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +3 -3
- 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 +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +52 -52
- data/test/test_custom.rb +61 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +86 -90
- data/test/test_file.rb +24 -29
- data/test/test_gc.rb +5 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +4 -4
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +78 -87
- data/test/test_parser.rb +4 -4
- data/test/test_parser_debug.rb +4 -4
- data/test/test_parser_saj.rb +27 -25
- data/test/test_parser_usual.rb +6 -6
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +35 -35
- data/test/test_strict.rb +28 -32
- data/test/test_various.rb +140 -97
- data/test/test_wab.rb +46 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +7 -7
- data/test/tests_mimic.rb +6 -6
- data/test/tests_mimic_addition.rb +6 -6
- metadata +18 -30
- 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/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/zoo.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 929e5766d8a556ed9590574901fe8268979fd6c165d10e1a2a8601a594dd6897
|
4
|
+
data.tar.gz: 966fedee6a16f73c004b56050474377ae48521f5858da962f0f0416b5636a4c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f458f616c33c48d84cb0e1d2c1c45e8b677609c19251345328721fe3b7b6c4c5aa1fd4906da2234b60889a6e3bb45ee0371e7de7565bb6d1aa7d924e231e36dd
|
7
|
+
data.tar.gz: fbbf233fc1ce57739d2fe538c179a24282e4c043740c2b47cce29745e3847712afa7828d321b877a3c29ab7d2216e7185af9a85bb9c8eb96b6036f9e3e49c1d1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.15.0 - 2023-06-02
|
4
|
+
|
5
|
+
- Added `omit_null_byte` option when dumping.
|
6
|
+
|
7
|
+
## 3.14.3 - 2023-04-07
|
8
|
+
|
9
|
+
- Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
|
10
|
+
|
3
11
|
## 3.14.2 - 2023-02-10
|
4
12
|
|
5
13
|
- Fixed check for \0 in strings.
|
@@ -14,7 +22,7 @@
|
|
14
22
|
|
15
23
|
- Tracing is now a compile time option giving a 15 to 20% performance boost.
|
16
24
|
|
17
|
-
- Some cleanup in
|
25
|
+
- Some cleanup in the fast parser.
|
18
26
|
|
19
27
|
## 3.13.23 - 2022-11-06
|
20
28
|
|
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
[](https://github.com/ohler55/oj/actions/workflows/CI.yml)
|
4
4
|

|
5
5
|

|
6
|
-
[](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver)
|
7
6
|
[](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme)
|
8
7
|
|
9
8
|
A *fast* JSON parser and Object marshaller as a Ruby gem.
|
data/ext/oj/buf.h
CHANGED
@@ -4,15 +4,15 @@
|
|
4
4
|
#ifndef OJ_BUF_H
|
5
5
|
#define OJ_BUF_H
|
6
6
|
|
7
|
-
#include "ruby.h"
|
8
7
|
#include "mem.h"
|
8
|
+
#include "ruby.h"
|
9
9
|
|
10
10
|
typedef struct _buf {
|
11
11
|
char *head;
|
12
12
|
char *end;
|
13
13
|
char *tail;
|
14
14
|
char base[1024];
|
15
|
-
} *
|
15
|
+
} *Buf;
|
16
16
|
|
17
17
|
inline static void buf_init(Buf buf) {
|
18
18
|
buf->head = buf->base;
|
data/ext/oj/cache.c
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
#endif
|
7
7
|
#include <stdlib.h>
|
8
8
|
|
9
|
-
#include "mem.h"
|
10
9
|
#include "cache.h"
|
10
|
+
#include "mem.h"
|
11
11
|
|
12
12
|
// The stdlib calloc, realloc, and free are used instead of the Ruby ALLOC,
|
13
13
|
// ALLOC_N, REALLOC, and xfree since the later could trigger a GC which will
|
@@ -29,16 +29,16 @@
|
|
29
29
|
#define M 0x5bd1e995
|
30
30
|
|
31
31
|
typedef struct _slot {
|
32
|
-
struct _slot
|
32
|
+
struct _slot *next;
|
33
33
|
VALUE val;
|
34
34
|
uint64_t hash;
|
35
35
|
volatile uint32_t use_cnt;
|
36
36
|
uint8_t klen;
|
37
37
|
char key[CACHE_MAX_KEY];
|
38
|
-
} *
|
38
|
+
} *Slot;
|
39
39
|
|
40
40
|
typedef struct _cache {
|
41
|
-
volatile Slot
|
41
|
+
volatile Slot *slots;
|
42
42
|
volatile size_t cnt;
|
43
43
|
VALUE (*form)(const char *str, size_t len);
|
44
44
|
uint64_t size;
|
@@ -53,7 +53,7 @@ typedef struct _cache {
|
|
53
53
|
#endif
|
54
54
|
uint8_t xrate;
|
55
55
|
bool mark;
|
56
|
-
} *
|
56
|
+
} *Cache;
|
57
57
|
|
58
58
|
void cache_set_form(Cache c, VALUE (*form)(const char *str, size_t len)) {
|
59
59
|
c->form = form;
|
@@ -95,8 +95,8 @@ static uint64_t hash_calc(const uint8_t *key, size_t len) {
|
|
95
95
|
|
96
96
|
static void rehash(Cache c) {
|
97
97
|
uint64_t osize;
|
98
|
-
Slot
|
99
|
-
Slot
|
98
|
+
Slot *end;
|
99
|
+
Slot *sp;
|
100
100
|
|
101
101
|
osize = c->size;
|
102
102
|
c->size = osize * 4;
|
@@ -111,7 +111,7 @@ static void rehash(Cache c) {
|
|
111
111
|
*sp = NULL;
|
112
112
|
for (; NULL != s; s = next) {
|
113
113
|
uint64_t h = s->hash & c->mask;
|
114
|
-
Slot
|
114
|
+
Slot *bucket = (Slot *)c->slots + h;
|
115
115
|
|
116
116
|
next = s->next;
|
117
117
|
s->next = *bucket;
|
@@ -122,7 +122,7 @@ static void rehash(Cache c) {
|
|
122
122
|
|
123
123
|
static VALUE lockless_intern(Cache c, const char *key, size_t len) {
|
124
124
|
uint64_t h = hash_calc((const uint8_t *)key, len);
|
125
|
-
Slot
|
125
|
+
Slot *bucket = (Slot *)c->slots + (h & c->mask);
|
126
126
|
Slot b;
|
127
127
|
volatile VALUE rkey;
|
128
128
|
|
@@ -166,7 +166,7 @@ static VALUE lockless_intern(Cache c, const char *key, size_t len) {
|
|
166
166
|
|
167
167
|
static VALUE locking_intern(Cache c, const char *key, size_t len) {
|
168
168
|
uint64_t h;
|
169
|
-
Slot
|
169
|
+
Slot *bucket;
|
170
170
|
Slot b;
|
171
171
|
uint64_t old_size;
|
172
172
|
volatile VALUE rkey;
|
@@ -242,12 +242,12 @@ Cache cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool
|
|
242
242
|
#else
|
243
243
|
c->mutex = rb_mutex_new();
|
244
244
|
#endif
|
245
|
-
c->size
|
246
|
-
c->mask
|
247
|
-
c->slots
|
248
|
-
c->form
|
249
|
-
c->xrate
|
250
|
-
c->mark
|
245
|
+
c->size = 1 << shift;
|
246
|
+
c->mask = c->size - 1;
|
247
|
+
c->slots = OJ_CALLOC(c->size, sizeof(Slot));
|
248
|
+
c->form = form;
|
249
|
+
c->xrate = 1; // low
|
250
|
+
c->mark = mark;
|
251
251
|
if (locking) {
|
252
252
|
c->intern = locking_intern;
|
253
253
|
} else {
|
data/ext/oj/cache8.c
CHANGED
@@ -39,10 +39,12 @@ void oj_cache8_new(Cache8 *cache) {
|
|
39
39
|
}
|
40
40
|
}
|
41
41
|
|
42
|
-
void oj_cache8_delete(Cache8 cache) {
|
42
|
+
void oj_cache8_delete(Cache8 cache) {
|
43
|
+
cache8_delete(cache, 0);
|
44
|
+
}
|
43
45
|
|
44
46
|
static void cache8_delete(Cache8 cache, int depth) {
|
45
|
-
Bucket
|
47
|
+
Bucket *b;
|
46
48
|
unsigned int i;
|
47
49
|
|
48
50
|
for (i = 0, b = cache->buckets; i < SLOT_CNT; i++, b++) {
|
@@ -80,7 +82,7 @@ void oj_cache8_print(Cache8 cache) {
|
|
80
82
|
}
|
81
83
|
|
82
84
|
static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
|
83
|
-
Bucket
|
85
|
+
Bucket *b;
|
84
86
|
unsigned int i;
|
85
87
|
sid_t k8 = (sid_t)key;
|
86
88
|
sid_t k;
|
@@ -91,11 +93,9 @@ static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
|
|
91
93
|
/*printf("*** key: 0x%016llx depth: %u i: %u\n", k, depth, i); */
|
92
94
|
if (DEPTH - 1 == depth) {
|
93
95
|
#if IS_WINDOWS
|
94
|
-
printf("0x%016lx: %4lu\n", (long unsigned int)k,
|
95
|
-
(long unsigned int)b->value);
|
96
|
+
printf("0x%016lx: %4lu\n", (long unsigned int)k, (long unsigned int)b->value);
|
96
97
|
#else
|
97
|
-
printf("0x%016llx: %4llu\n", (long long unsigned int)k,
|
98
|
-
(long long unsigned int)b->value);
|
98
|
+
printf("0x%016llx: %4llu\n", (long long unsigned int)k, (long long unsigned int)b->value);
|
99
99
|
#endif
|
100
100
|
} else {
|
101
101
|
slot_print(b->child, k, depth + 1);
|
data/ext/oj/circarray.c
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
2
2
|
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
3
3
|
|
4
|
-
#include "mem.h"
|
5
4
|
#include "circarray.h"
|
6
5
|
|
6
|
+
#include "mem.h"
|
7
|
+
|
7
8
|
CircArray oj_circ_array_new(void) {
|
8
9
|
CircArray ca;
|
9
10
|
|
data/ext/oj/circarray.h
CHANGED
@@ -9,10 +9,10 @@
|
|
9
9
|
|
10
10
|
typedef struct _circArray {
|
11
11
|
VALUE obj_array[1024];
|
12
|
-
VALUE
|
12
|
+
VALUE* objs;
|
13
13
|
unsigned long size; // allocated size or initial array size
|
14
14
|
unsigned long cnt;
|
15
|
-
}
|
15
|
+
}* CircArray;
|
16
16
|
|
17
17
|
extern CircArray oj_circ_array_new(void);
|
18
18
|
extern void oj_circ_array_free(CircArray ca);
|
data/ext/oj/code.c
CHANGED
@@ -18,8 +18,8 @@ inline static VALUE resolve_classname(VALUE mod, const char *classname) {
|
|
18
18
|
static VALUE path2class(const char *name) {
|
19
19
|
char class_name[1024];
|
20
20
|
VALUE clas;
|
21
|
-
char
|
22
|
-
char
|
21
|
+
char *end = class_name + sizeof(class_name) - 1;
|
22
|
+
char *s;
|
23
23
|
const char *n = name;
|
24
24
|
|
25
25
|
clas = rb_cObject;
|
data/ext/oj/code.h
CHANGED
@@ -17,7 +17,7 @@ typedef struct _code {
|
|
17
17
|
EncodeFunc encode;
|
18
18
|
DecodeFunc decode;
|
19
19
|
bool active; // For compat mode.
|
20
|
-
} *
|
20
|
+
} *Code;
|
21
21
|
|
22
22
|
// Used by encode functions.
|
23
23
|
typedef struct _attr {
|
@@ -26,7 +26,7 @@ typedef struct _attr {
|
|
26
26
|
VALUE value;
|
27
27
|
long num;
|
28
28
|
VALUE time;
|
29
|
-
} *
|
29
|
+
} *Attr;
|
30
30
|
|
31
31
|
extern bool oj_code_dump(Code codes, VALUE obj, int depth, Out out);
|
32
32
|
extern VALUE oj_code_load(Code codes, VALUE clas, VALUE args);
|
data/ext/oj/compat.c
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
|
4
4
|
#include <stdio.h>
|
5
5
|
|
6
|
-
#include "mem.h"
|
7
6
|
#include "encode.h"
|
8
7
|
#include "err.h"
|
9
8
|
#include "intern.h"
|
9
|
+
#include "mem.h"
|
10
10
|
#include "oj.h"
|
11
11
|
#include "parse.h"
|
12
12
|
#include "resolve.h"
|
13
13
|
#include "trace.h"
|
14
14
|
|
15
15
|
static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
16
|
-
const char
|
16
|
+
const char *key = kval->key;
|
17
17
|
int klen = kval->klen;
|
18
18
|
Val parent = stack_peek(&pi->stack);
|
19
19
|
volatile VALUE rkey = kval->key_val;
|
@@ -31,7 +31,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
31
31
|
if (Yes == pi->options.sym_key) {
|
32
32
|
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
|
33
33
|
} else {
|
34
|
-
|
34
|
+
rkey = rb_utf8_str_new(key, klen);
|
35
35
|
}
|
36
36
|
} else if (Yes == pi->options.sym_key) {
|
37
37
|
rkey = oj_sym_intern(key, klen);
|
@@ -116,16 +116,12 @@ static void add_num(ParseInfo pi, NumInfo ni) {
|
|
116
116
|
static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
|
117
117
|
volatile VALUE rval = oj_num_as_value(ni);
|
118
118
|
|
119
|
-
if (
|
119
|
+
if (rb_cHash != rb_obj_class(parent->val)) {
|
120
120
|
// The rb_hash_set would still work but the unit tests for the
|
121
121
|
// json gem require the less efficient []= method be called to set
|
122
122
|
// values. Even using the store method to set the values will fail
|
123
123
|
// the unit tests.
|
124
|
-
rb_funcall(stack_peek(&pi->stack)->val,
|
125
|
-
rb_intern("[]="),
|
126
|
-
2,
|
127
|
-
oj_calc_hash_key(pi, parent),
|
128
|
-
rval);
|
124
|
+
rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, oj_calc_hash_key(pi, parent), rval);
|
129
125
|
} else {
|
130
126
|
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
|
131
127
|
}
|
@@ -138,11 +134,7 @@ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
|
138
134
|
// json gem require the less efficient []= method be called to set
|
139
135
|
// values. Even using the store method to set the values will fail
|
140
136
|
// the unit tests.
|
141
|
-
rb_funcall(stack_peek(&pi->stack)->val,
|
142
|
-
rb_intern("[]="),
|
143
|
-
2,
|
144
|
-
oj_calc_hash_key(pi, parent),
|
145
|
-
value);
|
137
|
+
rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, oj_calc_hash_key(pi, parent), value);
|
146
138
|
} else {
|
147
139
|
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
|
148
140
|
}
|
data/ext/oj/custom.c
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
#include <stdint.h>
|
5
5
|
#include <stdio.h>
|
6
6
|
|
7
|
-
#include "mem.h"
|
8
7
|
#include "code.h"
|
9
8
|
#include "dump.h"
|
10
9
|
#include "encode.h"
|
11
10
|
#include "err.h"
|
12
11
|
#include "intern.h"
|
12
|
+
#include "mem.h"
|
13
13
|
#include "odd.h"
|
14
14
|
#include "oj.h"
|
15
15
|
#include "parse.h"
|
@@ -937,9 +937,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
937
937
|
break;
|
938
938
|
default: break;
|
939
939
|
}
|
940
|
-
|
941
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
|
942
|
-
}
|
940
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rstr);
|
943
941
|
}
|
944
942
|
}
|
945
943
|
|
@@ -998,9 +996,7 @@ static void hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
|
998
996
|
break;
|
999
997
|
default: break;
|
1000
998
|
}
|
1001
|
-
|
1002
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rval);
|
1003
|
-
}
|
999
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rval);
|
1004
1000
|
}
|
1005
1001
|
|
1006
1002
|
static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
@@ -1011,9 +1007,7 @@ static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
1011
1007
|
case T_HASH: rb_hash_aset(parent->val, oj_calc_hash_key(pi, kval), value); break;
|
1012
1008
|
default: break;
|
1013
1009
|
}
|
1014
|
-
|
1015
|
-
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
1016
|
-
}
|
1010
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
|
1017
1011
|
}
|
1018
1012
|
|
1019
1013
|
static void array_append_num(ParseInfo pi, NumInfo ni) {
|
@@ -1021,9 +1015,7 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
1021
1015
|
volatile VALUE rval = oj_num_as_value(ni);
|
1022
1016
|
|
1023
1017
|
rb_ary_push(parent->val, rval);
|
1024
|
-
|
1025
|
-
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
1026
|
-
}
|
1018
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, rval);
|
1027
1019
|
}
|
1028
1020
|
|
1029
1021
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
@@ -1038,9 +1030,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
|
|
1038
1030
|
}
|
1039
1031
|
}
|
1040
1032
|
rb_ary_push(stack_peek(&pi->stack)->val, rstr);
|
1041
|
-
|
1042
|
-
oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
|
1043
|
-
}
|
1033
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_string", pi, rstr);
|
1044
1034
|
}
|
1045
1035
|
|
1046
1036
|
void oj_set_custom_callbacks(ParseInfo pi) {
|
data/ext/oj/debug.c
CHANGED
@@ -30,9 +30,7 @@ static void add_int(struct _ojParser *p) {
|
|
30
30
|
switch (p->stack[p->depth]) {
|
31
31
|
case TOP_FUN: printf("*** add_int %lld at top\n", (long long)p->num.fixnum); break;
|
32
32
|
case ARRAY_FUN: printf("*** add_int %lld to array\n", (long long)p->num.fixnum); break;
|
33
|
-
case OBJECT_FUN:
|
34
|
-
printf("*** add_int %lld with '%s'\n", (long long)p->num.fixnum, buf_str(&p->key));
|
35
|
-
break;
|
33
|
+
case OBJECT_FUN: printf("*** add_int %lld with '%s'\n", (long long)p->num.fixnum, buf_str(&p->key)); break;
|
36
34
|
}
|
37
35
|
}
|
38
36
|
|
@@ -48,9 +46,7 @@ static void add_big(struct _ojParser *p) {
|
|
48
46
|
switch (p->stack[p->depth]) {
|
49
47
|
case TOP_FUN: printf("*** add_big %s at top\n", buf_str(&p->buf)); break;
|
50
48
|
case ARRAY_FUN: printf("*** add_big %s to array\n", buf_str(&p->buf)); break;
|
51
|
-
case OBJECT_FUN:
|
52
|
-
printf("*** add_big %s with '%s'\n", buf_str(&p->buf), buf_str(&p->key));
|
53
|
-
break;
|
49
|
+
case OBJECT_FUN: printf("*** add_big %s with '%s'\n", buf_str(&p->buf), buf_str(&p->key)); break;
|
54
50
|
}
|
55
51
|
}
|
56
52
|
|
@@ -58,9 +54,7 @@ static void add_str(struct _ojParser *p) {
|
|
58
54
|
switch (p->stack[p->depth]) {
|
59
55
|
case TOP_FUN: printf("*** add_str '%s' at top\n", buf_str(&p->buf)); break;
|
60
56
|
case ARRAY_FUN: printf("*** add_str '%s' to array\n", buf_str(&p->buf)); break;
|
61
|
-
case OBJECT_FUN:
|
62
|
-
printf("*** add_str '%s' with '%s'\n", buf_str(&p->buf), buf_str(&p->key));
|
63
|
-
break;
|
57
|
+
case OBJECT_FUN: printf("*** add_str '%s' with '%s'\n", buf_str(&p->buf), buf_str(&p->key)); break;
|
64
58
|
}
|
65
59
|
}
|
66
60
|
|
data/ext/oj/dump.c
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
#include <poll.h>
|
15
15
|
#endif
|
16
16
|
|
17
|
-
#include "mem.h"
|
18
17
|
#include "cache8.h"
|
18
|
+
#include "mem.h"
|
19
19
|
#include "odd.h"
|
20
20
|
#include "oj.h"
|
21
21
|
#include "trace.h"
|
@@ -306,8 +306,8 @@ static const char *dump_unicode(const char *str, const char *end, Out out, const
|
|
306
306
|
uint32_t c1;
|
307
307
|
|
308
308
|
code -= 0x00010000;
|
309
|
-
c1
|
310
|
-
code
|
309
|
+
c1 = ((code >> 10) & 0x000003FF) + 0x0000D800;
|
310
|
+
code = (code & 0x000003FF) + 0x0000DC00;
|
311
311
|
APPEND_CHARS(out->cur, "\\u", 2);
|
312
312
|
for (i = 3; 0 <= i; i--) {
|
313
313
|
*out->cur++ = hex_chars[(uint8_t)(c1 >> (i * 4)) & 0x0F];
|
@@ -610,7 +610,7 @@ void oj_write_obj_to_file(VALUE obj, const char *path, Options copts) {
|
|
610
610
|
|
611
611
|
oj_out_init(&out);
|
612
612
|
|
613
|
-
out.omit_nil
|
613
|
+
out.omit_nil = copts->dump_opts.omit_nil;
|
614
614
|
oj_dump_obj_to_json(obj, copts, &out);
|
615
615
|
size = out.cur - out.buf;
|
616
616
|
if (0 == (f = fopen(path, "w"))) {
|
@@ -658,7 +658,7 @@ void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts) {
|
|
658
658
|
|
659
659
|
oj_out_init(&out);
|
660
660
|
|
661
|
-
out.omit_nil
|
661
|
+
out.omit_nil = copts->dump_opts.omit_nil;
|
662
662
|
oj_dump_obj_to_json(obj, copts, &out);
|
663
663
|
size = out.cur - out.buf;
|
664
664
|
if (oj_stringio_class == clas) {
|
@@ -698,7 +698,7 @@ void oj_dump_str(VALUE obj, int depth, Out out, bool as_ok) {
|
|
698
698
|
|
699
699
|
if (oj_utf8_encoding_index != idx) {
|
700
700
|
rb_encoding *enc = rb_enc_from_index(idx);
|
701
|
-
obj
|
701
|
+
obj = rb_str_conv_enc(obj, enc, oj_utf8_encoding);
|
702
702
|
}
|
703
703
|
oj_dump_cstr(RSTRING_PTR(obj), (int)RSTRING_LEN(obj), 0, 0, out);
|
704
704
|
}
|
@@ -761,8 +761,8 @@ void oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out ou
|
|
761
761
|
break;
|
762
762
|
case SlashEsc:
|
763
763
|
has_hi = true;
|
764
|
-
cmap
|
765
|
-
size
|
764
|
+
cmap = slash_friendly_chars;
|
765
|
+
size = slash_friendly_size((uint8_t *)str, cnt);
|
766
766
|
break;
|
767
767
|
case XSSEsc:
|
768
768
|
cmap = xss_friendly_chars;
|
@@ -857,6 +857,9 @@ void oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out ou
|
|
857
857
|
break;
|
858
858
|
case '6': // control characters
|
859
859
|
if (*(uint8_t *)str < 0x80) {
|
860
|
+
if (0 == (uint8_t)*str && out->opts->dump_opts.omit_null_byte) {
|
861
|
+
break;
|
862
|
+
}
|
860
863
|
APPEND_CHARS(out->cur, "\\u00", 4);
|
861
864
|
dump_hex((uint8_t)*str, out);
|
862
865
|
} else {
|
@@ -941,15 +944,15 @@ void oj_dump_raw(const char *str, size_t cnt, Out out) {
|
|
941
944
|
}
|
942
945
|
|
943
946
|
void oj_out_init(Out out) {
|
944
|
-
out->buf
|
945
|
-
out->cur
|
946
|
-
out->end
|
947
|
+
out->buf = out->stack_buffer;
|
948
|
+
out->cur = out->buf;
|
949
|
+
out->end = out->buf + sizeof(out->stack_buffer) - BUFFER_EXTRA;
|
947
950
|
out->allocated = false;
|
948
951
|
}
|
949
952
|
|
950
953
|
void oj_out_free(Out out) {
|
951
954
|
if (out->allocated) {
|
952
|
-
OJ_R_FREE(out->buf);
|
955
|
+
OJ_R_FREE(out->buf); // TBD
|
953
956
|
}
|
954
957
|
}
|
955
958
|
|
@@ -980,24 +983,36 @@ void oj_grow_out(Out out, size_t len) {
|
|
980
983
|
void oj_dump_nil(VALUE obj, int depth, Out out, bool as_ok) {
|
981
984
|
assure_size(out, 4);
|
982
985
|
APPEND_CHARS(out->cur, "null", 4);
|
983
|
-
*out->cur
|
986
|
+
*out->cur = '\0';
|
984
987
|
}
|
985
988
|
|
986
989
|
void oj_dump_true(VALUE obj, int depth, Out out, bool as_ok) {
|
987
990
|
assure_size(out, 4);
|
988
991
|
APPEND_CHARS(out->cur, "true", 4);
|
989
|
-
*out->cur
|
992
|
+
*out->cur = '\0';
|
990
993
|
}
|
991
994
|
|
992
995
|
void oj_dump_false(VALUE obj, int depth, Out out, bool as_ok) {
|
993
996
|
assure_size(out, 5);
|
994
997
|
APPEND_CHARS(out->cur, "false", 5);
|
995
|
-
*out->cur
|
998
|
+
*out->cur = '\0';
|
996
999
|
}
|
997
1000
|
|
1001
|
+
static const char digits_table[] = "\
|
1002
|
+
00010203040506070809\
|
1003
|
+
10111213141516171819\
|
1004
|
+
20212223242526272829\
|
1005
|
+
30313233343536373839\
|
1006
|
+
40414243444546474849\
|
1007
|
+
50515253545556575859\
|
1008
|
+
60616263646566676869\
|
1009
|
+
70717273747576777879\
|
1010
|
+
80818283848586878889\
|
1011
|
+
90919293949596979899";
|
1012
|
+
|
998
1013
|
void oj_dump_fixnum(VALUE obj, int depth, Out out, bool as_ok) {
|
999
1014
|
char buf[32];
|
1000
|
-
char
|
1015
|
+
char *b = buf + sizeof(buf) - 1;
|
1001
1016
|
long long num = NUM2LL(obj);
|
1002
1017
|
int neg = 0;
|
1003
1018
|
size_t cnt = 0;
|
@@ -1017,9 +1032,19 @@ void oj_dump_fixnum(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1017
1032
|
*b-- = '"';
|
1018
1033
|
}
|
1019
1034
|
if (0 < num) {
|
1020
|
-
|
1021
|
-
|
1035
|
+
while (100 <= num) {
|
1036
|
+
unsigned idx = num % 100 * 2;
|
1037
|
+
*b-- = digits_table[idx + 1];
|
1038
|
+
*b-- = digits_table[idx];
|
1039
|
+
num /= 100;
|
1022
1040
|
}
|
1041
|
+
if (num < 10) {
|
1042
|
+
*b-- = num + '0';
|
1043
|
+
} else {
|
1044
|
+
*b-- = digits_table[num * 2 + 1];
|
1045
|
+
*b-- = digits_table[num * 2];
|
1046
|
+
}
|
1047
|
+
|
1023
1048
|
if (neg) {
|
1024
1049
|
*b = '-';
|
1025
1050
|
} else {
|