oj 3.13.23 → 3.16.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +81 -0
- data/README.md +2 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +26 -59
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +103 -53
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- 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 +16 -7
- data/ext/oj/fast.c +60 -92
- data/ext/oj/intern.c +62 -47
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +51 -32
- data/ext/oj/object.c +33 -43
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +243 -212
- data/ext/oj/oj.h +83 -81
- data/ext/oj/parse.c +94 -148
- data/ext/oj/parse.h +21 -24
- data/ext/oj/parser.c +80 -67
- data/ext/oj/parser.h +7 -8
- data/ext/oj/rails.c +70 -92
- data/ext/oj/reader.c +9 -14
- 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 +10 -9
- data/ext/oj/saj2.c +37 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +45 -41
- data/ext/oj/strict.c +20 -52
- data/ext/oj/string_writer.c +64 -38
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -114
- data/ext/oj/usual.h +7 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +13 -2
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- 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 +7 -7
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/InstallOptions.md +20 -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/activesupport6/encoding_test.rb +63 -28
- data/test/activesupport7/abstract_unit.rb +4 -1
- data/test/activesupport7/encoding_test.rb +72 -22
- data/test/files.rb +15 -15
- data/test/foo.rb +18 -69
- 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 +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 +50 -33
- 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 +28 -28
- 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 +5 -5
- 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 +81 -54
- data/test/test_custom.rb +63 -52
- 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 +92 -87
- data/test/test_parser.rb +4 -4
- data/test/test_parser_debug.rb +5 -5
- data/test/test_parser_saj.rb +27 -25
- data/test/test_parser_usual.rb +44 -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 +38 -32
- data/test/test_various.rb +146 -97
- data/test/test_wab.rb +46 -44
- data/test/test_writer.rb +63 -47
- data/test/tests.rb +7 -7
- data/test/tests_mimic.rb +6 -6
- data/test/tests_mimic_addition.rb +6 -6
- metadata +46 -26
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
- data/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: d3e57c02a1fe6782596953f34b8e2a2b729a09b5d8e7128dd4633d430ca7aa0c
|
4
|
+
data.tar.gz: 7698f8c0203459d62f4421f11a9c3637b04b5b808ecf87ce4ca057e2fd073762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417ada5b645a6ba48e81b52bb72cec97bb4a64595a61252989346a975c1026b3cbc039cbf7cef166b5dbfbdd79554d5c9e5786da3299ce1fd3f2ec70d3ef479f
|
7
|
+
data.tar.gz: ceffb29c6732b107d42091bc8754e8b4174e26e6d8eb9c4162ed8a12a65d37aa2450f9f5398d39242d92fabd46d63be5fc14e0dc003774378e4e6211b02e3f0d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,86 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.16.9 - 2024-12-28
|
4
|
+
|
5
|
+
- Fixed `Oj::Parser` create_id size issue #931.
|
6
|
+
|
7
|
+
- Changed parser to be more optimized (PR from @Watson1978)
|
8
|
+
|
9
|
+
## 3.16.8 - 2024-12-14
|
10
|
+
|
11
|
+
- Fixed StreamWriter to write to non-file IO thanks to @jscheid.
|
12
|
+
|
13
|
+
## 3.16.7 - 2024-11-01
|
14
|
+
|
15
|
+
- Changed string_writer_as_json to allow multiple arguments.
|
16
|
+
|
17
|
+
- Fixed Global variable registration added to mimic_json and rails code thanks to @byroot.
|
18
|
+
|
19
|
+
## 3.16.6 - 2024-09-09
|
20
|
+
|
21
|
+
- Fixed issue with Rails 7.2 that changed the order of calls to to_json and as_json.
|
22
|
+
|
23
|
+
## 3.16.5 - 2024-08-07
|
24
|
+
|
25
|
+
- Fixed Oj::Parser so that block procedures work correctly.
|
26
|
+
|
27
|
+
## 3.16.4 - 2024-06-08
|
28
|
+
|
29
|
+
- Fixed Oj::Parse EOF issue on larger stream input.
|
30
|
+
|
31
|
+
## 3.16.3 - 2023-12-11
|
32
|
+
|
33
|
+
- Fixed the gemspec to allow earlier versions of the bigdecimal gem.
|
34
|
+
|
35
|
+
## 3.16.2 - 2023-12-06
|
36
|
+
|
37
|
+
- Fixed documentation formatting.
|
38
|
+
|
39
|
+
- Added option to the "usual" parser to raise an error on an empty input string.
|
40
|
+
|
41
|
+
## 3.16.1 - 2023-09-01
|
42
|
+
|
43
|
+
- Fixed exception type on number parsing. (thank you @jasonpenny)
|
44
|
+
|
45
|
+
## 3.16.0 - 2023-08-16
|
46
|
+
|
47
|
+
- Added the `float_format` option.
|
48
|
+
|
49
|
+
- Expanded the `max_nesting` option to allow integer values as well as
|
50
|
+
the previous boolean (true or nil).
|
51
|
+
|
52
|
+
- Skip nesting tests with Truffle Ruby in the json gem tests.
|
53
|
+
|
54
|
+
## 3.15.1 - 2023-07-30
|
55
|
+
|
56
|
+
- Add protection against some using `require 'oj/json`, an internal file.
|
57
|
+
|
58
|
+
- Fixed non-json errors when in compat mode.
|
59
|
+
|
60
|
+
## 3.15.0 - 2023-06-02
|
61
|
+
|
62
|
+
- Added `omit_null_byte` option when dumping.
|
63
|
+
|
64
|
+
## 3.14.3 - 2023-04-07
|
65
|
+
|
66
|
+
- Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
|
67
|
+
|
68
|
+
## 3.14.2 - 2023-02-10
|
69
|
+
|
70
|
+
- Fixed check for \0 in strings.
|
71
|
+
|
72
|
+
## 3.14.1 - 2023-02-01
|
73
|
+
|
74
|
+
- Fixed issue with uninitialized handler for Oj::Parser::Saj.
|
75
|
+
|
76
|
+
- Fixed hang on unterminated string with a \0 byte in parse.c.
|
77
|
+
|
78
|
+
## 3.14.0 - 2023-01-30
|
79
|
+
|
80
|
+
- Tracing is now a compile time option giving a 15 to 20% performance boost.
|
81
|
+
|
82
|
+
- Some cleanup in the fast parser.
|
83
|
+
|
3
84
|
## 3.13.23 - 2022-11-06
|
4
85
|
|
5
86
|
- Fixed issue with Oj::Parser extension regarding GC timeing.
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# [](http://www.ohler.com/oj) gem
|
2
2
|
|
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.
|
@@ -70,6 +69,7 @@ links.
|
|
70
69
|
- [{file:Compatibility.md}](pages/Compatibility.md) lists current compatibility with Rubys and Rails.
|
71
70
|
- [{file:Advanced.md}](pages/Advanced.md) for fast parser and marshalling features.
|
72
71
|
- [{file:Security.md}](pages/Security.md) for security considerations.
|
72
|
+
- [{file:InstallOptions.md}](pages/InstallOptions.md) for install option.
|
73
73
|
|
74
74
|
## Releases
|
75
75
|
|
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
|
|
@@ -49,10 +50,10 @@ inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
|
|
49
50
|
size_t new_len = len + slen + len / 2;
|
50
51
|
|
51
52
|
if (buf->base == buf->head) {
|
52
|
-
buf->head =
|
53
|
+
buf->head = OJ_R_ALLOC_N(char, new_len);
|
53
54
|
memcpy(buf->head, buf->base, len);
|
54
55
|
} else {
|
55
|
-
|
56
|
+
OJ_R_REALLOC_N(buf->head, char, new_len);
|
56
57
|
}
|
57
58
|
buf->tail = buf->head + toff;
|
58
59
|
buf->end = buf->head + new_len - 1;
|
@@ -68,10 +69,10 @@ inline static void buf_append(Buf buf, char c) {
|
|
68
69
|
size_t new_len = len + len / 2;
|
69
70
|
|
70
71
|
if (buf->base == buf->head) {
|
71
|
-
buf->head =
|
72
|
+
buf->head = OJ_R_ALLOC_N(char, new_len);
|
72
73
|
memcpy(buf->head, buf->base, len);
|
73
74
|
} else {
|
74
|
-
|
75
|
+
OJ_R_REALLOC_N(buf->head, char, new_len);
|
75
76
|
}
|
76
77
|
buf->tail = buf->head + toff;
|
77
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 {
|
@@ -259,7 +260,8 @@ void cache_set_expunge_rate(Cache c, int rate) {
|
|
259
260
|
c->xrate = (uint8_t)rate;
|
260
261
|
}
|
261
262
|
|
262
|
-
void cache_free(
|
263
|
+
void cache_free(void *data) {
|
264
|
+
Cache c = (Cache)data;
|
263
265
|
uint64_t i;
|
264
266
|
|
265
267
|
for (i = 0; i < c->size; i++) {
|
@@ -268,14 +270,15 @@ void cache_free(Cache c) {
|
|
268
270
|
|
269
271
|
for (s = c->slots[i]; NULL != s; s = next) {
|
270
272
|
next = s->next;
|
271
|
-
|
273
|
+
OJ_FREE(s);
|
272
274
|
}
|
273
275
|
}
|
274
|
-
|
275
|
-
|
276
|
+
OJ_FREE((void *)c->slots);
|
277
|
+
OJ_FREE(c);
|
276
278
|
}
|
277
279
|
|
278
|
-
void cache_mark(
|
280
|
+
void cache_mark(void *data) {
|
281
|
+
Cache c = (Cache)data;
|
279
282
|
uint64_t i;
|
280
283
|
|
281
284
|
#if !HAVE_PTHREAD_MUTEX_INIT
|
data/ext/oj/cache.h
CHANGED
@@ -10,10 +10,11 @@
|
|
10
10
|
#define CACHE_MAX_KEY 35
|
11
11
|
|
12
12
|
struct _cache;
|
13
|
+
typedef struct _cache *Cache;
|
13
14
|
|
14
15
|
extern struct _cache *cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool mark, bool locking);
|
15
|
-
extern void cache_free(
|
16
|
-
extern void cache_mark(
|
16
|
+
extern void cache_free(void *data);
|
17
|
+
extern void cache_mark(void *data);
|
17
18
|
extern void cache_set_form(struct _cache *c, VALUE (*form)(const char *str, size_t len));
|
18
19
|
extern VALUE cache_intern(struct _cache *c, const char *key, size_t len);
|
19
20
|
extern void cache_set_expunge_rate(struct _cache *c, int rate);
|
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
|
+
#include "mem.h"
|
7
|
+
|
6
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(void) {
|
|
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;
|
@@ -185,24 +185,17 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
185
185
|
} else {
|
186
186
|
char buf[32];
|
187
187
|
char *b = buf + sizeof(buf) - 1;
|
188
|
-
|
188
|
+
bool neg = false;
|
189
189
|
long num = attrs->num;
|
190
190
|
size_t cnt = 0;
|
191
191
|
|
192
192
|
if (0 > num) {
|
193
|
-
neg =
|
193
|
+
neg = true;
|
194
194
|
num = -num;
|
195
195
|
}
|
196
196
|
*b-- = '\0';
|
197
197
|
if (0 < num) {
|
198
|
-
|
199
|
-
*b = (num % 10) + '0';
|
200
|
-
}
|
201
|
-
if (neg) {
|
202
|
-
*b = '-';
|
203
|
-
} else {
|
204
|
-
b++;
|
205
|
-
}
|
198
|
+
b = oj_longlong_to_string(num, neg, b);
|
206
199
|
} else {
|
207
200
|
*b = '0';
|
208
201
|
}
|
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);
|