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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce52cbfa0a36f659877cda70d0376fdc19264f96ff8ff1f8085e8cb3560c8bae
|
4
|
+
data.tar.gz: 44b94e3e4174f1464dd7b4f025e28110dc273a353c42a4d8460c6e45846d1fab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465dd87a8c8e11b562de10d1ab60d78f8e2250c4c06f997455673ea67fb88c75e1c07dea01c01fa864ebfa39a2b0bee1371ee7551895ba6d125bee3af20975ee
|
7
|
+
data.tar.gz: 430a1f0a293fe87fd03af88b2e1f27e70ffae7b7ab8a2451dea1de5891ce6b9967f5475bd33f7cb37c728a7e4ed44b2b3c5051ebeb452c76f393f543a42d5dd1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.14.3 - 2023-04-07
|
4
|
+
|
5
|
+
- Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
|
6
|
+
|
3
7
|
## 3.14.2 - 2023-02-10
|
4
8
|
|
5
9
|
- Fixed check for \0 in strings.
|
@@ -14,7 +18,7 @@
|
|
14
18
|
|
15
19
|
- Tracing is now a compile time option giving a 15 to 20% performance boost.
|
16
20
|
|
17
|
-
- Some cleanup in
|
21
|
+
- Some cleanup in the fast parser.
|
18
22
|
|
19
23
|
## 3.13.23 - 2022-11-06
|
20
24
|
|
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
[![CI](https://github.com/ohler55/oj/actions/workflows/CI.yml/badge.svg)](https://github.com/ohler55/oj/actions/workflows/CI.yml)
|
4
4
|
![Gem](https://img.shields.io/gem/v/oj.svg)
|
5
5
|
![Gem](https://img.shields.io/gem/dt/oj.svg)
|
6
|
-
[![SemVer compatibility](https://api.dependabot.com/badges/compatibility_score?dependency-name=oj&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver)
|
7
6
|
[![TideLift](https://tidelift.com/badges/github/ohler55/oj)](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
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;
|
@@ -941,15 +941,15 @@ void oj_dump_raw(const char *str, size_t cnt, Out out) {
|
|
941
941
|
}
|
942
942
|
|
943
943
|
void oj_out_init(Out out) {
|
944
|
-
out->buf
|
945
|
-
out->cur
|
946
|
-
out->end
|
944
|
+
out->buf = out->stack_buffer;
|
945
|
+
out->cur = out->buf;
|
946
|
+
out->end = out->buf + sizeof(out->stack_buffer) - BUFFER_EXTRA;
|
947
947
|
out->allocated = false;
|
948
948
|
}
|
949
949
|
|
950
950
|
void oj_out_free(Out out) {
|
951
951
|
if (out->allocated) {
|
952
|
-
OJ_R_FREE(out->buf);
|
952
|
+
OJ_R_FREE(out->buf); // TBD
|
953
953
|
}
|
954
954
|
}
|
955
955
|
|
@@ -980,24 +980,24 @@ void oj_grow_out(Out out, size_t len) {
|
|
980
980
|
void oj_dump_nil(VALUE obj, int depth, Out out, bool as_ok) {
|
981
981
|
assure_size(out, 4);
|
982
982
|
APPEND_CHARS(out->cur, "null", 4);
|
983
|
-
*out->cur
|
983
|
+
*out->cur = '\0';
|
984
984
|
}
|
985
985
|
|
986
986
|
void oj_dump_true(VALUE obj, int depth, Out out, bool as_ok) {
|
987
987
|
assure_size(out, 4);
|
988
988
|
APPEND_CHARS(out->cur, "true", 4);
|
989
|
-
*out->cur
|
989
|
+
*out->cur = '\0';
|
990
990
|
}
|
991
991
|
|
992
992
|
void oj_dump_false(VALUE obj, int depth, Out out, bool as_ok) {
|
993
993
|
assure_size(out, 5);
|
994
994
|
APPEND_CHARS(out->cur, "false", 5);
|
995
|
-
*out->cur
|
995
|
+
*out->cur = '\0';
|
996
996
|
}
|
997
997
|
|
998
998
|
void oj_dump_fixnum(VALUE obj, int depth, Out out, bool as_ok) {
|
999
999
|
char buf[32];
|
1000
|
-
char
|
1000
|
+
char *b = buf + sizeof(buf) - 1;
|
1001
1001
|
long long num = NUM2LL(obj);
|
1002
1002
|
int neg = 0;
|
1003
1003
|
size_t cnt = 0;
|