oj 3.8.0 → 3.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/custom.c +59 -36
- data/ext/oj/extconf.rb +1 -0
- data/ext/oj/object.c +8 -5
- data/ext/oj/oj.c +3 -3
- data/ext/oj/oj.h +2 -2
- data/ext/oj/parse.c +4 -0
- data/ext/oj/rails.c +2 -0
- data/ext/oj/resolve.c +3 -3
- data/ext/oj/sparse.c +4 -0
- data/ext/oj/util.c +5 -5
- data/ext/oj/val_stack.c +9 -9
- data/ext/oj/val_stack.h +9 -9
- data/lib/oj/json.rb +1 -1
- data/lib/oj/version.rb +1 -1
- data/pages/Options.md +4 -0
- data/test/foo.rb +8 -154
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52a998aa9f2273e995d9ef52e26df3f8998aae1a98d7d088f6973cf8234a444f
|
4
|
+
data.tar.gz: 26647fb39df6d357074e5798bf263ca708a361cf910eba43c7c7a3d1ba905f51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dffec2bd8c447ca172aa4a647a719c1cc62eeedab91ea30b79943fa212e4b78a10b3e3ddfd69e873e632c3bdddce2d955d34aa106dfa7e4f43618ea842aa829
|
7
|
+
data.tar.gz: 5dd30d0dcaf87e9b57c16ad13f0e7654ab8b8b02d8b3709f20614025283101bc44cedf4470bb2bb887b41a280d2e4b131f77a26a65a8e79447771a6bc5cca42d
|
data/ext/oj/custom.c
CHANGED
@@ -32,6 +32,13 @@ dump_obj_str(VALUE obj, int depth, Out out) {
|
|
32
32
|
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
33
33
|
}
|
34
34
|
|
35
|
+
static void
|
36
|
+
dump_obj_as_str(VALUE obj, int depth, Out out) {
|
37
|
+
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
38
|
+
const char *str = rb_string_value_ptr((VALUE*)&rstr);
|
39
|
+
|
40
|
+
oj_dump_cstr(str, RSTRING_LEN(rstr), 0, 0, out);
|
41
|
+
}
|
35
42
|
|
36
43
|
static void
|
37
44
|
bigdecimal_dump(VALUE obj, int depth, Out out) {
|
@@ -57,19 +64,23 @@ static ID imag_id = 0;
|
|
57
64
|
|
58
65
|
static void
|
59
66
|
complex_dump(VALUE obj, int depth, Out out) {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
if (NULL != out->opts->create_id) {
|
68
|
+
struct _attr attrs[] = {
|
69
|
+
{ "real", 4, Qnil },
|
70
|
+
{ "imag", 4, Qnil },
|
71
|
+
{ NULL, 0, Qnil },
|
72
|
+
};
|
73
|
+
if (0 == real_id) {
|
74
|
+
real_id = rb_intern("real");
|
75
|
+
imag_id = rb_intern("imag");
|
76
|
+
}
|
77
|
+
attrs[0].value = rb_funcall(obj, real_id, 0);
|
78
|
+
attrs[1].value = rb_funcall(obj, imag_id, 0);
|
71
79
|
|
72
|
-
|
80
|
+
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
81
|
+
} else {
|
82
|
+
dump_obj_as_str(obj, depth, out);
|
83
|
+
}
|
73
84
|
}
|
74
85
|
|
75
86
|
static VALUE
|
@@ -193,17 +204,21 @@ openstruct_load(VALUE clas, VALUE args) {
|
|
193
204
|
|
194
205
|
static void
|
195
206
|
range_dump(VALUE obj, int depth, Out out) {
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
207
|
+
if (NULL != out->opts->create_id) {
|
208
|
+
struct _attr attrs[] = {
|
209
|
+
{ "begin", 5, Qnil },
|
210
|
+
{ "end", 3, Qnil },
|
211
|
+
{ "exclude", 7, Qnil },
|
212
|
+
{ NULL, 0, Qnil },
|
213
|
+
};
|
214
|
+
attrs[0].value = rb_funcall(obj, oj_begin_id, 0);
|
215
|
+
attrs[1].value = rb_funcall(obj, oj_end_id, 0);
|
216
|
+
attrs[2].value = rb_funcall(obj, oj_exclude_end_id, 0);
|
205
217
|
|
206
|
-
|
218
|
+
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
219
|
+
} else {
|
220
|
+
dump_obj_as_str(obj, depth, out);
|
221
|
+
}
|
207
222
|
}
|
208
223
|
|
209
224
|
static VALUE
|
@@ -222,19 +237,23 @@ static ID denominator_id = 0;
|
|
222
237
|
|
223
238
|
static void
|
224
239
|
rational_dump(VALUE obj, int depth, Out out) {
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
240
|
+
if (NULL != out->opts->create_id) {
|
241
|
+
struct _attr attrs[] = {
|
242
|
+
{ "numerator", 9, Qnil },
|
243
|
+
{ "denominator", 11, Qnil },
|
244
|
+
{ NULL, 0, Qnil },
|
245
|
+
};
|
246
|
+
if (0 == numerator_id) {
|
247
|
+
numerator_id = rb_intern("numerator");
|
248
|
+
denominator_id = rb_intern("denominator");
|
249
|
+
}
|
250
|
+
attrs[0].value = rb_funcall(obj, numerator_id, 0);
|
251
|
+
attrs[1].value = rb_funcall(obj, denominator_id, 0);
|
236
252
|
|
237
|
-
|
253
|
+
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
254
|
+
} else {
|
255
|
+
dump_obj_as_str(obj, depth, out);
|
256
|
+
}
|
238
257
|
}
|
239
258
|
|
240
259
|
static VALUE
|
@@ -874,7 +893,11 @@ dump_data(VALUE obj, int depth, Out out, bool as_ok) {
|
|
874
893
|
|
875
894
|
static void
|
876
895
|
dump_regexp(VALUE obj, int depth, Out out, bool as_ok) {
|
877
|
-
|
896
|
+
if (NULL != out->opts->create_id) {
|
897
|
+
dump_obj_str(obj, depth, out);
|
898
|
+
} else {
|
899
|
+
dump_obj_as_str(obj, depth, out);
|
900
|
+
}
|
878
901
|
}
|
879
902
|
|
880
903
|
static void
|
@@ -1046,7 +1069,7 @@ hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
|
1046
1069
|
oj_set_obj_ivar(parent, kval, rval);
|
1047
1070
|
break;
|
1048
1071
|
case T_HASH:
|
1049
|
-
if (4 == parent->klen && NULL != parent->key && rb_cTime == parent->clas && 0 == strncmp("time", parent->key, 4)) {
|
1072
|
+
if (4 == parent->klen && NULL != parent->key && rb_cTime == parent->clas && 0 != ni->div && 0 == strncmp("time", parent->key, 4)) {
|
1050
1073
|
int64_t nsec = ni->num * 1000000000LL / ni->div;
|
1051
1074
|
|
1052
1075
|
if (ni->neg) {
|
data/ext/oj/extconf.rb
CHANGED
data/ext/oj/object.c
CHANGED
@@ -276,7 +276,10 @@ hat_num(ParseInfo pi, Val parent, Val kval, NumInfo ni) {
|
|
276
276
|
if (2 == kval->klen) {
|
277
277
|
switch (kval->key[1]) {
|
278
278
|
case 't': // time as a float
|
279
|
-
{
|
279
|
+
if (0 == ni->div || 9 < ni->di) {
|
280
|
+
rb_raise(rb_eArgError, "Invalid time decimal representation.");
|
281
|
+
//parent->val = rb_time_nano_new(0, 0);
|
282
|
+
} else {
|
280
283
|
int64_t nsec = ni->num * 1000000000LL / ni->div;
|
281
284
|
|
282
285
|
if (ni->neg) {
|
@@ -407,7 +410,7 @@ oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
|
|
407
410
|
ID var_id;
|
408
411
|
ID *slot;
|
409
412
|
|
410
|
-
#
|
413
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
411
414
|
pthread_mutex_lock(&oj_cache_mutex);
|
412
415
|
#else
|
413
416
|
rb_mutex_lock(oj_cache_mutex);
|
@@ -441,7 +444,7 @@ oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
|
|
441
444
|
}
|
442
445
|
*slot = var_id;
|
443
446
|
}
|
444
|
-
#
|
447
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
445
448
|
pthread_mutex_unlock(&oj_cache_mutex);
|
446
449
|
#else
|
447
450
|
rb_mutex_unlock(oj_cache_mutex);
|
@@ -665,7 +668,7 @@ end_hash(ParseInfo pi) {
|
|
665
668
|
static void
|
666
669
|
array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
667
670
|
volatile VALUE rval = Qnil;
|
668
|
-
|
671
|
+
|
669
672
|
if (3 <= len && 0 != pi->circ_array) {
|
670
673
|
if ('i' == str[1]) {
|
671
674
|
long i = read_long(str + 2, len - 2);
|
@@ -694,7 +697,7 @@ array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
694
697
|
static void
|
695
698
|
array_append_num(ParseInfo pi, NumInfo ni) {
|
696
699
|
volatile VALUE rval = oj_num_as_value(ni);
|
697
|
-
|
700
|
+
|
698
701
|
rb_ary_push(stack_peek(&pi->stack)->val, rval);
|
699
702
|
if (Yes == pi->options.trace) {
|
700
703
|
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
data/ext/oj/oj.c
CHANGED
@@ -149,7 +149,7 @@ static VALUE xss_safe_sym;
|
|
149
149
|
|
150
150
|
rb_encoding *oj_utf8_encoding = 0;
|
151
151
|
|
152
|
-
#
|
152
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
153
153
|
pthread_mutex_t oj_cache_mutex;
|
154
154
|
#else
|
155
155
|
VALUE oj_cache_mutex = Qnil;
|
@@ -329,7 +329,7 @@ get_def_opts(VALUE self) {
|
|
329
329
|
case AutoDec:
|
330
330
|
default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
|
331
331
|
}
|
332
|
-
rb_hash_aset(opts, create_id_sym, (
|
332
|
+
rb_hash_aset(opts, create_id_sym, (NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
|
333
333
|
rb_hash_aset(opts, oj_space_sym, (0 == oj_default_options.dump_opts.after_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.after_sep));
|
334
334
|
rb_hash_aset(opts, oj_space_before_sym, (0 == oj_default_options.dump_opts.before_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.before_sep));
|
335
335
|
rb_hash_aset(opts, oj_object_nl_sym, (0 == oj_default_options.dump_opts.hash_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.hash_nl));
|
@@ -1692,7 +1692,7 @@ Init_oj() {
|
|
1692
1692
|
oj_odd_init();
|
1693
1693
|
oj_mimic_rails_init();
|
1694
1694
|
|
1695
|
-
#
|
1695
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
1696
1696
|
if (0 != (err = pthread_mutex_init(&oj_cache_mutex, 0))) {
|
1697
1697
|
rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
|
1698
1698
|
}
|
data/ext/oj/oj.h
CHANGED
@@ -21,7 +21,7 @@ extern "C" {
|
|
21
21
|
#include <stdint.h>
|
22
22
|
#include <stdbool.h>
|
23
23
|
|
24
|
-
#
|
24
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
25
25
|
#include <pthread.h>
|
26
26
|
#endif
|
27
27
|
#include "cache8.h"
|
@@ -370,7 +370,7 @@ extern bool oj_use_hash_alt;
|
|
370
370
|
extern bool oj_use_array_alt;
|
371
371
|
extern bool string_writer_optimized;
|
372
372
|
|
373
|
-
#
|
373
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
374
374
|
extern pthread_mutex_t oj_cache_mutex;
|
375
375
|
#else
|
376
376
|
extern VALUE oj_cache_mutex;
|
data/ext/oj/parse.c
CHANGED
@@ -1049,6 +1049,10 @@ CLEANUP:
|
|
1049
1049
|
msg = rb_str_append(msg, oj_encode(rb_str_new2(pi->json)));
|
1050
1050
|
}
|
1051
1051
|
args[0] = msg;
|
1052
|
+
if (pi->err.clas == oj_parse_error_class) {
|
1053
|
+
// The error was an Oj::ParseError so change to a JSON::ParseError.
|
1054
|
+
pi->err.clas = oj_json_parser_error_class;
|
1055
|
+
}
|
1052
1056
|
rb_exc_raise(rb_class_new_instance(1, args, pi->err.clas));
|
1053
1057
|
} else {
|
1054
1058
|
oj_err_raise(&pi->err);
|
data/ext/oj/rails.c
CHANGED
@@ -1071,6 +1071,8 @@ rails_set_encoder(VALUE self) {
|
|
1071
1071
|
rb_undef_method(encoding, "use_standard_json_time_format=");
|
1072
1072
|
rb_define_module_function(encoding, "use_standard_json_time_format=", rails_use_standard_json_time_format, 1);
|
1073
1073
|
|
1074
|
+
pv = rb_iv_get(encoding, "@escape_html_entities_in_json");
|
1075
|
+
escape_html = Qtrue == pv;
|
1074
1076
|
rb_undef_method(encoding, "escape_html_entities_in_json=");
|
1075
1077
|
rb_define_module_function(encoding, "escape_html_entities_in_json=", rails_escape_html_entities_in_json, 1);
|
1076
1078
|
|
data/ext/oj/resolve.c
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
#include <stdlib.h>
|
7
7
|
#include <stdio.h>
|
8
8
|
#include <string.h>
|
9
|
-
#
|
9
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
10
10
|
#include <pthread.h>
|
11
11
|
#endif
|
12
12
|
|
@@ -75,7 +75,7 @@ oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE
|
|
75
75
|
if (No == pi->options.class_cache) {
|
76
76
|
return resolve_classpath(pi, name, len, auto_define, error_class);
|
77
77
|
}
|
78
|
-
#
|
78
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
79
79
|
pthread_mutex_lock(&oj_cache_mutex);
|
80
80
|
#else
|
81
81
|
rb_mutex_lock(oj_cache_mutex);
|
@@ -85,7 +85,7 @@ oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE
|
|
85
85
|
*slot = clas;
|
86
86
|
}
|
87
87
|
}
|
88
|
-
#
|
88
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
89
89
|
pthread_mutex_unlock(&oj_cache_mutex);
|
90
90
|
#else
|
91
91
|
rb_mutex_unlock(oj_cache_mutex);
|
data/ext/oj/sparse.c
CHANGED
@@ -898,6 +898,10 @@ CLEANUP:
|
|
898
898
|
// idea.
|
899
899
|
VALUE args[] = { oj_encode(rb_str_new2(pi->err.msg)) };
|
900
900
|
|
901
|
+
if (pi->err.clas == oj_parse_error_class) {
|
902
|
+
// The error was an Oj::ParseError so change to a JSON::ParseError.
|
903
|
+
pi->err.clas = oj_json_parser_error_class;
|
904
|
+
}
|
901
905
|
rb_exc_raise(rb_class_new_instance(1, args, pi->err.clas));
|
902
906
|
} else {
|
903
907
|
oj_err_raise(&pi->err);
|
data/ext/oj/util.c
CHANGED
@@ -110,7 +110,7 @@ sec_as_time(int64_t secs, TimeInfo ti) {
|
|
110
110
|
}
|
111
111
|
}
|
112
112
|
}
|
113
|
-
ti->year = (qc - shift) * 400 + c * 100 + qy * 4 + y;
|
113
|
+
ti->year = (int)((qc - (int64_t)shift) * 400 + c * 100 + qy * 4 + y);
|
114
114
|
if (leap) {
|
115
115
|
ms = eom_leap_secs;
|
116
116
|
} else {
|
@@ -125,12 +125,12 @@ sec_as_time(int64_t secs, TimeInfo ti) {
|
|
125
125
|
break;
|
126
126
|
}
|
127
127
|
}
|
128
|
-
ti->day = secs / 86400LL;
|
128
|
+
ti->day = (int)(secs / 86400LL);
|
129
129
|
secs = secs - (int64_t)ti->day * 86400LL;
|
130
130
|
ti->day++;
|
131
|
-
ti->hour = secs / 3600LL;
|
131
|
+
ti->hour = (int)(secs / 3600LL);
|
132
132
|
secs = secs - (int64_t)ti->hour * 3600LL;
|
133
|
-
ti->min = secs / 60LL;
|
133
|
+
ti->min = (int)(secs / 60LL);
|
134
134
|
secs = secs - (int64_t)ti->min * 60LL;
|
135
|
-
ti->sec = secs;
|
135
|
+
ti->sec = (int)secs;
|
136
136
|
}
|
data/ext/oj/val_stack.c
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
/* val_stack.c
|
2
2
|
* Copyright (c) 2011, Peter Ohler
|
3
3
|
* All rights reserved.
|
4
|
-
*
|
4
|
+
*
|
5
5
|
* Redistribution and use in source and binary forms, with or without
|
6
6
|
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* - Redistributions of source code must retain the above copyright notice, this
|
9
9
|
* list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
12
|
* this list of conditions and the following disclaimer in the documentation
|
13
13
|
* and/or other materials provided with the distribution.
|
14
|
-
*
|
14
|
+
*
|
15
15
|
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
16
|
* used to endorse or promote products derived from this software without
|
17
17
|
* specific prior written permission.
|
18
|
-
*
|
18
|
+
*
|
19
19
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
20
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
21
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -42,7 +42,7 @@ mark(void *ptr) {
|
|
42
42
|
if (0 == ptr) {
|
43
43
|
return;
|
44
44
|
}
|
45
|
-
#
|
45
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
46
46
|
pthread_mutex_lock(&stack->mutex);
|
47
47
|
#else
|
48
48
|
rb_mutex_lock(stack->mutex);
|
@@ -66,7 +66,7 @@ mark(void *ptr) {
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
}
|
69
|
-
#
|
69
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
70
70
|
pthread_mutex_unlock(&stack->mutex);
|
71
71
|
#else
|
72
72
|
rb_mutex_unlock(stack->mutex);
|
@@ -75,9 +75,9 @@ mark(void *ptr) {
|
|
75
75
|
|
76
76
|
VALUE
|
77
77
|
oj_stack_init(ValStack stack) {
|
78
|
-
#
|
78
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
79
79
|
int err;
|
80
|
-
|
80
|
+
|
81
81
|
if (0 != (err = pthread_mutex_init(&stack->mutex, 0))) {
|
82
82
|
rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
|
83
83
|
}
|
data/ext/oj/val_stack.h
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
/* val_stack.h
|
2
2
|
* Copyright (c) 2011, Peter Ohler
|
3
3
|
* All rights reserved.
|
4
|
-
*
|
4
|
+
*
|
5
5
|
* Redistribution and use in source and binary forms, with or without
|
6
6
|
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* - Redistributions of source code must retain the above copyright notice, this
|
9
9
|
* list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
12
|
* this list of conditions and the following disclaimer in the documentation
|
13
13
|
* and/or other materials provided with the distribution.
|
14
|
-
*
|
14
|
+
*
|
15
15
|
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
16
|
* used to endorse or promote products derived from this software without
|
17
17
|
* specific prior written permission.
|
18
|
-
*
|
18
|
+
*
|
19
19
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
20
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
21
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -34,7 +34,7 @@
|
|
34
34
|
#include "ruby.h"
|
35
35
|
#include "odd.h"
|
36
36
|
#include <stdint.h>
|
37
|
-
#
|
37
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
38
38
|
#include <pthread.h>
|
39
39
|
#endif
|
40
40
|
|
@@ -72,7 +72,7 @@ typedef struct _valStack {
|
|
72
72
|
Val head; // current stack
|
73
73
|
Val end; // stack end
|
74
74
|
Val tail; // pointer to one past last element name on stack
|
75
|
-
#
|
75
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
76
76
|
pthread_mutex_t mutex;
|
77
77
|
#else
|
78
78
|
VALUE mutex;
|
@@ -110,7 +110,7 @@ stack_push(ValStack stack, VALUE val, ValNext next) {
|
|
110
110
|
} else {
|
111
111
|
REALLOC_N(head, struct _val, len + STACK_INC);
|
112
112
|
}
|
113
|
-
#
|
113
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
114
114
|
pthread_mutex_lock(&stack->mutex);
|
115
115
|
#else
|
116
116
|
rb_mutex_lock(stack->mutex);
|
@@ -118,7 +118,7 @@ stack_push(ValStack stack, VALUE val, ValNext next) {
|
|
118
118
|
stack->head = head;
|
119
119
|
stack->tail = stack->head + toff;
|
120
120
|
stack->end = stack->head + len + STACK_INC;
|
121
|
-
#
|
121
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
122
122
|
pthread_mutex_unlock(&stack->mutex);
|
123
123
|
#else
|
124
124
|
rb_mutex_unlock(stack->mutex);
|
data/lib/oj/json.rb
CHANGED
data/lib/oj/version.rb
CHANGED
data/pages/Options.md
CHANGED
@@ -89,6 +89,10 @@ with the key.
|
|
89
89
|
The :create_id option specifies that key is used for dumping and loading when
|
90
90
|
specifying the class for an encoded object. The default is `json_create`.
|
91
91
|
|
92
|
+
In the `:custom` mode setting the `:create_id` to nil will cause Complex,
|
93
|
+
Rational, Range, and Regexp to be output as strings instead of as JSON
|
94
|
+
objects.
|
95
|
+
|
92
96
|
### :empty_string [Boolean]
|
93
97
|
|
94
98
|
If true an empty or all whitespace input will not raise an Exception. The
|
data/test/foo.rb
CHANGED
@@ -7,161 +7,15 @@ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
|
7
7
|
$: << File.join($oj_dir, dir)
|
8
8
|
end
|
9
9
|
|
10
|
-
#require 'json'
|
11
10
|
require 'oj'
|
11
|
+
require 'active_support'
|
12
|
+
require 'active_support/json'
|
13
|
+
#require 'tracer'
|
12
14
|
|
13
|
-
Oj.
|
15
|
+
Oj::Rails.set_encoder()
|
16
|
+
Oj::Rails.set_decoder()
|
17
|
+
Oj::Rails.optimize()
|
14
18
|
|
15
|
-
|
16
|
-
ab: {
|
17
|
-
cbbb: {
|
18
|
-
tilbeb: [
|
19
|
-
{
|
20
|
-
coob: {
|
21
|
-
uijwts: [
|
22
|
-
{
|
23
|
-
prrrrr: {
|
24
|
-
yakj: "pvebbx",
|
25
|
-
lbhqy: {
|
26
|
-
uhyw: {
|
27
|
-
uijwts: [
|
28
|
-
{
|
29
|
-
jangi: {
|
30
|
-
ubentg7haineued8atnr8w: {
|
31
|
-
abc: "uejdncbncnamnasdasdasdasd",
|
32
|
-
cde: "skfjskdfjskdfjsdkfjsdkfjs"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
},
|
41
|
-
{
|
42
|
-
kdncg: {
|
43
|
-
lvbnt8b9ounv: {
|
44
|
-
qk: 9
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
],
|
49
|
-
jenfjbhe: {}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
]
|
53
|
-
}
|
54
|
-
},
|
55
|
-
ijbh: {
|
56
|
-
jsnbrpbnunt: {
|
57
|
-
b88dibalbvp: {
|
58
|
-
mnbvd: "9uhbqlpiev"
|
59
|
-
}
|
60
|
-
},
|
61
|
-
ncnwkl: {
|
62
|
-
ksdfsf: {
|
63
|
-
mjln: "mnklkn"
|
64
|
-
},
|
65
|
-
kbrh: {
|
66
|
-
sdfn83nnalbmgnansdd: {
|
67
|
-
uijwts: {
|
68
|
-
ibha: {
|
69
|
-
uijwts: [
|
70
|
-
{
|
71
|
-
lnrbf: {
|
72
|
-
nbvtmqbhap9ebeb7btnnaw: {
|
73
|
-
ksb: "sdfksdfjsdfsb39242dnasddd",
|
74
|
-
mnm: "1293dsfnsdmfnsdfsd,fmnsd,"
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
]
|
79
|
-
}
|
80
|
-
},
|
81
|
-
kbrh: {
|
82
|
-
bo8libts: {
|
83
|
-
nag40n: {
|
84
|
-
kyen: "sdfasnc92nsn"
|
85
|
-
},
|
86
|
-
kbrh: {
|
87
|
-
nbwyu26snfcbajsdkj8: {
|
88
|
-
uijwts: {
|
89
|
-
mdfnkjsdd: {}
|
90
|
-
},
|
91
|
-
kbrh: {
|
92
|
-
kneahce: {
|
93
|
-
uijwts: {
|
94
|
-
kwnb: {
|
95
|
-
uijwts: [
|
96
|
-
{
|
97
|
-
fhfd: {
|
98
|
-
sfasdnfmasndfamsdnfajsmdf: false
|
99
|
-
}
|
100
|
-
}
|
101
|
-
],
|
102
|
-
asdfsdff: [
|
103
|
-
{
|
104
|
-
cwdf: {
|
105
|
-
sddlkfajsdkfjabskdfjalsdkfjansdkfjf: ""
|
106
|
-
}
|
107
|
-
},
|
108
|
-
{
|
109
|
-
bsdj: {
|
110
|
-
sdfsjdlfkasy8kljsfsdf83jlkjfals: true
|
111
|
-
}
|
112
|
-
}
|
113
|
-
]
|
114
|
-
}
|
115
|
-
},
|
116
|
-
kbrh: {
|
117
|
-
sdfsdfsddfk: {
|
118
|
-
uijwts: {
|
119
|
-
sdfsd: {
|
120
|
-
sdfsadf89mnlrrrqurqwvdnff: {
|
121
|
-
"kj": 8
|
122
|
-
}
|
123
|
-
}
|
124
|
-
},
|
125
|
-
kbrh: {
|
126
|
-
dkdjd: {
|
127
|
-
dfeteu: {
|
128
|
-
sdfd: "sdfasdfjlkjslrsdbb"
|
129
|
-
},
|
130
|
-
kbrh: {
|
131
|
-
sdfskjdfldk: {
|
132
|
-
buqpen: {
|
133
|
-
kjlkj: {
|
134
|
-
sdflskdjfalsdkrjalwkjfsrlfjasdf: {
|
135
|
-
sd: 0
|
136
|
-
}
|
137
|
-
}
|
138
|
-
},
|
139
|
-
kbrh: {
|
140
|
-
sdfksljdlfksdfl: {
|
141
|
-
sdfsdkfjssd: {
|
142
|
-
ksdjf: "sdflsdkfjasdkaufs;ldkfjsdlf",
|
143
|
-
sdfsdfsl: [5]
|
144
|
-
}
|
145
|
-
}
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
}
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
}
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
}
|
158
|
-
}
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
19
|
+
#Oj::mimic_JSON
|
164
20
|
|
165
|
-
|
166
|
-
JSON.pretty_generate(obj)
|
167
|
-
#JSON.generate(obj)
|
21
|
+
puts JSON.parse('{"a":1}', symbolize_names: 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: 3.
|
4
|
+
version: 3.9.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: 2019-
|
11
|
+
date: 2019-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|