oj 3.13.9 → 3.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +101 -0
- data/README.md +13 -2
- data/ext/oj/buf.h +11 -6
- data/ext/oj/cache.c +25 -24
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +76 -155
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +203 -213
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +59 -181
- data/ext/oj/dump_strict.c +24 -48
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +18 -7
- data/ext/oj/fast.c +83 -108
- data/ext/oj/intern.c +52 -50
- data/ext/oj/intern.h +4 -8
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +104 -81
- data/ext/oj/object.c +50 -67
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +171 -106
- data/ext/oj/oj.h +96 -74
- data/ext/oj/parse.c +169 -189
- data/ext/oj/parse.h +23 -24
- data/ext/oj/parser.c +89 -34
- data/ext/oj/parser.h +20 -9
- data/ext/oj/rails.c +86 -151
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +12 -15
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +21 -32
- data/ext/oj/saj2.c +329 -93
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +26 -70
- data/ext/oj/stream_writer.c +12 -22
- data/ext/oj/strict.c +20 -52
- data/ext/oj/string_writer.c +21 -22
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +105 -150
- data/ext/oj/usual.h +68 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +1 -1
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +21 -26
- data/ext/oj/wab.c +32 -69
- data/lib/oj/active_support_helper.rb +1 -3
- 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 +162 -150
- data/lib/oj/mimic.rb +6 -2
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/state.rb +9 -6
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +6 -3
- data/pages/Options.md +10 -0
- data/pages/Rails.md +12 -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/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +20 -34
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +15 -15
- data/test/helper.rb +11 -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 +8 -6
- 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 +49 -37
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +13 -12
- data/test/perf.rb +21 -26
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- 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 +42 -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 +95 -43
- data/test/test_custom.rb +72 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +102 -87
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -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 +85 -96
- data/test/test_parser.rb +6 -22
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +115 -23
- 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 +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +163 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +34 -144
- 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/test_helper.rb +0 -72
- data/test/bar.rb +0 -16
- 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: 380409882636ecb1f8e3e54369f85dc11d7e167db741f5aec15bfadad2180601
|
4
|
+
data.tar.gz: 0c60d6f8a5b7d76904b84d378e41632f67c0e3fa2e61aeacfb680cadf15ef9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cbb6d75ab0c495c8d40983970e8fca54aa846eedb4e031368a98874f1db4ca68f160076ac59c230186316dc686923bad86196fa09bf585f501cf11fe814f9bc
|
7
|
+
data.tar.gz: 9d521e53c4e5311eda8abb0f89b12ae2dd3f8007abb02f0b5ff7728311f6d0b64221a493f8df66a7f223dd12c2c2ba6d47b309867f99e2fe206d440d028368a6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,106 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.16.1 - 2023-09-01
|
4
|
+
|
5
|
+
- Fixed exception type on number parsing. (thank you @jasonpenny)
|
6
|
+
|
7
|
+
## 3.16.0 - 2023-08-16
|
8
|
+
|
9
|
+
- Added the `float_format` option.
|
10
|
+
|
11
|
+
- Expanded the `max_nesting` option to allow integer values as well as
|
12
|
+
the previous boolean (true or nil).
|
13
|
+
|
14
|
+
- Skip nesting tests with Truffle Ruby in the json gem tests.
|
15
|
+
|
16
|
+
## 3.15.1 - 2023-07-30
|
17
|
+
|
18
|
+
- Add protection against some using `require 'oj/json`, an internal file.
|
19
|
+
|
20
|
+
- Fixed non-json errors when in compat mode.
|
21
|
+
|
22
|
+
## 3.15.0 - 2023-06-02
|
23
|
+
|
24
|
+
- Added `omit_null_byte` option when dumping.
|
25
|
+
|
26
|
+
## 3.14.3 - 2023-04-07
|
27
|
+
|
28
|
+
- Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
|
29
|
+
|
30
|
+
## 3.14.2 - 2023-02-10
|
31
|
+
|
32
|
+
- Fixed check for \0 in strings.
|
33
|
+
|
34
|
+
## 3.14.1 - 2023-02-01
|
35
|
+
|
36
|
+
- Fixed issue with uninitialized handler for Oj::Parser::Saj.
|
37
|
+
|
38
|
+
- Fixed hang on unterminated string with a \0 byte in parse.c.
|
39
|
+
|
40
|
+
## 3.14.0 - 2023-01-30
|
41
|
+
|
42
|
+
- Tracing is now a compile time option giving a 15 to 20% performance boost.
|
43
|
+
|
44
|
+
- Some cleanup in the fast parser.
|
45
|
+
|
46
|
+
## 3.13.23 - 2022-11-06
|
47
|
+
|
48
|
+
- Fixed issue with Oj::Parser extension regarding GC timeing.
|
49
|
+
|
50
|
+
## 3.13.22 - 2022-11-01
|
51
|
+
|
52
|
+
- Reorganized Oj::Parser code to allow for parser extensions in C.
|
53
|
+
|
54
|
+
## 3.13.21 - 2022-08-19
|
55
|
+
|
56
|
+
- Bug parsing big numbers fixed in the SAJ parser.
|
57
|
+
|
58
|
+
## 3.13.20 - 2022-08-07
|
59
|
+
|
60
|
+
- SSE4 made optional with a `--with-sse42` flag to the compile.
|
61
|
+
|
62
|
+
## 3.13.19 - 2022-07-29
|
63
|
+
|
64
|
+
- TruffleRuby issues resolved.
|
65
|
+
|
66
|
+
## 3.13.18 - 2022-07-25
|
67
|
+
|
68
|
+
- Fixed SSE detection at run time.
|
69
|
+
|
70
|
+
## 3.13.17 - 2022-07-15
|
71
|
+
|
72
|
+
- Fixed Oj::Parser to detect unterminated arrays and objects.
|
73
|
+
|
74
|
+
## 3.13.16 - 2022-07-06
|
75
|
+
|
76
|
+
- Added line and column as optional arguments to the Oj::Parser.saj parser.
|
77
|
+
|
78
|
+
## 3.13.15 - 2022-07-03
|
79
|
+
|
80
|
+
- Fixed issue dumping NaN value in object mode.
|
81
|
+
|
82
|
+
## 3.13.14 - 2022-06-03
|
83
|
+
|
84
|
+
- Double fclose() due to bad merger fixed by tonobo.
|
85
|
+
|
86
|
+
## 3.13.13 - 2022-05-20
|
87
|
+
|
88
|
+
- Fixed flooding stdout with debug output when dumping.
|
89
|
+
|
90
|
+
## 3.13.12 - 2022-05-20
|
91
|
+
|
92
|
+
- Fixed crash on no arguments to pretty_generate. Now raises an exception.
|
93
|
+
- Register all classes and globals.
|
94
|
+
- Fixed memory issue with dumping.
|
95
|
+
|
96
|
+
## 3.13.11 - 2022-01-05
|
97
|
+
|
98
|
+
- Fixed write blocking failures on writes to a slow stream with larger writes.
|
99
|
+
|
100
|
+
## 3.13.10 - 2021-12-12
|
101
|
+
|
102
|
+
- Fixed Oj::Doc re-entrant issue with each_child.
|
103
|
+
- Fixed each_child on empty Oj::Doc.
|
3
104
|
|
4
105
|
## 3.13.9 - 2021-10-06
|
5
106
|
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# [![{}j](http://www.ohler.com/dev/images/oj_comet_64.svg)](http://www.ohler.com/oj) gem
|
2
2
|
|
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.
|
@@ -43,6 +42,15 @@ or in Bundler:
|
|
43
42
|
gem 'oj'
|
44
43
|
```
|
45
44
|
|
45
|
+
## Rails and json quickstart
|
46
|
+
|
47
|
+
See the Quickstart sections of the [Rails](pages/Rails.md) and [json](pages/JsonGem.md) docs.
|
48
|
+
|
49
|
+
## multi_json
|
50
|
+
|
51
|
+
Code which uses [multi_json](https://github.com/intridea/multi_json)
|
52
|
+
will automatically prefer Oj if it is installed.
|
53
|
+
|
46
54
|
## Support
|
47
55
|
|
48
56
|
[Get supported Oj with a Tidelift Subscription.](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme) Security updates are [supported](https://tidelift.com/security).
|
@@ -61,6 +69,7 @@ links.
|
|
61
69
|
- [{file:Compatibility.md}](pages/Compatibility.md) lists current compatibility with Rubys and Rails.
|
62
70
|
- [{file:Advanced.md}](pages/Advanced.md) for fast parser and marshalling features.
|
63
71
|
- [{file:Security.md}](pages/Security.md) for security considerations.
|
72
|
+
- [{file:InstallOptions.md}](pages/InstallOptions.md) for install option.
|
64
73
|
|
65
74
|
## Releases
|
66
75
|
|
@@ -100,6 +109,8 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
|
|
100
109
|
|
101
110
|
- *Agoo-C, a high performance C web server supporting GraphQL on GitHub*: https://github.com/ohler55/agoo-c
|
102
111
|
|
112
|
+
- *oj-introspect, an example of creating an Oj parser extension in C*: https://github.com/meinac/oj-introspect
|
113
|
+
|
103
114
|
#### Contributing
|
104
115
|
|
105
116
|
+ Provide a Pull Request off the `develop` branch.
|
data/ext/oj/buf.h
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
#ifndef OJ_BUF_H
|
5
5
|
#define OJ_BUF_H
|
6
6
|
|
7
|
+
#include "mem.h"
|
7
8
|
#include "ruby.h"
|
8
9
|
|
9
10
|
typedef struct _buf {
|
@@ -11,7 +12,7 @@ typedef struct _buf {
|
|
11
12
|
char *end;
|
12
13
|
char *tail;
|
13
14
|
char base[1024];
|
14
|
-
} *
|
15
|
+
} *Buf;
|
15
16
|
|
16
17
|
inline static void buf_init(Buf buf) {
|
17
18
|
buf->head = buf->base;
|
@@ -25,7 +26,7 @@ inline static void buf_reset(Buf buf) {
|
|
25
26
|
|
26
27
|
inline static void buf_cleanup(Buf buf) {
|
27
28
|
if (buf->base != buf->head) {
|
28
|
-
|
29
|
+
OJ_R_FREE(buf->head);
|
29
30
|
}
|
30
31
|
}
|
31
32
|
|
@@ -39,16 +40,20 @@ inline static const char *buf_str(Buf buf) {
|
|
39
40
|
}
|
40
41
|
|
41
42
|
inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
|
43
|
+
if (0 == slen) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
42
47
|
if (buf->end <= buf->tail + slen) {
|
43
48
|
size_t len = buf->end - buf->head;
|
44
49
|
size_t toff = buf->tail - buf->head;
|
45
50
|
size_t new_len = len + slen + len / 2;
|
46
51
|
|
47
52
|
if (buf->base == buf->head) {
|
48
|
-
buf->head =
|
53
|
+
buf->head = OJ_R_ALLOC_N(char, new_len);
|
49
54
|
memcpy(buf->head, buf->base, len);
|
50
55
|
} else {
|
51
|
-
|
56
|
+
OJ_R_REALLOC_N(buf->head, char, new_len);
|
52
57
|
}
|
53
58
|
buf->tail = buf->head + toff;
|
54
59
|
buf->end = buf->head + new_len - 1;
|
@@ -64,10 +69,10 @@ inline static void buf_append(Buf buf, char c) {
|
|
64
69
|
size_t new_len = len + len / 2;
|
65
70
|
|
66
71
|
if (buf->base == buf->head) {
|
67
|
-
buf->head =
|
72
|
+
buf->head = OJ_R_ALLOC_N(char, new_len);
|
68
73
|
memcpy(buf->head, buf->base, len);
|
69
74
|
} else {
|
70
|
-
|
75
|
+
OJ_R_REALLOC_N(buf->head, char, new_len);
|
71
76
|
}
|
72
77
|
buf->tail = buf->head + toff;
|
73
78
|
buf->end = buf->head + new_len - 1;
|
data/ext/oj/cache.c
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
#include <stdlib.h>
|
8
8
|
|
9
9
|
#include "cache.h"
|
10
|
+
#include "mem.h"
|
10
11
|
|
11
12
|
// The stdlib calloc, realloc, and free are used instead of the Ruby ALLOC,
|
12
13
|
// ALLOC_N, REALLOC, and xfree since the later could trigger a GC which will
|
@@ -28,16 +29,16 @@
|
|
28
29
|
#define M 0x5bd1e995
|
29
30
|
|
30
31
|
typedef struct _slot {
|
31
|
-
struct _slot
|
32
|
+
struct _slot *next;
|
32
33
|
VALUE val;
|
33
34
|
uint64_t hash;
|
34
35
|
volatile uint32_t use_cnt;
|
35
36
|
uint8_t klen;
|
36
37
|
char key[CACHE_MAX_KEY];
|
37
|
-
} *
|
38
|
+
} *Slot;
|
38
39
|
|
39
40
|
typedef struct _cache {
|
40
|
-
volatile Slot
|
41
|
+
volatile Slot *slots;
|
41
42
|
volatile size_t cnt;
|
42
43
|
VALUE (*form)(const char *str, size_t len);
|
43
44
|
uint64_t size;
|
@@ -52,7 +53,7 @@ typedef struct _cache {
|
|
52
53
|
#endif
|
53
54
|
uint8_t xrate;
|
54
55
|
bool mark;
|
55
|
-
} *
|
56
|
+
} *Cache;
|
56
57
|
|
57
58
|
void cache_set_form(Cache c, VALUE (*form)(const char *str, size_t len)) {
|
58
59
|
c->form = form;
|
@@ -94,13 +95,13 @@ static uint64_t hash_calc(const uint8_t *key, size_t len) {
|
|
94
95
|
|
95
96
|
static void rehash(Cache c) {
|
96
97
|
uint64_t osize;
|
97
|
-
Slot
|
98
|
-
Slot
|
98
|
+
Slot *end;
|
99
|
+
Slot *sp;
|
99
100
|
|
100
101
|
osize = c->size;
|
101
102
|
c->size = osize * 4;
|
102
103
|
c->mask = c->size - 1;
|
103
|
-
c->slots =
|
104
|
+
c->slots = OJ_REALLOC((void *)c->slots, sizeof(Slot) * c->size);
|
104
105
|
memset((Slot *)c->slots + osize, 0, sizeof(Slot) * osize * 3);
|
105
106
|
end = (Slot *)c->slots + osize;
|
106
107
|
for (sp = (Slot *)c->slots; sp < end; sp++) {
|
@@ -110,7 +111,7 @@ static void rehash(Cache c) {
|
|
110
111
|
*sp = NULL;
|
111
112
|
for (; NULL != s; s = next) {
|
112
113
|
uint64_t h = s->hash & c->mask;
|
113
|
-
Slot
|
114
|
+
Slot *bucket = (Slot *)c->slots + h;
|
114
115
|
|
115
116
|
next = s->next;
|
116
117
|
s->next = *bucket;
|
@@ -121,14 +122,14 @@ static void rehash(Cache c) {
|
|
121
122
|
|
122
123
|
static VALUE lockless_intern(Cache c, const char *key, size_t len) {
|
123
124
|
uint64_t h = hash_calc((const uint8_t *)key, len);
|
124
|
-
Slot
|
125
|
+
Slot *bucket = (Slot *)c->slots + (h & c->mask);
|
125
126
|
Slot b;
|
126
127
|
volatile VALUE rkey;
|
127
128
|
|
128
129
|
while (REUSE_MAX < c->rcnt) {
|
129
130
|
if (NULL != (b = c->reuse)) {
|
130
131
|
c->reuse = b->next;
|
131
|
-
|
132
|
+
OJ_FREE(b);
|
132
133
|
c->rcnt--;
|
133
134
|
} else {
|
134
135
|
// An accounting error occured somewhere so correct it.
|
@@ -143,7 +144,7 @@ static VALUE lockless_intern(Cache c, const char *key, size_t len) {
|
|
143
144
|
}
|
144
145
|
rkey = c->form(key, len);
|
145
146
|
if (NULL == (b = c->reuse)) {
|
146
|
-
b =
|
147
|
+
b = OJ_CALLOC(1, sizeof(struct _slot));
|
147
148
|
} else {
|
148
149
|
c->reuse = b->next;
|
149
150
|
c->rcnt--;
|
@@ -165,7 +166,7 @@ static VALUE lockless_intern(Cache c, const char *key, size_t len) {
|
|
165
166
|
|
166
167
|
static VALUE locking_intern(Cache c, const char *key, size_t len) {
|
167
168
|
uint64_t h;
|
168
|
-
Slot
|
169
|
+
Slot *bucket;
|
169
170
|
Slot b;
|
170
171
|
uint64_t old_size;
|
171
172
|
volatile VALUE rkey;
|
@@ -174,7 +175,7 @@ static VALUE locking_intern(Cache c, const char *key, size_t len) {
|
|
174
175
|
while (REUSE_MAX < c->rcnt) {
|
175
176
|
if (NULL != (b = c->reuse)) {
|
176
177
|
c->reuse = b->next;
|
177
|
-
|
178
|
+
OJ_FREE(b);
|
178
179
|
c->rcnt--;
|
179
180
|
} else {
|
180
181
|
// An accounting error occured somewhere so correct it.
|
@@ -200,7 +201,7 @@ static VALUE locking_intern(Cache c, const char *key, size_t len) {
|
|
200
201
|
}
|
201
202
|
CACHE_UNLOCK(c);
|
202
203
|
if (NULL == b) {
|
203
|
-
b =
|
204
|
+
b = OJ_CALLOC(1, sizeof(struct _slot));
|
204
205
|
}
|
205
206
|
rkey = c->form(key, len);
|
206
207
|
b->hash = h;
|
@@ -228,7 +229,7 @@ static VALUE locking_intern(Cache c, const char *key, size_t len) {
|
|
228
229
|
}
|
229
230
|
|
230
231
|
Cache cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool mark, bool locking) {
|
231
|
-
Cache c =
|
232
|
+
Cache c = OJ_CALLOC(1, sizeof(struct _cache));
|
232
233
|
int shift = 0;
|
233
234
|
|
234
235
|
for (; REHASH_LIMIT < size; size /= 2, shift++) {
|
@@ -241,12 +242,12 @@ Cache cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool
|
|
241
242
|
#else
|
242
243
|
c->mutex = rb_mutex_new();
|
243
244
|
#endif
|
244
|
-
c->size
|
245
|
-
c->mask
|
246
|
-
c->slots
|
247
|
-
c->form
|
248
|
-
c->xrate
|
249
|
-
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;
|
250
251
|
if (locking) {
|
251
252
|
c->intern = locking_intern;
|
252
253
|
} else {
|
@@ -268,11 +269,11 @@ void cache_free(Cache c) {
|
|
268
269
|
|
269
270
|
for (s = c->slots[i]; NULL != s; s = next) {
|
270
271
|
next = s->next;
|
271
|
-
|
272
|
+
OJ_FREE(s);
|
272
273
|
}
|
273
274
|
}
|
274
|
-
|
275
|
-
|
275
|
+
OJ_FREE((void *)c->slots);
|
276
|
+
OJ_FREE(c);
|
276
277
|
}
|
277
278
|
|
278
279
|
void cache_mark(Cache c) {
|
data/ext/oj/cache8.c
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
#include <stdlib.h>
|
10
10
|
#include <string.h>
|
11
11
|
|
12
|
+
#include "mem.h"
|
12
13
|
#include "ruby.h"
|
13
14
|
|
14
15
|
#define BITS 4
|
@@ -32,16 +33,18 @@ void oj_cache8_new(Cache8 *cache) {
|
|
32
33
|
Bucket *b;
|
33
34
|
int i;
|
34
35
|
|
35
|
-
*cache =
|
36
|
+
*cache = OJ_R_ALLOC(struct _cache8);
|
36
37
|
for (i = SLOT_CNT, b = (*cache)->buckets; 0 < i; i--, b++) {
|
37
38
|
b->value = 0;
|
38
39
|
}
|
39
40
|
}
|
40
41
|
|
41
|
-
void oj_cache8_delete(Cache8 cache) {
|
42
|
+
void oj_cache8_delete(Cache8 cache) {
|
43
|
+
cache8_delete(cache, 0);
|
44
|
+
}
|
42
45
|
|
43
46
|
static void cache8_delete(Cache8 cache, int depth) {
|
44
|
-
Bucket
|
47
|
+
Bucket *b;
|
45
48
|
unsigned int i;
|
46
49
|
|
47
50
|
for (i = 0, b = cache->buckets; i < SLOT_CNT; i++, b++) {
|
@@ -51,7 +54,7 @@ static void cache8_delete(Cache8 cache, int depth) {
|
|
51
54
|
}
|
52
55
|
}
|
53
56
|
}
|
54
|
-
|
57
|
+
OJ_R_FREE(cache);
|
55
58
|
}
|
56
59
|
|
57
60
|
slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot) {
|
@@ -79,7 +82,7 @@ void oj_cache8_print(Cache8 cache) {
|
|
79
82
|
}
|
80
83
|
|
81
84
|
static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
|
82
|
-
Bucket
|
85
|
+
Bucket *b;
|
83
86
|
unsigned int i;
|
84
87
|
sid_t k8 = (sid_t)key;
|
85
88
|
sid_t k;
|
@@ -90,11 +93,9 @@ static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
|
|
90
93
|
/*printf("*** key: 0x%016llx depth: %u i: %u\n", k, depth, i); */
|
91
94
|
if (DEPTH - 1 == depth) {
|
92
95
|
#if IS_WINDOWS
|
93
|
-
printf("0x%016lx: %4lu\n", (long unsigned int)k,
|
94
|
-
(long unsigned int)b->value);
|
96
|
+
printf("0x%016lx: %4lu\n", (long unsigned int)k, (long unsigned int)b->value);
|
95
97
|
#else
|
96
|
-
printf("0x%016llx: %4llu\n", (long long unsigned int)k,
|
97
|
-
(long long unsigned int)b->value);
|
98
|
+
printf("0x%016llx: %4llu\n", (long long unsigned int)k, (long long unsigned int)b->value);
|
98
99
|
#endif
|
99
100
|
} else {
|
100
101
|
slot_print(b->child, k, depth + 1);
|
data/ext/oj/circarray.c
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
|
4
4
|
#include "circarray.h"
|
5
5
|
|
6
|
-
|
6
|
+
#include "mem.h"
|
7
|
+
|
8
|
+
CircArray oj_circ_array_new(void) {
|
7
9
|
CircArray ca;
|
8
10
|
|
9
|
-
if (0 == (ca =
|
11
|
+
if (0 == (ca = OJ_R_ALLOC(struct _circArray))) {
|
10
12
|
rb_raise(rb_eNoMemError, "not enough memory\n");
|
11
13
|
}
|
12
14
|
ca->objs = ca->obj_array;
|
@@ -18,9 +20,9 @@ CircArray oj_circ_array_new() {
|
|
18
20
|
|
19
21
|
void oj_circ_array_free(CircArray ca) {
|
20
22
|
if (ca->objs != ca->obj_array) {
|
21
|
-
|
23
|
+
OJ_R_FREE(ca->objs);
|
22
24
|
}
|
23
|
-
|
25
|
+
OJ_R_FREE(ca);
|
24
26
|
}
|
25
27
|
|
26
28
|
void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
@@ -31,12 +33,12 @@ void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
|
31
33
|
unsigned long cnt = id + 512;
|
32
34
|
|
33
35
|
if (ca->objs == ca->obj_array) {
|
34
|
-
if (0 == (ca->objs =
|
36
|
+
if (0 == (ca->objs = OJ_R_ALLOC_N(VALUE, cnt))) {
|
35
37
|
rb_raise(rb_eNoMemError, "not enough memory\n");
|
36
38
|
}
|
37
39
|
memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
|
38
40
|
} else {
|
39
|
-
|
41
|
+
OJ_R_REALLOC_N(ca->objs, VALUE, cnt);
|
40
42
|
}
|
41
43
|
ca->size = cnt;
|
42
44
|
}
|
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;
|
@@ -140,21 +140,17 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
140
140
|
if (with_class) {
|
141
141
|
fill_indent(out, d2);
|
142
142
|
*out->cur++ = '"';
|
143
|
-
|
144
|
-
out->cur += out->opts->create_id_len;
|
143
|
+
APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
|
145
144
|
*out->cur++ = '"';
|
146
145
|
if (0 < out->opts->dump_opts.before_size) {
|
147
|
-
|
148
|
-
out->cur += out->opts->dump_opts.before_size;
|
146
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
149
147
|
}
|
150
148
|
*out->cur++ = ':';
|
151
149
|
if (0 < out->opts->dump_opts.after_size) {
|
152
|
-
|
153
|
-
out->cur += out->opts->dump_opts.after_size;
|
150
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
154
151
|
}
|
155
152
|
*out->cur++ = '"';
|
156
|
-
|
157
|
-
out->cur += len;
|
153
|
+
APPEND_CHARS(out->cur, classname, len);
|
158
154
|
*out->cur++ = '"';
|
159
155
|
no_comma = false;
|
160
156
|
}
|
@@ -168,17 +164,14 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
168
164
|
}
|
169
165
|
fill_indent(out, d2);
|
170
166
|
*out->cur++ = '"';
|
171
|
-
|
172
|
-
out->cur += attrs->len;
|
167
|
+
APPEND_CHARS(out->cur, attrs->name, attrs->len);
|
173
168
|
*out->cur++ = '"';
|
174
169
|
if (0 < out->opts->dump_opts.before_size) {
|
175
|
-
|
176
|
-
out->cur += out->opts->dump_opts.before_size;
|
170
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
177
171
|
}
|
178
172
|
*out->cur++ = ':';
|
179
173
|
if (0 < out->opts->dump_opts.after_size) {
|
180
|
-
|
181
|
-
out->cur += out->opts->dump_opts.after_size;
|
174
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
182
175
|
}
|
183
176
|
if (Qundef == attrs->value) {
|
184
177
|
if (Qundef != attrs->time) {
|
@@ -190,32 +183,25 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
190
183
|
default: oj_dump_time(attrs->time, out, false); break;
|
191
184
|
}
|
192
185
|
} else {
|
193
|
-
char
|
194
|
-
char
|
195
|
-
|
196
|
-
long
|
186
|
+
char buf[32];
|
187
|
+
char *b = buf + sizeof(buf) - 1;
|
188
|
+
bool neg = false;
|
189
|
+
long num = attrs->num;
|
190
|
+
size_t cnt = 0;
|
197
191
|
|
198
192
|
if (0 > num) {
|
199
|
-
neg =
|
193
|
+
neg = true;
|
200
194
|
num = -num;
|
201
195
|
}
|
202
196
|
*b-- = '\0';
|
203
197
|
if (0 < num) {
|
204
|
-
|
205
|
-
*b = (num % 10) + '0';
|
206
|
-
}
|
207
|
-
if (neg) {
|
208
|
-
*b = '-';
|
209
|
-
} else {
|
210
|
-
b++;
|
211
|
-
}
|
198
|
+
b = oj_longlong_to_string(num, neg, b);
|
212
199
|
} else {
|
213
200
|
*b = '0';
|
214
201
|
}
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
}
|
202
|
+
cnt = sizeof(buf) - (b - buf) - 1;
|
203
|
+
assure_size(out, cnt);
|
204
|
+
APPEND_CHARS(out->cur, b, cnt);
|
219
205
|
}
|
220
206
|
} else {
|
221
207
|
oj_dump_compat_val(attrs->value, d3, out, true);
|
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);
|