oj 3.7.5 → 3.7.6
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/ext/oj/buf.h +4 -4
- data/ext/oj/cache8.c +3 -3
- data/ext/oj/cache8.h +4 -4
- data/ext/oj/circarray.c +1 -1
- data/ext/oj/circarray.h +4 -4
- data/ext/oj/code.h +6 -6
- data/ext/oj/compat.c +5 -5
- data/ext/oj/custom.c +15 -13
- data/ext/oj/dump.c +15 -5
- data/ext/oj/dump.h +3 -3
- data/ext/oj/dump_compat.c +15 -11
- data/ext/oj/dump_leaf.c +1 -1
- data/ext/oj/dump_object.c +4 -2
- data/ext/oj/encode.h +3 -3
- data/ext/oj/err.c +1 -1
- data/ext/oj/err.h +5 -5
- data/ext/oj/fast.c +14 -14
- data/ext/oj/hash.c +7 -7
- data/ext/oj/hash.h +4 -4
- data/ext/oj/hash_test.c +2 -2
- data/ext/oj/mimic_json.c +9 -9
- data/ext/oj/object.c +3 -3
- data/ext/oj/odd.c +12 -8
- data/ext/oj/odd.h +5 -5
- data/ext/oj/oj.c +14 -12
- data/ext/oj/oj.h +23 -23
- data/ext/oj/parse.c +3 -3
- data/ext/oj/parse.h +26 -26
- data/ext/oj/rails.c +27 -23
- data/ext/oj/rails.h +3 -3
- data/ext/oj/reader.h +5 -5
- data/ext/oj/resolve.h +3 -3
- data/ext/oj/rxclass.c +5 -5
- data/ext/oj/rxclass.h +7 -7
- data/ext/oj/saj.c +2 -2
- data/ext/oj/scp.c +3 -3
- data/ext/oj/sparse.c +4 -4
- data/ext/oj/stream_writer.c +1 -1
- data/ext/oj/strict.c +6 -6
- data/ext/oj/string_writer.c +1 -1
- data/ext/oj/trace.h +8 -8
- data/ext/oj/val_stack.c +8 -2
- data/ext/oj/val_stack.h +9 -9
- data/ext/oj/wab.c +11 -7
- data/lib/oj/version.rb +1 -1
- data/test/bug.rb +51 -0
- data/test/bug2.rb +10 -0
- data/test/bug3.rb +46 -0
- data/test/bug_fast.rb +32 -0
- data/test/bug_load.rb +24 -0
- data/test/crash.rb +111 -0
- data/test/example.rb +11 -0
- data/test/foo.rb +4 -29
- data/test/io.rb +48 -0
- data/test/isolated/test_mimic_rails_datetime.rb +27 -0
- data/test/mem.rb +12 -27
- data/test/mod.rb +16 -0
- data/test/omit.rb +20 -0
- data/test/rails.rb +50 -0
- data/test/rails_datetime_test.rb +24 -0
- data/test/russian.rb +18 -0
- data/test/struct.rb +29 -0
- data/test/test_serializer.rb +59 -0
- data/test/write_timebars.rb +31 -0
- data/test/x_test.rb +185 -0
- metadata +102 -68
- data/test/big.rb +0 -15
data/ext/oj/dump_leaf.c
CHANGED
data/ext/oj/dump_object.c
CHANGED
@@ -423,7 +423,7 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
423
423
|
if (odd->raw) {
|
424
424
|
v = rb_funcall(obj, *odd->attrs, 0);
|
425
425
|
if (Qundef == v || T_STRING != rb_type(v)) {
|
426
|
-
rb_raise(rb_eEncodingError, "Invalid type for raw JSON
|
426
|
+
rb_raise(rb_eEncodingError, "Invalid type for raw JSON.");
|
427
427
|
} else {
|
428
428
|
const char *s = rb_string_value_ptr((VALUE*)&v);
|
429
429
|
int len = (int)RSTRING_LEN(v);
|
@@ -462,7 +462,9 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
462
462
|
ID i;
|
463
463
|
|
464
464
|
if (sizeof(nbuf) <= nlen) {
|
465
|
-
n2 = strdup(name)
|
465
|
+
if (NULL == (n2 = strdup(name))) {
|
466
|
+
rb_raise(rb_eNoMemError, "for attribute name.");
|
467
|
+
}
|
466
468
|
} else {
|
467
469
|
strcpy(n2, name);
|
468
470
|
}
|
data/ext/oj/encode.h
CHANGED
@@ -28,8 +28,8 @@
|
|
28
28
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
*/
|
30
30
|
|
31
|
-
#ifndef
|
32
|
-
#define
|
31
|
+
#ifndef OJ_ENCODE_H
|
32
|
+
#define OJ_ENCODE_H
|
33
33
|
|
34
34
|
#include "ruby.h"
|
35
35
|
#include "ruby/encoding.h"
|
@@ -40,4 +40,4 @@ oj_encode(VALUE rstr) {
|
|
40
40
|
return rstr;
|
41
41
|
}
|
42
42
|
|
43
|
-
#endif /*
|
43
|
+
#endif /* OJ_ENCODE_H */
|
data/ext/oj/err.c
CHANGED
@@ -40,7 +40,7 @@ _oj_err_set_with_location(Err err, VALUE eclas, const char *msg, const char *jso
|
|
40
40
|
|
41
41
|
void
|
42
42
|
_oj_raise_error(const char *msg, const char *json, const char *current, const char* file, int line) {
|
43
|
-
struct
|
43
|
+
struct _err err;
|
44
44
|
int n = 1;
|
45
45
|
int col = 1;
|
46
46
|
|
data/ext/oj/err.h
CHANGED
@@ -28,8 +28,8 @@
|
|
28
28
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
*/
|
30
30
|
|
31
|
-
#ifndef
|
32
|
-
#define
|
31
|
+
#ifndef OJ_ERR_H
|
32
|
+
#define OJ_ERR_H
|
33
33
|
|
34
34
|
#include "ruby.h"
|
35
35
|
// Needed to silence 2.4.0 warnings.
|
@@ -37,9 +37,9 @@
|
|
37
37
|
# define NORETURN(x) x
|
38
38
|
#endif
|
39
39
|
|
40
|
-
#define set_error(err, eclas, msg, json, current) _oj_err_set_with_location(err, eclas, msg, json, current,
|
40
|
+
#define set_error(err, eclas, msg, json, current) _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
|
41
41
|
|
42
|
-
typedef struct
|
42
|
+
typedef struct _err {
|
43
43
|
VALUE clas;
|
44
44
|
char msg[128];
|
45
45
|
} *Err;
|
@@ -67,4 +67,4 @@ err_has(Err e) {
|
|
67
67
|
return (Qnil != e->clas);
|
68
68
|
}
|
69
69
|
|
70
|
-
#endif /*
|
70
|
+
#endif /* OJ_ERR_H */
|
data/ext/oj/fast.c
CHANGED
@@ -43,16 +43,16 @@
|
|
43
43
|
// maximum to allocate on the stack, arbitrary limit
|
44
44
|
#define SMALL_XML 65536
|
45
45
|
#define MAX_STACK 100
|
46
|
-
//#define BATCH_SIZE (4096 / sizeof(struct
|
46
|
+
//#define BATCH_SIZE (4096 / sizeof(struct _leaf) - 1)
|
47
47
|
#define BATCH_SIZE 100
|
48
48
|
|
49
|
-
typedef struct
|
50
|
-
struct
|
49
|
+
typedef struct _batch {
|
50
|
+
struct _batch *next;
|
51
51
|
int next_avail;
|
52
|
-
struct
|
52
|
+
struct _leaf leaves[BATCH_SIZE];
|
53
53
|
} *Batch;
|
54
54
|
|
55
|
-
typedef struct
|
55
|
+
typedef struct _doc {
|
56
56
|
Leaf data;
|
57
57
|
Leaf *where; // points to current location
|
58
58
|
Leaf where_path[MAX_STACK]; // points to head of path
|
@@ -60,10 +60,10 @@ typedef struct _Doc {
|
|
60
60
|
unsigned long size; // number of leaves/branches in the doc
|
61
61
|
VALUE self;
|
62
62
|
Batch batches;
|
63
|
-
struct
|
63
|
+
struct _batch batch0;
|
64
64
|
} *Doc;
|
65
65
|
|
66
|
-
typedef struct
|
66
|
+
typedef struct _parseInfo {
|
67
67
|
char *str; /* buffer being read from */
|
68
68
|
char *s; /* current position in buffer */
|
69
69
|
Doc doc;
|
@@ -204,10 +204,10 @@ leaf_new(Doc doc, int type) {
|
|
204
204
|
Leaf leaf;
|
205
205
|
|
206
206
|
if (0 == doc->batches || BATCH_SIZE == doc->batches->next_avail) {
|
207
|
-
Batch b = ALLOC(struct
|
207
|
+
Batch b = ALLOC(struct _batch);
|
208
208
|
|
209
209
|
// Initializes all leaves with a NO_VAL value_type
|
210
|
-
memset(b, 0, sizeof(struct
|
210
|
+
memset(b, 0, sizeof(struct _batch));
|
211
211
|
b->next = doc->batches;
|
212
212
|
doc->batches = b;
|
213
213
|
b->next_avail = 0;
|
@@ -734,7 +734,7 @@ read_quoted_value(ParseInfo pi) {
|
|
734
734
|
// doc support functions
|
735
735
|
inline static void
|
736
736
|
doc_init(Doc doc) {
|
737
|
-
memset(doc, 0, sizeof(struct
|
737
|
+
memset(doc, 0, sizeof(struct _doc));
|
738
738
|
doc->where = doc->where_path;
|
739
739
|
doc->self = Qundef;
|
740
740
|
doc->batches = &doc->batch0;
|
@@ -813,16 +813,16 @@ mark_doc(void *ptr) {
|
|
813
813
|
|
814
814
|
static VALUE
|
815
815
|
parse_json(VALUE clas, char *json, bool given, bool allocated) {
|
816
|
-
struct
|
816
|
+
struct _parseInfo pi;
|
817
817
|
volatile VALUE result = Qnil;
|
818
818
|
Doc doc;
|
819
819
|
int ex = 0;
|
820
820
|
volatile VALUE self;
|
821
821
|
|
822
822
|
if (given) {
|
823
|
-
doc = ALLOCA_N(struct
|
823
|
+
doc = ALLOCA_N(struct _doc, 1);
|
824
824
|
} else {
|
825
|
-
doc = ALLOC(struct
|
825
|
+
doc = ALLOC(struct _doc);
|
826
826
|
}
|
827
827
|
/* skip UTF-8 BOM if present */
|
828
828
|
if (0xEF == (uint8_t)*json && 0xBB == (uint8_t)json[1] && 0xBF == (uint8_t)json[2]) {
|
@@ -1624,7 +1624,7 @@ doc_dump(int argc, VALUE *argv, VALUE self) {
|
|
1624
1624
|
|
1625
1625
|
if (0 == filename) {
|
1626
1626
|
char buf[4096];
|
1627
|
-
struct
|
1627
|
+
struct _out out;
|
1628
1628
|
|
1629
1629
|
out.buf = buf;
|
1630
1630
|
out.end = buf + sizeof(buf) - 10;
|
data/ext/oj/hash.c
CHANGED
@@ -34,19 +34,19 @@
|
|
34
34
|
#define HASH_MASK 0x000003FF
|
35
35
|
#define HASH_SLOT_CNT 1024
|
36
36
|
|
37
|
-
typedef struct
|
38
|
-
struct
|
37
|
+
typedef struct _keyVal {
|
38
|
+
struct _keyVal *next;
|
39
39
|
const char *key;
|
40
40
|
size_t len;
|
41
41
|
VALUE val;
|
42
42
|
} *KeyVal;
|
43
43
|
|
44
|
-
struct
|
45
|
-
struct
|
44
|
+
struct _hash {
|
45
|
+
struct _keyVal slots[HASH_SLOT_CNT];
|
46
46
|
};
|
47
47
|
|
48
|
-
struct
|
49
|
-
struct
|
48
|
+
struct _hash class_hash;
|
49
|
+
struct _hash intern_hash;
|
50
50
|
|
51
51
|
// almost the Murmur hash algorithm
|
52
52
|
#define M 0x5bd1e995
|
@@ -114,7 +114,7 @@ hash_get(Hash hash, const char *key, size_t len, VALUE **slotp, VALUE def_value)
|
|
114
114
|
}
|
115
115
|
if (0 != slotp) {
|
116
116
|
if (0 != bucket->key) {
|
117
|
-
KeyVal b = ALLOC(struct
|
117
|
+
KeyVal b = ALLOC(struct _keyVal);
|
118
118
|
|
119
119
|
b->next = 0;
|
120
120
|
bucket->next = b;
|
data/ext/oj/hash.h
CHANGED
@@ -28,12 +28,12 @@
|
|
28
28
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
*/
|
30
30
|
|
31
|
-
#ifndef
|
32
|
-
#define
|
31
|
+
#ifndef OJ_HASH_H
|
32
|
+
#define OJ_HASH_H
|
33
33
|
|
34
34
|
#include "ruby.h"
|
35
35
|
|
36
|
-
typedef struct
|
36
|
+
typedef struct _hash *Hash;
|
37
37
|
|
38
38
|
extern void oj_hash_init();
|
39
39
|
|
@@ -43,4 +43,4 @@ extern ID oj_attr_hash_get(const char *key, size_t len, ID **slotp);
|
|
43
43
|
extern void oj_hash_print();
|
44
44
|
extern char* oj_strndup(const char *s, size_t len);
|
45
45
|
|
46
|
-
#endif /*
|
46
|
+
#endif /* OJ_HASH_H */
|
data/ext/oj/hash_test.c
CHANGED
@@ -39,12 +39,12 @@
|
|
39
39
|
#define __STDC_FORMAT_MACROS
|
40
40
|
#include <inttypes.h>
|
41
41
|
|
42
|
-
typedef struct
|
42
|
+
typedef struct _strLen {
|
43
43
|
const char *str;
|
44
44
|
size_t len;
|
45
45
|
} *StrLen;
|
46
46
|
|
47
|
-
static struct
|
47
|
+
static struct _strLen data[] = {
|
48
48
|
{ "Gem::Version", 12 },
|
49
49
|
{ "TracePoint", 10 },
|
50
50
|
{ "Complex::compatible", 19 },
|
data/ext/oj/mimic_json.c
CHANGED
@@ -196,8 +196,8 @@ mimic_limit_arg(VALUE a) {
|
|
196
196
|
static VALUE
|
197
197
|
mimic_dump(int argc, VALUE *argv, VALUE self) {
|
198
198
|
char buf[4096];
|
199
|
-
struct
|
200
|
-
struct
|
199
|
+
struct _out out;
|
200
|
+
struct _options copts = oj_default_options;
|
201
201
|
VALUE rstr;
|
202
202
|
|
203
203
|
copts.str_rx.head = NULL;
|
@@ -354,7 +354,7 @@ mimic_dump_load(int argc, VALUE *argv, VALUE self) {
|
|
354
354
|
static VALUE
|
355
355
|
mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
356
356
|
char buf[4096];
|
357
|
-
struct
|
357
|
+
struct _out out;
|
358
358
|
VALUE rstr;
|
359
359
|
|
360
360
|
out.buf = buf;
|
@@ -414,7 +414,7 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
414
414
|
*/
|
415
415
|
VALUE
|
416
416
|
oj_mimic_generate(int argc, VALUE *argv, VALUE self) {
|
417
|
-
struct
|
417
|
+
struct _options copts = oj_default_options;
|
418
418
|
|
419
419
|
copts.str_rx.head = NULL;
|
420
420
|
copts.str_rx.tail = NULL;
|
@@ -432,7 +432,7 @@ oj_mimic_generate(int argc, VALUE *argv, VALUE self) {
|
|
432
432
|
*/
|
433
433
|
VALUE
|
434
434
|
oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
|
435
|
-
struct
|
435
|
+
struct _options copts = oj_default_options;
|
436
436
|
VALUE rargs[2];
|
437
437
|
volatile VALUE h;
|
438
438
|
|
@@ -481,7 +481,7 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
|
|
481
481
|
|
482
482
|
static VALUE
|
483
483
|
mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
484
|
-
struct
|
484
|
+
struct _parseInfo pi;
|
485
485
|
VALUE ropts;
|
486
486
|
VALUE args[1];
|
487
487
|
|
@@ -660,7 +660,7 @@ mimic_create_id(VALUE self) {
|
|
660
660
|
return rb_str_new_cstr(oj_json_class);
|
661
661
|
}
|
662
662
|
|
663
|
-
static struct
|
663
|
+
static struct _options mimic_object_to_json_options = {
|
664
664
|
0, // indent
|
665
665
|
No, // circular
|
666
666
|
No, // auto_define
|
@@ -717,9 +717,9 @@ static struct _Options mimic_object_to_json_options = {
|
|
717
717
|
static VALUE
|
718
718
|
mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
|
719
719
|
char buf[4096];
|
720
|
-
struct
|
720
|
+
struct _out out;
|
721
721
|
VALUE rstr;
|
722
|
-
struct
|
722
|
+
struct _options copts = oj_default_options;
|
723
723
|
|
724
724
|
copts.str_rx.head = NULL;
|
725
725
|
copts.str_rx.tail = NULL;
|
data/ext/oj/object.c
CHANGED
@@ -677,7 +677,7 @@ start_hash(ParseInfo pi) {
|
|
677
677
|
}
|
678
678
|
|
679
679
|
static void
|
680
|
-
end_hash(
|
680
|
+
end_hash(ParseInfo pi) {
|
681
681
|
Val parent = stack_peek(&pi->stack);
|
682
682
|
|
683
683
|
if (Qnil == parent->val) {
|
@@ -765,7 +765,7 @@ oj_set_object_callbacks(ParseInfo pi) {
|
|
765
765
|
|
766
766
|
VALUE
|
767
767
|
oj_object_parse(int argc, VALUE *argv, VALUE self) {
|
768
|
-
struct
|
768
|
+
struct _parseInfo pi;
|
769
769
|
|
770
770
|
parse_info_init(&pi);
|
771
771
|
pi.options = oj_default_options;
|
@@ -782,7 +782,7 @@ oj_object_parse(int argc, VALUE *argv, VALUE self) {
|
|
782
782
|
|
783
783
|
VALUE
|
784
784
|
oj_object_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
|
785
|
-
struct
|
785
|
+
struct _parseInfo pi;
|
786
786
|
|
787
787
|
parse_info_init(&pi);
|
788
788
|
pi.options = oj_default_options;
|
data/ext/oj/odd.c
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
|
8
8
|
#include "odd.h"
|
9
9
|
|
10
|
-
static struct
|
11
|
-
static struct
|
10
|
+
static struct _odd _odds[4]; // bump up if new initial Odd classes are added
|
11
|
+
static struct _odd *odds = _odds;
|
12
12
|
static long odd_cnt = 0;
|
13
13
|
static ID sec_id;
|
14
14
|
static ID sec_fraction_id;
|
@@ -152,7 +152,7 @@ oj_get_oddc(const char *classname, size_t len) {
|
|
152
152
|
|
153
153
|
OddArgs
|
154
154
|
oj_odd_alloc_args(Odd odd) {
|
155
|
-
OddArgs oa = ALLOC_N(struct
|
155
|
+
OddArgs oa = ALLOC_N(struct _oddArgs, 1);
|
156
156
|
VALUE *a;
|
157
157
|
int i;
|
158
158
|
|
@@ -191,15 +191,17 @@ oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE
|
|
191
191
|
AttrGetFunc *fp;
|
192
192
|
|
193
193
|
if (_odds == odds) {
|
194
|
-
odds = ALLOC_N(struct
|
194
|
+
odds = ALLOC_N(struct _odd, odd_cnt + 1);
|
195
195
|
|
196
|
-
memcpy(odds, _odds, sizeof(struct
|
196
|
+
memcpy(odds, _odds, sizeof(struct _odd) * odd_cnt);
|
197
197
|
} else {
|
198
|
-
REALLOC_N(odds, struct
|
198
|
+
REALLOC_N(odds, struct _odd, odd_cnt + 1);
|
199
199
|
}
|
200
200
|
odd = odds + odd_cnt;
|
201
201
|
odd->clas = clas;
|
202
|
-
odd->classname = strdup(rb_class2name(clas))
|
202
|
+
if (NULL == (odd->classname = strdup(rb_class2name(clas)))) {
|
203
|
+
rb_raise(rb_eNoMemError, "for attribute name.");
|
204
|
+
}
|
203
205
|
odd->clen = strlen(odd->classname);
|
204
206
|
odd->create_obj = create_object;
|
205
207
|
odd->create_op = SYM2ID(create_method);
|
@@ -210,7 +212,9 @@ oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE
|
|
210
212
|
*fp = 0;
|
211
213
|
switch (rb_type(*members)) {
|
212
214
|
case T_STRING:
|
213
|
-
*np = strdup(rb_string_value_ptr(members))
|
215
|
+
if (NULL == (*np = strdup(rb_string_value_ptr(members)))) {
|
216
|
+
rb_raise(rb_eNoMemError, "for attribute name.");
|
217
|
+
}
|
214
218
|
break;
|
215
219
|
case T_SYMBOL:
|
216
220
|
*np = rb_id2name(SYM2ID(*members));
|
data/ext/oj/odd.h
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
6
|
+
#ifndef OJ_ODD_H
|
7
|
+
#define OJ_ODD_H
|
8
8
|
|
9
9
|
#include <stdbool.h>
|
10
10
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
typedef VALUE (*AttrGetFunc)(VALUE obj);
|
16
16
|
|
17
|
-
typedef struct
|
17
|
+
typedef struct _odd {
|
18
18
|
const char *classname;
|
19
19
|
size_t clen;
|
20
20
|
VALUE clas; // Ruby class or module
|
@@ -28,7 +28,7 @@ typedef struct _Odd {
|
|
28
28
|
AttrGetFunc attrFuncs[MAX_ODD_ARGS];
|
29
29
|
} *Odd;
|
30
30
|
|
31
|
-
typedef struct
|
31
|
+
typedef struct _oddArgs {
|
32
32
|
Odd odd;
|
33
33
|
VALUE args[MAX_ODD_ARGS];
|
34
34
|
} *OddArgs;
|
@@ -41,4 +41,4 @@ extern void oj_odd_free(OddArgs args);
|
|
41
41
|
extern int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value);
|
42
42
|
extern void oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw);
|
43
43
|
|
44
|
-
#endif /*
|
44
|
+
#endif /* OJ_ODD_H */
|
data/ext/oj/oj.c
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
#include "rails.h"
|
20
20
|
#include "encode.h"
|
21
21
|
|
22
|
-
typedef struct
|
22
|
+
typedef struct _yesNoOpt {
|
23
23
|
VALUE sym;
|
24
24
|
char *attr;
|
25
25
|
} *YesNoOpt;
|
@@ -154,7 +154,7 @@ VALUE oj_cache_mutex = Qnil;
|
|
154
154
|
|
155
155
|
const char oj_json_class[] = "json_class";
|
156
156
|
|
157
|
-
struct
|
157
|
+
struct _options oj_default_options = {
|
158
158
|
0, // indent
|
159
159
|
No, // circular
|
160
160
|
No, // auto_define
|
@@ -401,7 +401,7 @@ set_def_opts(VALUE self, VALUE opts) {
|
|
401
401
|
|
402
402
|
void
|
403
403
|
oj_parse_options(VALUE ropts, Options copts) {
|
404
|
-
struct
|
404
|
+
struct _yesNoOpt ynos[] = {
|
405
405
|
{ circular_sym, &copts->circular },
|
406
406
|
{ auto_define_sym, &copts->auto_define },
|
407
407
|
{ symbol_keys_sym, &copts->sym_key },
|
@@ -901,7 +901,7 @@ load_file(int argc, VALUE *argv, VALUE self) {
|
|
901
901
|
char *path;
|
902
902
|
int fd;
|
903
903
|
Mode mode = oj_default_options.mode;
|
904
|
-
struct
|
904
|
+
struct _parseInfo pi;
|
905
905
|
|
906
906
|
if (1 > argc) {
|
907
907
|
rb_raise(rb_eArgError, "Wrong number of arguments to load().");
|
@@ -976,7 +976,7 @@ load_file(int argc, VALUE *argv, VALUE self) {
|
|
976
976
|
*/
|
977
977
|
static VALUE
|
978
978
|
safe_load(VALUE self, VALUE doc) {
|
979
|
-
struct
|
979
|
+
struct _parseInfo pi;
|
980
980
|
VALUE args[1];
|
981
981
|
|
982
982
|
parse_info_init(&pi);
|
@@ -1028,8 +1028,8 @@ safe_load(VALUE self, VALUE doc) {
|
|
1028
1028
|
static VALUE
|
1029
1029
|
dump(int argc, VALUE *argv, VALUE self) {
|
1030
1030
|
char buf[4096];
|
1031
|
-
struct
|
1032
|
-
struct
|
1031
|
+
struct _out out;
|
1032
|
+
struct _options copts = oj_default_options;
|
1033
1033
|
VALUE rstr;
|
1034
1034
|
|
1035
1035
|
if (1 > argc) {
|
@@ -1080,8 +1080,8 @@ dump(int argc, VALUE *argv, VALUE self) {
|
|
1080
1080
|
static VALUE
|
1081
1081
|
to_json(int argc, VALUE *argv, VALUE self) {
|
1082
1082
|
char buf[4096];
|
1083
|
-
struct
|
1084
|
-
struct
|
1083
|
+
struct _out out;
|
1084
|
+
struct _options copts = oj_default_options;
|
1085
1085
|
VALUE rstr;
|
1086
1086
|
|
1087
1087
|
if (1 > argc) {
|
@@ -1125,7 +1125,7 @@ to_json(int argc, VALUE *argv, VALUE self) {
|
|
1125
1125
|
*/
|
1126
1126
|
static VALUE
|
1127
1127
|
to_file(int argc, VALUE *argv, VALUE self) {
|
1128
|
-
struct
|
1128
|
+
struct _options copts = oj_default_options;
|
1129
1129
|
|
1130
1130
|
if (3 == argc) {
|
1131
1131
|
oj_parse_options(argv[2], &copts);
|
@@ -1148,7 +1148,7 @@ to_file(int argc, VALUE *argv, VALUE self) {
|
|
1148
1148
|
*/
|
1149
1149
|
static VALUE
|
1150
1150
|
to_stream(int argc, VALUE *argv, VALUE self) {
|
1151
|
-
struct
|
1151
|
+
struct _options copts = oj_default_options;
|
1152
1152
|
|
1153
1153
|
if (3 == argc) {
|
1154
1154
|
oj_parse_options(argv[2], &copts);
|
@@ -1699,7 +1699,9 @@ Init_oj() {
|
|
1699
1699
|
oj_mimic_rails_init();
|
1700
1700
|
|
1701
1701
|
#if HAVE_LIBPTHREAD
|
1702
|
-
pthread_mutex_init(&oj_cache_mutex, 0)
|
1702
|
+
if (0 != (err = pthread_mutex_init(&oj_cache_mutex, 0))) {
|
1703
|
+
rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
|
1704
|
+
}
|
1703
1705
|
#else
|
1704
1706
|
oj_cache_mutex = rb_mutex_new();
|
1705
1707
|
rb_gc_register_address(&oj_cache_mutex);
|