oj 2.11.2 → 2.11.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oj might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +2 -10
- data/ext/oj/dump.c +5 -2
- data/ext/oj/extconf.rb +1 -0
- data/ext/oj/odd.c +33 -2
- data/ext/oj/odd.h +3 -0
- data/lib/oj/version.rb +1 -1
- data/test/test_object.rb +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92a7b7be45175f18661ed207bb79b4a03192c731
|
4
|
+
data.tar.gz: 2c2f13ed34b8d715265c4e9a5a53ee203ed042c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f195c7904b2c9de392d93e097155dbd32e028a8d0d4bf1640782e16e25aee11dbeaa73c35d1cc472804e378aeab801961c095a0501f1c6c1d976855e89ebfb0
|
7
|
+
data.tar.gz: ce8fadea6f3f07de21144e16f0b2b1aabeb108debbc34ee6b2b7adb22e9eaca18824b9e354dcf04c1affcd0a2610886ecd3a87b4c4dd0c42557e999f5a914fc8
|
data/README.md
CHANGED
@@ -26,17 +26,9 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
|
|
26
26
|
|
27
27
|
[![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
|
28
28
|
|
29
|
-
## Current Release 2.11.
|
29
|
+
## Current Release 2.11.3
|
30
30
|
|
31
|
-
-
|
32
|
-
the default 15.
|
33
|
-
|
34
|
-
- Fixed bug where a subclass of Array would be serialized as if in object mode
|
35
|
-
instead of compat when in compat mode.
|
36
|
-
|
37
|
-
### Release 2.11.1
|
38
|
-
|
39
|
-
- Changed the use_to_json option to still allow as_json even when set to false.
|
31
|
+
- DateTime encoding now includes nanoseconds.
|
40
32
|
|
41
33
|
[Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
|
42
34
|
|
data/ext/oj/dump.c
CHANGED
@@ -1713,6 +1713,7 @@ dump_struct_obj(VALUE obj, int depth, Out out) {
|
|
1713
1713
|
static void
|
1714
1714
|
dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
1715
1715
|
ID *idp;
|
1716
|
+
AttrGetFunc *fp;
|
1716
1717
|
volatile VALUE v;
|
1717
1718
|
const char *name;
|
1718
1719
|
size_t size;
|
@@ -1740,7 +1741,7 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
1740
1741
|
*out->cur++ = ',';
|
1741
1742
|
}
|
1742
1743
|
size = d2 * out->indent + 1;
|
1743
|
-
for (idp = odd->attrs; 0 != *idp; idp++) {
|
1744
|
+
for (idp = odd->attrs, fp = odd->attrFuncs; 0 != *idp; idp++, fp++) {
|
1744
1745
|
size_t nlen;
|
1745
1746
|
|
1746
1747
|
if (out->end - out->cur <= (long)size) {
|
@@ -1748,7 +1749,9 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
1748
1749
|
}
|
1749
1750
|
name = rb_id2name(*idp);
|
1750
1751
|
nlen = strlen(name);
|
1751
|
-
if (0
|
1752
|
+
if (0 != *fp) {
|
1753
|
+
v = (*fp)(obj);
|
1754
|
+
} else if (0 == strchr(name, '.')) {
|
1752
1755
|
v = rb_funcall(obj, *idp, 0);
|
1753
1756
|
} else {
|
1754
1757
|
char nbuf[256];
|
data/ext/oj/extconf.rb
CHANGED
@@ -32,6 +32,7 @@ dflags = {
|
|
32
32
|
'IS_WINDOWS' => is_windows ? 1 : 0,
|
33
33
|
'USE_PTHREAD_MUTEX' => is_windows ? 0 : 1,
|
34
34
|
'USE_RB_MUTEX' => (is_windows && !('1' == version[0] && '8' == version[1])) ? 1 : 0,
|
35
|
+
'DATETIME_1_8' => ('ruby' == type && ('1' == version[0] && '8' == version[1])) ? 1 : 0,
|
35
36
|
}
|
36
37
|
# This is a monster hack to get around issues with 1.9.3-p0 on CentOS 5.4. SO
|
37
38
|
# some reason math.h and string.h contents are not processed. Might be a
|
data/ext/oj/odd.c
CHANGED
@@ -35,6 +35,10 @@
|
|
35
35
|
static struct _Odd _odds[4]; // bump up if new initial Odd classes are added
|
36
36
|
static struct _Odd *odds = _odds;
|
37
37
|
static long odd_cnt = 0;
|
38
|
+
static ID sec_id;
|
39
|
+
static ID sec_fraction_id;
|
40
|
+
static ID to_f_id;
|
41
|
+
static ID rational_id;
|
38
42
|
|
39
43
|
static void
|
40
44
|
set_class(Odd odd, const char *classname) {
|
@@ -52,11 +56,35 @@ set_class(Odd odd, const char *classname) {
|
|
52
56
|
*idp = 0;
|
53
57
|
}
|
54
58
|
|
59
|
+
static VALUE
|
60
|
+
get_datetime_secs(VALUE obj) {
|
61
|
+
VALUE rsecs = rb_funcall(obj, sec_id, 0);
|
62
|
+
VALUE rfrac = rb_funcall(obj, sec_fraction_id, 0);
|
63
|
+
double secs = NUM2DBL(rb_funcall(rfrac, to_f_id, 0));
|
64
|
+
|
65
|
+
#if DATETIME_1_8
|
66
|
+
secs *= 86400.0;
|
67
|
+
#endif
|
68
|
+
secs += NUM2DBL(rb_funcall(rsecs, to_f_id, 0));
|
69
|
+
|
70
|
+
#if DATETIME_1_8
|
71
|
+
return rb_funcall(rb_cObject, rational_id, 2, LONG2FIX((long)(secs * 1000000000)), LONG2FIX(1000000000));
|
72
|
+
#else
|
73
|
+
return rb_float_new(secs);
|
74
|
+
#endif
|
75
|
+
}
|
76
|
+
|
55
77
|
void
|
56
78
|
oj_odd_init() {
|
57
79
|
Odd odd;
|
58
80
|
const char **np;
|
59
81
|
|
82
|
+
sec_id = rb_intern("sec");
|
83
|
+
sec_fraction_id = rb_intern("sec_fraction");
|
84
|
+
to_f_id = rb_intern("to_f");
|
85
|
+
rational_id = rb_intern("Rational");
|
86
|
+
|
87
|
+
memset(_odds, 0, sizeof(_odds));
|
60
88
|
odd = odds;
|
61
89
|
// Rational
|
62
90
|
np = odd->attr_names;
|
@@ -65,7 +93,7 @@ oj_odd_init() {
|
|
65
93
|
*np = 0;
|
66
94
|
set_class(odd, "Rational");
|
67
95
|
odd->create_obj = rb_cObject;
|
68
|
-
odd->create_op =
|
96
|
+
odd->create_op = rational_id;
|
69
97
|
odd->attr_cnt = 2;
|
70
98
|
// Date
|
71
99
|
odd++;
|
@@ -91,6 +119,7 @@ oj_odd_init() {
|
|
91
119
|
*np++ = 0;
|
92
120
|
set_class(odd, "DateTime");
|
93
121
|
odd->attr_cnt = 8;
|
122
|
+
odd->attrFuncs[5] = get_datetime_secs;
|
94
123
|
// Range
|
95
124
|
odd++;
|
96
125
|
np = odd->attr_names;
|
@@ -166,6 +195,7 @@ oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE
|
|
166
195
|
Odd odd;
|
167
196
|
const char **np;
|
168
197
|
ID *ap;
|
198
|
+
AttrGetFunc *fp;
|
169
199
|
|
170
200
|
if (_odds == odds) {
|
171
201
|
odds = ALLOC_N(struct _Odd, odd_cnt + 1);
|
@@ -181,7 +211,8 @@ oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE
|
|
181
211
|
odd->create_obj = create_object;
|
182
212
|
odd->create_op = SYM2ID(create_method);
|
183
213
|
odd->attr_cnt = mcnt;
|
184
|
-
for (ap = odd->attrs, np = odd->attr_names; 0 < mcnt; mcnt--, ap++, np++, members++) {
|
214
|
+
for (ap = odd->attrs, np = odd->attr_names, fp = odd->attrFuncs; 0 < mcnt; mcnt--, ap++, np++, members++, fp++) {
|
215
|
+
*fp = 0;
|
185
216
|
switch (rb_type(*members)) {
|
186
217
|
case T_STRING:
|
187
218
|
*np = strdup(rb_string_value_ptr(members));
|
data/ext/oj/odd.h
CHANGED
@@ -35,6 +35,8 @@
|
|
35
35
|
|
36
36
|
#define MAX_ODD_ARGS 10
|
37
37
|
|
38
|
+
typedef VALUE (*AttrGetFunc)(VALUE obj);
|
39
|
+
|
38
40
|
typedef struct _Odd {
|
39
41
|
const char *classname;
|
40
42
|
size_t clen;
|
@@ -44,6 +46,7 @@ typedef struct _Odd {
|
|
44
46
|
int attr_cnt;
|
45
47
|
const char *attr_names[MAX_ODD_ARGS]; // 0 terminated attr IDs
|
46
48
|
ID attrs[MAX_ODD_ARGS]; // 0 terminated attr IDs
|
49
|
+
AttrGetFunc attrFuncs[MAX_ODD_ARGS];
|
47
50
|
} *Odd;
|
48
51
|
|
49
52
|
typedef struct _OddArgs {
|
data/lib/oj/version.rb
CHANGED
data/test/test_object.rb
CHANGED
@@ -473,6 +473,10 @@ class ObjectJuice < Minitest::Test
|
|
473
473
|
dump_and_load(Date.new(2012, 6, 19), false)
|
474
474
|
end
|
475
475
|
|
476
|
+
def test_odd_datetime
|
477
|
+
dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(7123456789, 1000000000)), false)
|
478
|
+
end
|
479
|
+
|
476
480
|
def test_odd_string
|
477
481
|
Oj.register_odd(Strung, Strung, :create, :to_s, 'safe?')
|
478
482
|
s = Strung.new("Pete", true)
|
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: 2.11.
|
4
|
+
version: 2.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -179,8 +179,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
requirements: []
|
181
181
|
rubyforge_project: oj
|
182
|
-
rubygems_version: 2.
|
182
|
+
rubygems_version: 2.2.2
|
183
183
|
signing_key:
|
184
184
|
specification_version: 4
|
185
185
|
summary: A fast JSON parser and serializer.
|
186
186
|
test_files: []
|
187
|
+
has_rdoc: true
|