oj 3.17.3 → 3.17.5
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 +75 -0
- data/ext/oj/cache.c +17 -1
- data/ext/oj/cache.h +5 -0
- data/ext/oj/circarray.c +6 -2
- data/ext/oj/compat.c +2 -2
- data/ext/oj/custom.c +5 -3
- data/ext/oj/dump.c +27 -12
- data/ext/oj/dump.h +10 -0
- data/ext/oj/dump_compat.c +11 -4
- data/ext/oj/dump_object.c +20 -10
- data/ext/oj/extconf.rb +1 -0
- data/ext/oj/fast.c +87 -44
- data/ext/oj/intern.c +6 -1
- data/ext/oj/object.c +26 -15
- data/ext/oj/odd.c +6 -2
- data/ext/oj/oj.c +224 -10
- data/ext/oj/oj.h +5 -1
- data/ext/oj/parse.c +17 -3
- data/ext/oj/parse.h +0 -1
- data/ext/oj/parser.c +120 -35
- data/ext/oj/rails.c +166 -40
- data/ext/oj/reader.c +18 -6
- data/ext/oj/resolve.c +11 -2
- data/ext/oj/rxclass.c +16 -0
- data/ext/oj/rxclass.h +1 -0
- data/ext/oj/safe.c +62 -48
- data/ext/oj/safe.h +14 -2
- data/ext/oj/saj.c +46 -10
- data/ext/oj/sparse.c +16 -6
- data/ext/oj/stream_writer.c +16 -1
- data/ext/oj/string_writer.c +23 -7
- data/ext/oj/usual.c +5 -1
- data/ext/oj/util.c +27 -0
- data/ext/oj/util.h +2 -1
- data/ext/oj/val_stack.h +24 -5
- data/ext/oj/wab.c +14 -26
- data/lib/oj/version.rb +1 -1
- data/pages/Compatibility.md +1 -1
- data/pages/Custom.md +2 -3
- data/pages/InstallOptions.md +8 -6
- data/pages/Modes.md +1 -1
- data/pages/Options.md +5 -6
- data/pages/Parser.md +2 -2
- data/pages/Rails.md +2 -0
- data/pages/Security.md +21 -7
- metadata +2 -2
data/ext/oj/wab.c
CHANGED
|
@@ -375,44 +375,41 @@ static const char *read_num(const char *s, int len, int *vp) {
|
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
static VALUE time_parse(const char *s, int len) {
|
|
378
|
-
struct
|
|
379
|
-
bool
|
|
380
|
-
long
|
|
381
|
-
int
|
|
382
|
-
time_t secs;
|
|
378
|
+
struct _timeInfo ti;
|
|
379
|
+
bool neg = false;
|
|
380
|
+
long nsecs = 0;
|
|
381
|
+
int i;
|
|
383
382
|
|
|
384
|
-
memset(&
|
|
383
|
+
memset(&ti, 0, sizeof(ti));
|
|
385
384
|
if ('-' == *s) {
|
|
386
385
|
s++;
|
|
387
386
|
neg = true;
|
|
388
387
|
}
|
|
389
|
-
if (NULL == (s = read_num(s, 4, &
|
|
388
|
+
if (NULL == (s = read_num(s, 4, &ti.year))) {
|
|
390
389
|
return Qnil;
|
|
391
390
|
}
|
|
392
391
|
if (neg) {
|
|
393
|
-
|
|
394
|
-
neg
|
|
392
|
+
ti.year = -ti.year;
|
|
393
|
+
neg = false;
|
|
395
394
|
}
|
|
396
|
-
tm.tm_year -= 1900;
|
|
397
395
|
s++;
|
|
398
|
-
if (NULL == (s = read_num(s, 2, &
|
|
396
|
+
if (NULL == (s = read_num(s, 2, &ti.mon))) {
|
|
399
397
|
return Qnil;
|
|
400
398
|
}
|
|
401
|
-
tm.tm_mon--;
|
|
402
399
|
s++;
|
|
403
|
-
if (NULL == (s = read_num(s, 2, &
|
|
400
|
+
if (NULL == (s = read_num(s, 2, &ti.day))) {
|
|
404
401
|
return Qnil;
|
|
405
402
|
}
|
|
406
403
|
s++;
|
|
407
|
-
if (NULL == (s = read_num(s, 2, &
|
|
404
|
+
if (NULL == (s = read_num(s, 2, &ti.hour))) {
|
|
408
405
|
return Qnil;
|
|
409
406
|
}
|
|
410
407
|
s++;
|
|
411
|
-
if (NULL == (s = read_num(s, 2, &
|
|
408
|
+
if (NULL == (s = read_num(s, 2, &ti.min))) {
|
|
412
409
|
return Qnil;
|
|
413
410
|
}
|
|
414
411
|
s++;
|
|
415
|
-
if (NULL == (s = read_num(s, 2, &
|
|
412
|
+
if (NULL == (s = read_num(s, 2, &ti.sec))) {
|
|
416
413
|
return Qnil;
|
|
417
414
|
}
|
|
418
415
|
s++;
|
|
@@ -424,16 +421,7 @@ static VALUE time_parse(const char *s, int len) {
|
|
|
424
421
|
return Qnil;
|
|
425
422
|
}
|
|
426
423
|
}
|
|
427
|
-
|
|
428
|
-
secs = (time_t)mktime(&tm);
|
|
429
|
-
memset(&tm, 0, sizeof(tm));
|
|
430
|
-
tm.tm_year = 70;
|
|
431
|
-
tm.tm_mday = 1;
|
|
432
|
-
secs -= (time_t)mktime(&tm);
|
|
433
|
-
#else
|
|
434
|
-
secs = (time_t)timegm(&tm);
|
|
435
|
-
#endif
|
|
436
|
-
return rb_funcall(rb_time_nano_new(secs, nsecs), oj_utc_id, 0);
|
|
424
|
+
return rb_funcall(rb_time_nano_new((time_t)time_as_sec(&ti), nsecs), oj_utc_id, 0);
|
|
437
425
|
}
|
|
438
426
|
|
|
439
427
|
static VALUE protect_uri(VALUE rstr) {
|
data/lib/oj/version.rb
CHANGED
data/pages/Compatibility.md
CHANGED
data/pages/Custom.md
CHANGED
|
@@ -8,9 +8,8 @@ for object dumping and loading. The `:compat` mode mimic the json gem
|
|
|
8
8
|
including methods called for encoding and inconsistencies between
|
|
9
9
|
`JSON.dump()`, `JSON.generate()`, and `JSON()`.
|
|
10
10
|
|
|
11
|
-
The `:custom` mode
|
|
12
|
-
|
|
13
|
-
options.
|
|
11
|
+
The `:custom` mode can be configured either by passing options to the
|
|
12
|
+
`Oj.dump()` and `Oj.load()` methods or by modifying the default options.
|
|
14
13
|
|
|
15
14
|
The ability to create objects from JSON object elements is supported and
|
|
16
15
|
considers the `:create_additions` option. Special treatment is given to the
|
data/pages/InstallOptions.md
CHANGED
|
@@ -10,11 +10,13 @@ To enable Oj trace feature, it uses `--enable-trace-log` option when installing
|
|
|
10
10
|
Then, the trace logs will be displayed when `:trace` option is set to `true`.
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### SIMD instructions
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
SIMD optimizations are enabled automatically, so no install option is
|
|
16
|
+
required. At runtime Oj detects the CPU features that are available and
|
|
17
|
+
selects the best implementation: SSE4.2 or SSE2 on x86 / x86_64, NEON on ARM,
|
|
18
|
+
and a scalar fallback when none is available.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
Earlier versions required a `--with-sse42` option at install time to turn on
|
|
21
|
+
SSE4.2. That option has been removed (#982); SSE4.2 is now selected
|
|
22
|
+
automatically when the CPU supports it.
|
data/pages/Modes.md
CHANGED
|
@@ -121,7 +121,7 @@ information.
|
|
|
121
121
|
| :object_nl | String | | | x | x | | x | |
|
|
122
122
|
| :omit_nil | Boolean | x | x | x | x | x | x | |
|
|
123
123
|
| :quirks_mode | Boolean | | | 6 | | | x | |
|
|
124
|
-
| :safe |
|
|
124
|
+
| :safe | Boolean | | | x | | | | |
|
|
125
125
|
| :second_precision | Fixnum | | | | | x | x | |
|
|
126
126
|
| :space | String | | | x | x | | x | |
|
|
127
127
|
| :space_before | String | | | x | x | | x | |
|
data/pages/Options.md
CHANGED
|
@@ -213,8 +213,7 @@ for json gem compatibility.
|
|
|
213
213
|
|
|
214
214
|
Primary behavior for loading and dumping. The :mode option controls which
|
|
215
215
|
other options are in effect. For more details see the {file:Modes.md} page. By
|
|
216
|
-
default Oj uses the :
|
|
217
|
-
customization.
|
|
216
|
+
default Oj uses the :object mode.
|
|
218
217
|
|
|
219
218
|
### :nan [Symbol]
|
|
220
219
|
|
|
@@ -249,6 +248,10 @@ integer gives better performance.
|
|
|
249
248
|
|
|
250
249
|
If true, Hash and Object attributes with nil values are omitted.
|
|
251
250
|
|
|
251
|
+
### :omit_null_byte [Boolean]
|
|
252
|
+
|
|
253
|
+
If true, null bytes in strings will be omitted when dumping.
|
|
254
|
+
|
|
252
255
|
### :quirks_mode [Boolean]
|
|
253
256
|
|
|
254
257
|
Allow single JSON values instead of documents, default is true (allow). This
|
|
@@ -265,10 +268,6 @@ to true.
|
|
|
265
268
|
|
|
266
269
|
The number of digits after the decimal when dumping the seconds of time.
|
|
267
270
|
|
|
268
|
-
### :skip_null_byte [Boolean]
|
|
269
|
-
|
|
270
|
-
If true, null bytes in strings will be omitted when dumping.
|
|
271
|
-
|
|
272
271
|
### :space
|
|
273
272
|
|
|
274
273
|
String inserted after the ':' character when dumping a JSON object. The
|
data/pages/Parser.md
CHANGED
|
@@ -280,7 +280,7 @@ Oj::Parser.usual 0.452 110544.876
|
|
|
280
280
|
JSON::Ext 1.009 49555.094
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
-
The `Oj::Parser.new(:
|
|
283
|
+
The `Oj::Parser.new(:usual)` is **1.55** times faster than `Oj.load` and
|
|
284
284
|
**2.23** times faster than the JSON gem.
|
|
285
285
|
|
|
286
286
|
### Object
|
|
@@ -298,7 +298,7 @@ Oj::Parser.usual 0.071 703502.033
|
|
|
298
298
|
JSON::Ext 0.401 124638.859
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
-
The `Oj::Parser.new(:
|
|
301
|
+
The `Oj::Parser.new(:usual)` is **3.17** times faster than
|
|
302
302
|
`Oj.compat_load` and **5.64** times faster than the JSON gem.
|
|
303
303
|
|
|
304
304
|
## Summary
|
data/pages/Rails.md
CHANGED
|
@@ -89,6 +89,8 @@ The classes that can be put in optimized mode and are optimized when
|
|
|
89
89
|
* any class inheriting from ActiveRecord::Base
|
|
90
90
|
* any other class where all attributes should be dumped
|
|
91
91
|
|
|
92
|
+
Both `Oj::Rails` and each `Oj::Rails::Encoder` have `optimize()`, `deoptimize()`, and `optimized?()` methods. The module level methods change the setting for the whole process. An encoder follows those process wide settings until `optimize()` or `deoptimize()` is called on the encoder itself. From then on the encoder keeps a set of its own and later module level changes do not reach it.
|
|
93
|
+
|
|
92
94
|
The ActiveSupport decoder is the `JSON.parse()` method. Calling the
|
|
93
95
|
`Oj::Rails.set_decoder()` method replaces that method with the Oj equivalent.
|
|
94
96
|
|
data/pages/Security.md
CHANGED
|
@@ -11,10 +11,24 @@ auto defined is used with an untrusted source. The `Oj.safe_load()` method
|
|
|
11
11
|
sets and uses the most strict and safest options. It should be used by
|
|
12
12
|
developers who find it difficult to understand the options available in Oj.
|
|
13
13
|
|
|
14
|
-
The options in Oj are designed to provide flexibility to the developer. This
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
The options in Oj are designed to provide flexibility to the developer. This flexibility allows Objects to be serialized and deserialized. An Object is deserialized by allocating it without calling its initializer and then setting its instance variables. A few methods are called on what that builds: `exception` and `set_backtrace` on an `Exception`, and `replace` on a subclass of `Hash`, `Array` or `String` for a `self` key. As in any system, check your inputs before working with them. Taking an arbitrary `String` from a user and evaluating it is never a good idea from an unsecure source. The same is true for `Object` attributes as they are not more than `String`s. Always check inputs from untrusted sources.
|
|
15
|
+
|
|
16
|
+
## The mode a document is loaded in
|
|
17
|
+
|
|
18
|
+
`Oj.load()` uses the `:object` mode unless the mode is changed. That mode takes the class of an Object from the document, so the document decides which of the classes already loaded in the process is allocated and what its instance variables are. Classes are looked up and not created unless `:auto_define` is turned on.
|
|
19
|
+
|
|
20
|
+
For a document from an untrusted source, ask for a mode that does not do that:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
Oj.load(json, mode: :strict)
|
|
24
|
+
Oj.strict_load(json)
|
|
25
|
+
Oj.safe_load(json)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
or set it for the process:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
Oj.default_options = {mode: :strict}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`Oj.object_load()` is the explicit form of the current default and stays in `:object` mode whatever the default is set to.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oj
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.17.
|
|
4
|
+
version: 3.17.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Ohler
|
|
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
231
231
|
- !ruby/object:Gem::Version
|
|
232
232
|
version: '0'
|
|
233
233
|
requirements: []
|
|
234
|
-
rubygems_version: 4.0.
|
|
234
|
+
rubygems_version: 4.0.17
|
|
235
235
|
specification_version: 4
|
|
236
236
|
summary: A fast JSON parser and serializer.
|
|
237
237
|
test_files: []
|