oj 3.6.0 → 3.6.2
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 +5 -5
- data/ext/oj/dump.c +2 -2
- data/ext/oj/dump.h +1 -1
- data/ext/oj/dump_strict.c +0 -3
- data/ext/oj/rails.c +68 -55
- data/lib/oj/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0f7d6dbca5f0271c4a6e2296c56881940e85b4b
|
4
|
+
data.tar.gz: 879796b3fdfee0aa99c3a8913a13bd6047e7f957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c919d3e606b41de048d2d150834e6b795494ef6b9d9c80676c217e773e23126a928638dccbf96bb372c4e473997c1811ebc46ab3189b323a1ff00abc5b8a73e4
|
7
|
+
data.tar.gz: 13114820906d6af519314be9dee39224f79071490b5ee23bbf7b1a7bb01d89725fd751f4c056f88f1f7e837457df49885f31f556ca03f25a2767bae0fa77eea0
|
data/ext/oj/dump.c
CHANGED
@@ -896,14 +896,14 @@ void
|
|
896
896
|
oj_grow_out(Out out, size_t len) {
|
897
897
|
size_t size = out->end - out->buf;
|
898
898
|
long pos = out->cur - out->buf;
|
899
|
-
char *buf;
|
899
|
+
char *buf = out->buf;
|
900
900
|
|
901
901
|
size *= 2;
|
902
902
|
if (size <= len * 2 + pos) {
|
903
903
|
size += len;
|
904
904
|
}
|
905
905
|
if (out->allocated) {
|
906
|
-
|
906
|
+
REALLOC_N(buf, char, (size + BUFFER_EXTRA));
|
907
907
|
} else {
|
908
908
|
buf = ALLOC_N(char, (size + BUFFER_EXTRA));
|
909
909
|
out->allocated = true;
|
data/ext/oj/dump.h
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
#define MAX_DEPTH 1000
|
14
14
|
|
15
15
|
// Extra padding at end of buffer.
|
16
|
-
#define BUFFER_EXTRA
|
16
|
+
#define BUFFER_EXTRA 64
|
17
17
|
|
18
18
|
extern void oj_dump_nil(VALUE obj, int depth, Out out, bool as_ok);
|
19
19
|
extern void oj_dump_true(VALUE obj, int depth, Out out, bool as_ok);
|
data/ext/oj/dump_strict.c
CHANGED
@@ -21,9 +21,6 @@
|
|
21
21
|
// Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
|
22
22
|
#define OJ_INFINITY (1.0/0.0)
|
23
23
|
|
24
|
-
// Extra padding at end of buffer.
|
25
|
-
#define BUFFER_EXTRA 10
|
26
|
-
|
27
24
|
typedef unsigned long ulong;
|
28
25
|
|
29
26
|
static const char inf_val[] = INF_VAL;
|
data/ext/oj/rails.c
CHANGED
@@ -319,11 +319,13 @@ dump_time(VALUE obj, int depth, Out out, bool as_ok) {
|
|
319
319
|
static void
|
320
320
|
dump_timewithzone(VALUE obj, int depth, Out out, bool as_ok) {
|
321
321
|
time_t sec = NUM2LONG(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
322
|
+
long long nsec = 0;
|
323
|
+
|
324
|
+
if (rb_respond_to(obj, oj_tv_nsec_id)) {
|
325
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
326
|
+
} else if (rb_respond_to(obj, oj_tv_usec_id)) {
|
327
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
|
328
|
+
}
|
327
329
|
dump_sec_nano(obj, sec, nsec, out);
|
328
330
|
}
|
329
331
|
|
@@ -502,13 +504,70 @@ typedef struct _NamedFunc {
|
|
502
504
|
DumpFunc func;
|
503
505
|
} *NamedFunc;
|
504
506
|
|
507
|
+
static void
|
508
|
+
dump_as_string(VALUE obj, int depth, Out out, bool as_ok) {
|
509
|
+
if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
|
510
|
+
out->argc = 0;
|
511
|
+
return;
|
512
|
+
}
|
513
|
+
oj_dump_obj_to_s(obj, out);
|
514
|
+
}
|
515
|
+
|
516
|
+
static void
|
517
|
+
dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
|
518
|
+
volatile VALUE ja;
|
519
|
+
|
520
|
+
if (Yes == out->opts->trace) {
|
521
|
+
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
522
|
+
}
|
523
|
+
// Some classes elect to not take an options argument so check the arity
|
524
|
+
// of as_json.
|
525
|
+
#if HAS_METHOD_ARITY
|
526
|
+
if (0 == rb_obj_method_arity(obj, oj_as_json_id)) {
|
527
|
+
ja = rb_funcall(obj, oj_as_json_id, 0);
|
528
|
+
} else {
|
529
|
+
ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
|
530
|
+
}
|
531
|
+
#else
|
532
|
+
ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
|
533
|
+
#endif
|
534
|
+
if (Yes == out->opts->trace) {
|
535
|
+
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
536
|
+
}
|
537
|
+
|
538
|
+
out->argc = 0;
|
539
|
+
if (ja == obj || !as_ok) {
|
540
|
+
// Once as_json is called it should never be called again on the same
|
541
|
+
// object with as_ok.
|
542
|
+
dump_rails_val(ja, depth, out, false);
|
543
|
+
} else {
|
544
|
+
int type = rb_type(ja);
|
545
|
+
|
546
|
+
if (T_HASH == type || T_ARRAY == type) {
|
547
|
+
dump_rails_val(ja, depth, out, true);
|
548
|
+
} else {
|
549
|
+
dump_rails_val(ja, depth, out, true);
|
550
|
+
}
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
static void
|
555
|
+
dump_regexp(VALUE obj, int depth, Out out, bool as_ok) {
|
556
|
+
if (as_ok && rb_respond_to(obj, oj_as_json_id)) {
|
557
|
+
dump_as_json(obj, depth, out, false);
|
558
|
+
return;
|
559
|
+
}
|
560
|
+
dump_as_string(obj, depth, out, as_ok);
|
561
|
+
}
|
562
|
+
|
505
563
|
static struct _NamedFunc dump_map[] = {
|
506
564
|
{ "ActionController::Parameters", dump_actioncontroller_parameters },
|
507
565
|
{ "ActiveRecord::Result", dump_activerecord_result },
|
508
566
|
{ "ActiveSupport::TimeWithZone", dump_timewithzone },
|
509
567
|
{ "BigDecimal", dump_bigdecimal },
|
510
568
|
{ "Range", dump_to_s },
|
511
|
-
{ "Regexp",
|
569
|
+
{ "Regexp", dump_regexp },
|
570
|
+
//{ "Regexp", dump_to_s },
|
512
571
|
{ "Time", dump_time },
|
513
572
|
{ NULL, NULL },
|
514
573
|
};
|
@@ -1117,44 +1176,6 @@ oj_mimic_rails_init() {
|
|
1117
1176
|
rb_define_method(encoder_class, "optimized?", encoder_optimized, 1);
|
1118
1177
|
}
|
1119
1178
|
|
1120
|
-
static void
|
1121
|
-
dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
|
1122
|
-
volatile VALUE ja;
|
1123
|
-
|
1124
|
-
if (Yes == out->opts->trace) {
|
1125
|
-
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
1126
|
-
}
|
1127
|
-
// Some classes elect to not take an options argument so check the arity
|
1128
|
-
// of as_json.
|
1129
|
-
#if HAS_METHOD_ARITY
|
1130
|
-
if (0 == rb_obj_method_arity(obj, oj_as_json_id)) {
|
1131
|
-
ja = rb_funcall(obj, oj_as_json_id, 0);
|
1132
|
-
} else {
|
1133
|
-
ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
|
1134
|
-
}
|
1135
|
-
#else
|
1136
|
-
ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
|
1137
|
-
#endif
|
1138
|
-
if (Yes == out->opts->trace) {
|
1139
|
-
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
1140
|
-
}
|
1141
|
-
|
1142
|
-
out->argc = 0;
|
1143
|
-
if (ja == obj || !as_ok) {
|
1144
|
-
// Once as_json is call it should never be called again on the same
|
1145
|
-
// object with as_ok.
|
1146
|
-
dump_rails_val(ja, depth, out, false);
|
1147
|
-
} else {
|
1148
|
-
int type = rb_type(ja);
|
1149
|
-
|
1150
|
-
if (T_HASH == type || T_ARRAY == type) {
|
1151
|
-
dump_rails_val(ja, depth, out, true);
|
1152
|
-
} else {
|
1153
|
-
dump_rails_val(ja, depth, out, true);
|
1154
|
-
}
|
1155
|
-
}
|
1156
|
-
}
|
1157
|
-
|
1158
1179
|
static void
|
1159
1180
|
dump_to_hash(VALUE obj, int depth, Out out) {
|
1160
1181
|
dump_rails_val(rb_funcall(obj, oj_to_hash_id, 0), depth, out, true);
|
@@ -1388,7 +1409,7 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1388
1409
|
}
|
1389
1410
|
if (as_ok) {
|
1390
1411
|
ROpt ro;
|
1391
|
-
|
1412
|
+
|
1392
1413
|
if (NULL != (ro = oj_rails_get_opt(out->ropts, rb_obj_class(obj))) && ro->on) {
|
1393
1414
|
ro->dump(obj, depth, out, as_ok);
|
1394
1415
|
} else if (rb_respond_to(obj, oj_as_json_id)) {
|
@@ -1406,15 +1427,6 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1406
1427
|
}
|
1407
1428
|
}
|
1408
1429
|
|
1409
|
-
static void
|
1410
|
-
dump_as_string(VALUE obj, int depth, Out out, bool as_ok) {
|
1411
|
-
if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
|
1412
|
-
out->argc = 0;
|
1413
|
-
return;
|
1414
|
-
}
|
1415
|
-
oj_dump_obj_to_s(obj, out);
|
1416
|
-
}
|
1417
|
-
|
1418
1430
|
static DumpFunc rails_funcs[] = {
|
1419
1431
|
NULL, // RUBY_T_NONE = 0x00,
|
1420
1432
|
dump_obj, // RUBY_T_OBJECT = 0x01,
|
@@ -1422,7 +1434,8 @@ static DumpFunc rails_funcs[] = {
|
|
1422
1434
|
oj_dump_class, // RUBY_T_MODULE = 0x03,
|
1423
1435
|
dump_float, // RUBY_T_FLOAT = 0x04,
|
1424
1436
|
oj_dump_str, // RUBY_T_STRING = 0x05,
|
1425
|
-
|
1437
|
+
dump_regexp, // RUBY_T_REGEXP = 0x06,
|
1438
|
+
//dump_as_string, // RUBY_T_REGEXP = 0x06,
|
1426
1439
|
dump_array, // RUBY_T_ARRAY = 0x07,
|
1427
1440
|
dump_hash, // RUBY_T_HASH = 0x08,
|
1428
1441
|
dump_obj, // RUBY_T_STRUCT = 0x09,
|
data/lib/oj/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
270
|
version: '0'
|
271
271
|
requirements: []
|
272
272
|
rubyforge_project:
|
273
|
-
rubygems_version: 2.
|
273
|
+
rubygems_version: 2.5.1
|
274
274
|
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: A fast JSON parser and serializer.
|