oj 3.12.3 → 3.13.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/ext/oj/buf.h +9 -0
- data/ext/oj/cache.c +341 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/compat.c +7 -22
- data/ext/oj/custom.c +15 -17
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +12 -15
- data/ext/oj/dump_compat.c +3 -3
- data/ext/oj/dump_object.c +9 -9
- data/ext/oj/dump_strict.c +3 -3
- data/ext/oj/err.h +19 -0
- data/ext/oj/extconf.rb +5 -0
- data/ext/oj/fast.c +7 -18
- data/ext/oj/intern.c +281 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +2 -2
- data/ext/oj/object.c +15 -92
- data/ext/oj/odd.c +1 -1
- data/ext/oj/oj.c +117 -94
- data/ext/oj/oj.h +1 -1
- data/ext/oj/parse.c +5 -5
- data/ext/oj/parser.c +1483 -0
- data/ext/oj/parser.h +90 -0
- data/ext/oj/rails.c +5 -5
- data/ext/oj/resolve.c +2 -20
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/saj.c +1 -1
- data/ext/oj/saj2.c +348 -0
- data/ext/oj/scp.c +1 -1
- data/ext/oj/sparse.c +2 -2
- data/ext/oj/stream_writer.c +4 -4
- data/ext/oj/strict.c +9 -27
- data/ext/oj/string_writer.c +2 -2
- data/ext/oj/usual.c +1252 -0
- data/ext/oj/validate.c +51 -0
- data/ext/oj/wab.c +14 -19
- data/lib/oj/error.rb +1 -1
- data/lib/oj/state.rb +8 -7
- data/lib/oj/version.rb +1 -1
- data/pages/Options.md +1 -1
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +2 -2
- data/test/json_gem/json_generator_test.rb +1 -1
- data/test/mem.rb +33 -0
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/test_hash.rb +1 -1
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +245 -0
- data/test/test_parser_usual.rb +213 -0
- metadata +26 -5
- data/ext/oj/hash.c +0 -168
- data/ext/oj/hash.h +0 -21
- data/ext/oj/hash_test.c +0 -491
data/ext/oj/custom.c
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
#include "dump.h"
|
9
9
|
#include "encode.h"
|
10
10
|
#include "err.h"
|
11
|
-
#include "
|
11
|
+
#include "intern.h"
|
12
12
|
#include "odd.h"
|
13
13
|
#include "oj.h"
|
14
14
|
#include "parse.h"
|
@@ -31,14 +31,14 @@ static void dump_obj_str(VALUE obj, int depth, Out out) {
|
|
31
31
|
|
32
32
|
static void dump_obj_as_str(VALUE obj, int depth, Out out) {
|
33
33
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
34
|
-
const char * str =
|
34
|
+
const char * str = RSTRING_PTR(rstr);
|
35
35
|
|
36
36
|
oj_dump_cstr(str, RSTRING_LEN(rstr), 0, 0, out);
|
37
37
|
}
|
38
38
|
|
39
39
|
static void bigdecimal_dump(VALUE obj, int depth, Out out) {
|
40
40
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
41
|
-
const char * str =
|
41
|
+
const char * str = RSTRING_PTR(rstr);
|
42
42
|
int len = (int)RSTRING_LEN(rstr);
|
43
43
|
|
44
44
|
if (0 == strcasecmp("Infinity", str)) {
|
@@ -123,7 +123,7 @@ static void date_dump(VALUE obj, int depth, Out out) {
|
|
123
123
|
case RubyTime:
|
124
124
|
case XmlTime:
|
125
125
|
v = rb_funcall(obj, rb_intern("iso8601"), 0);
|
126
|
-
oj_dump_cstr(
|
126
|
+
oj_dump_cstr(RSTRING_PTR(v), (int)RSTRING_LEN(v), 0, 0, out);
|
127
127
|
break;
|
128
128
|
case UnixZTime:
|
129
129
|
v = rb_funcall(obj, rb_intern("to_time"), 0);
|
@@ -420,7 +420,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
420
420
|
if (Qundef == v || T_STRING != rb_type(v)) {
|
421
421
|
rb_raise(rb_eEncodingError, "Invalid type for raw JSON.\n");
|
422
422
|
} else {
|
423
|
-
const char *s =
|
423
|
+
const char *s = RSTRING_PTR(v);
|
424
424
|
int len = (int)RSTRING_LEN(v);
|
425
425
|
const char *name = rb_id2name(*odd->attrs);
|
426
426
|
size_t nlen = strlen(name);
|
@@ -510,7 +510,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
510
510
|
if (Yes == out->opts->trace) {
|
511
511
|
oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
512
512
|
}
|
513
|
-
s =
|
513
|
+
s = RSTRING_PTR(rs);
|
514
514
|
len = (int)RSTRING_LEN(rs);
|
515
515
|
|
516
516
|
assure_size(out, len + 1);
|
@@ -537,7 +537,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
537
537
|
if (aj == obj) {
|
538
538
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
539
539
|
|
540
|
-
oj_dump_cstr(
|
540
|
+
oj_dump_cstr(RSTRING_PTR(rstr),
|
541
541
|
(int)RSTRING_LEN(rstr),
|
542
542
|
false,
|
543
543
|
false,
|
@@ -833,9 +833,9 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
|
|
833
833
|
v = rb_struct_aref(obj, INT2FIX(i));
|
834
834
|
#endif
|
835
835
|
if (ma != Qnil) {
|
836
|
-
volatile VALUE s =
|
836
|
+
volatile VALUE s = rb_sym2str(rb_ary_entry(ma, i));
|
837
837
|
|
838
|
-
name =
|
838
|
+
name = RSTRING_PTR(s);
|
839
839
|
len = (int)RSTRING_LEN(s);
|
840
840
|
} else {
|
841
841
|
len = snprintf(num_id, sizeof(num_id), "%d", i);
|
@@ -956,14 +956,13 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
956
956
|
}
|
957
957
|
} else {
|
958
958
|
//volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
959
|
-
volatile VALUE rstr =
|
959
|
+
volatile VALUE rstr = rb_utf8_str_new(str, len);
|
960
960
|
|
961
961
|
if (Qundef == rkey) {
|
962
|
-
rkey = rb_str_new(key, klen);
|
963
|
-
rstr = oj_encode(rstr);
|
964
|
-
rkey = oj_encode(rkey);
|
965
962
|
if (Yes == pi->options.sym_key) {
|
966
|
-
rkey =
|
963
|
+
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
|
964
|
+
} else {
|
965
|
+
rkey = rb_utf8_str_new(key, klen);
|
967
966
|
}
|
968
967
|
}
|
969
968
|
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
@@ -1031,7 +1030,7 @@ static void hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
|
1031
1030
|
}
|
1032
1031
|
if (86400 == ni->exp) { // UTC time
|
1033
1032
|
parent->val = rb_time_nano_new(ni->i, (long)nsec);
|
1034
|
-
// Since the ruby C routines
|
1033
|
+
// Since the ruby C routines always create local time, the
|
1035
1034
|
// offset and then a conversion to UTC keeps makes the time
|
1036
1035
|
// match the expected value.
|
1037
1036
|
parent->val = rb_funcall2(parent->val, oj_utc_id, 0, 0);
|
@@ -1089,9 +1088,8 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
1089
1088
|
}
|
1090
1089
|
|
1091
1090
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
1092
|
-
volatile VALUE rstr =
|
1091
|
+
volatile VALUE rstr = rb_utf8_str_new(str, len);
|
1093
1092
|
|
1094
|
-
rstr = oj_encode(rstr);
|
1095
1093
|
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
1096
1094
|
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
|
1097
1095
|
|
data/ext/oj/debug.c
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
// Copyright (c) 2021, Peter Ohler, All rights reserved.
|
2
|
+
|
3
|
+
#include "parser.h"
|
4
|
+
|
5
|
+
static void add_null(struct _ojParser *p) {
|
6
|
+
switch (p->stack[p->depth]) {
|
7
|
+
case TOP_FUN: printf("*** add_null at top\n"); break;
|
8
|
+
case ARRAY_FUN: printf("*** add_null to array\n"); break;
|
9
|
+
case OBJECT_FUN: printf("*** add_null with '%s'\n", buf_str(&p->key)); break;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
static void add_true(struct _ojParser *p) {
|
14
|
+
switch (p->stack[p->depth]) {
|
15
|
+
case TOP_FUN: printf("*** add_true at top\n"); break;
|
16
|
+
case ARRAY_FUN: printf("*** add_true to array\n"); break;
|
17
|
+
case OBJECT_FUN: printf("*** add_true with '%s'\n", buf_str(&p->key)); break;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
static void add_false(struct _ojParser *p) {
|
22
|
+
switch (p->stack[p->depth]) {
|
23
|
+
case TOP_FUN: printf("*** add_false at top\n"); break;
|
24
|
+
case ARRAY_FUN: printf("*** add_false to array\n"); break;
|
25
|
+
case OBJECT_FUN: printf("*** add_false with '%s'\n", buf_str(&p->key)); break;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
static void add_int(struct _ojParser *p) {
|
30
|
+
switch (p->stack[p->depth]) {
|
31
|
+
case TOP_FUN: printf("*** add_int %lld at top\n", (long long)p->num.fixnum); break;
|
32
|
+
case ARRAY_FUN: printf("*** add_int %lld to array\n", (long long)p->num.fixnum); break;
|
33
|
+
case OBJECT_FUN:
|
34
|
+
printf("*** add_int %lld with '%s'\n", (long long)p->num.fixnum, buf_str(&p->key));
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
static void add_float(struct _ojParser *p) {
|
40
|
+
switch (p->stack[p->depth]) {
|
41
|
+
case TOP_FUN: printf("*** add_float %Lf at top\n", p->num.dub); break;
|
42
|
+
case ARRAY_FUN: printf("*** add_float %Lf to array\n", p->num.dub); break;
|
43
|
+
case OBJECT_FUN: printf("*** add_float %Lf with '%s'\n", p->num.dub, buf_str(&p->key)); break;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
static void add_big(struct _ojParser *p) {
|
48
|
+
switch (p->stack[p->depth]) {
|
49
|
+
case TOP_FUN: printf("*** add_big %s at top\n", buf_str(&p->buf)); break;
|
50
|
+
case ARRAY_FUN: printf("*** add_big %s to array\n", buf_str(&p->buf)); break;
|
51
|
+
case OBJECT_FUN:
|
52
|
+
printf("*** add_big %s with '%s'\n", buf_str(&p->buf), buf_str(&p->key));
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
static void add_str(struct _ojParser *p) {
|
58
|
+
switch (p->stack[p->depth]) {
|
59
|
+
case TOP_FUN: printf("*** add_str '%s' at top\n", buf_str(&p->buf)); break;
|
60
|
+
case ARRAY_FUN: printf("*** add_str '%s' to array\n", buf_str(&p->buf)); break;
|
61
|
+
case OBJECT_FUN:
|
62
|
+
printf("*** add_str '%s' with '%s'\n", buf_str(&p->buf), buf_str(&p->key));
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
static void open_array(struct _ojParser *p) {
|
68
|
+
switch (p->stack[p->depth]) {
|
69
|
+
case TOP_FUN: printf("*** open_array at top\n"); break;
|
70
|
+
case ARRAY_FUN: printf("*** open_array to array\n"); break;
|
71
|
+
case OBJECT_FUN: printf("*** open_array with '%s'\n", buf_str(&p->key)); break;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
static void close_array(struct _ojParser *p) {
|
76
|
+
printf("*** close_array\n");
|
77
|
+
}
|
78
|
+
|
79
|
+
static void open_object(struct _ojParser *p) {
|
80
|
+
switch (p->stack[p->depth]) {
|
81
|
+
case TOP_FUN: printf("*** open_object at top\n"); break;
|
82
|
+
case ARRAY_FUN: printf("*** open_object to array\n"); break;
|
83
|
+
case OBJECT_FUN: printf("*** open_object with '%s'\n", buf_str(&p->key)); break;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
static void close_object(struct _ojParser *p) {
|
88
|
+
printf("*** close_object\n");
|
89
|
+
}
|
90
|
+
|
91
|
+
static VALUE option(ojParser p, const char *key, VALUE value) {
|
92
|
+
rb_raise(rb_eArgError, "%s is not an option for the debug delegate", key);
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
static VALUE result(struct _ojParser *p) {
|
97
|
+
return Qnil;
|
98
|
+
}
|
99
|
+
|
100
|
+
static void start(struct _ojParser *p) {
|
101
|
+
printf("*** start\n");
|
102
|
+
}
|
103
|
+
|
104
|
+
static void dfree(struct _ojParser *p) {
|
105
|
+
}
|
106
|
+
|
107
|
+
static void mark(struct _ojParser *p) {
|
108
|
+
}
|
109
|
+
|
110
|
+
void oj_set_parser_debug(ojParser p) {
|
111
|
+
Funcs end = p->funcs + 3;
|
112
|
+
Funcs f;
|
113
|
+
|
114
|
+
for (f = p->funcs; f < end; f++) {
|
115
|
+
f->add_null = add_null;
|
116
|
+
f->add_true = add_true;
|
117
|
+
f->add_false = add_false;
|
118
|
+
f->add_int = add_int;
|
119
|
+
f->add_float = add_float;
|
120
|
+
f->add_big = add_big;
|
121
|
+
f->add_str = add_str;
|
122
|
+
f->open_array = open_array;
|
123
|
+
f->close_array = close_array;
|
124
|
+
f->open_object = open_object;
|
125
|
+
f->close_object = close_object;
|
126
|
+
}
|
127
|
+
p->option = option;
|
128
|
+
p->result = result;
|
129
|
+
p->free = dfree;
|
130
|
+
p->mark = mark;
|
131
|
+
p->start = start;
|
132
|
+
}
|
data/ext/oj/dump.c
CHANGED
@@ -472,7 +472,7 @@ void oj_dump_time(VALUE obj, Out out, int withZone) {
|
|
472
472
|
void oj_dump_ruby_time(VALUE obj, Out out) {
|
473
473
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
474
474
|
|
475
|
-
oj_dump_cstr(
|
475
|
+
oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), 0, 0, out);
|
476
476
|
}
|
477
477
|
|
478
478
|
void oj_dump_xml_time(VALUE obj, Out out) {
|
@@ -708,21 +708,18 @@ void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts) {
|
|
708
708
|
}
|
709
709
|
|
710
710
|
void oj_dump_str(VALUE obj, int depth, Out out, bool as_ok) {
|
711
|
-
rb_encoding *enc =
|
711
|
+
rb_encoding *enc = rb_enc_get(obj);
|
712
712
|
|
713
|
-
if (
|
714
|
-
obj = rb_str_conv_enc(obj, enc,
|
713
|
+
if (oj_utf8_encoding != enc) {
|
714
|
+
obj = rb_str_conv_enc(obj, enc, oj_utf8_encoding);
|
715
715
|
}
|
716
|
-
oj_dump_cstr(
|
716
|
+
oj_dump_cstr(RSTRING_PTR(obj), (int)RSTRING_LEN(obj), 0, 0, out);
|
717
717
|
}
|
718
718
|
|
719
719
|
void oj_dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
|
720
|
-
|
721
|
-
// const char *sym = rb_id2name(SYM2ID(obj));
|
720
|
+
volatile VALUE s = rb_sym2str(obj);
|
722
721
|
|
723
|
-
|
724
|
-
|
725
|
-
oj_dump_cstr(rb_string_value_ptr((VALUE *)&s), (int)RSTRING_LEN(s), 0, 0, out);
|
722
|
+
oj_dump_cstr(RSTRING_PTR(s), (int)RSTRING_LEN(s), 0, 0, out);
|
726
723
|
}
|
727
724
|
|
728
725
|
static void debug_raise(const char *orig, size_t cnt, int line) {
|
@@ -760,7 +757,7 @@ void oj_dump_raw_json(VALUE obj, int depth, Out out) {
|
|
760
757
|
if (Yes == out->opts->trace) {
|
761
758
|
oj_trace("raw_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
762
759
|
}
|
763
|
-
oj_dump_raw(
|
760
|
+
oj_dump_raw(RSTRING_PTR(jv), (size_t)RSTRING_LEN(jv), out);
|
764
761
|
}
|
765
762
|
}
|
766
763
|
|
@@ -958,7 +955,7 @@ void oj_dump_class(VALUE obj, int depth, Out out, bool as_ok) {
|
|
958
955
|
void oj_dump_obj_to_s(VALUE obj, Out out) {
|
959
956
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
960
957
|
|
961
|
-
oj_dump_cstr(
|
958
|
+
oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), 0, 0, out);
|
962
959
|
}
|
963
960
|
|
964
961
|
void oj_dump_raw(const char *str, size_t cnt, Out out) {
|
@@ -1075,7 +1072,7 @@ void oj_dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1075
1072
|
} else {
|
1076
1073
|
assure_size(out, cnt);
|
1077
1074
|
}
|
1078
|
-
memcpy(out->cur,
|
1075
|
+
memcpy(out->cur, RSTRING_PTR(rs), cnt);
|
1079
1076
|
out->cur += cnt;
|
1080
1077
|
if (dump_as_string) {
|
1081
1078
|
*out->cur++ = '"';
|
@@ -1203,7 +1200,7 @@ void oj_dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1203
1200
|
if ((int)sizeof(buf) <= cnt) {
|
1204
1201
|
cnt = sizeof(buf) - 1;
|
1205
1202
|
}
|
1206
|
-
memcpy(buf,
|
1203
|
+
memcpy(buf, RSTRING_PTR(rstr), cnt);
|
1207
1204
|
buf[cnt] = '\0';
|
1208
1205
|
} else {
|
1209
1206
|
cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
|
@@ -1223,7 +1220,7 @@ int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char
|
|
1223
1220
|
if (17 <= cnt && (0 == strcmp("0001", buf + cnt - 4) || 0 == strcmp("9999", buf + cnt - 4))) {
|
1224
1221
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
1225
1222
|
|
1226
|
-
strcpy(buf,
|
1223
|
+
strcpy(buf, RSTRING_PTR(rstr));
|
1227
1224
|
cnt = (int)RSTRING_LEN(rstr);
|
1228
1225
|
}
|
1229
1226
|
return cnt;
|
data/ext/oj/dump_compat.c
CHANGED
@@ -129,7 +129,7 @@ dump_to_json(VALUE obj, Out out) {
|
|
129
129
|
oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyOut);
|
130
130
|
}
|
131
131
|
|
132
|
-
s =
|
132
|
+
s = RSTRING_PTR(rs);
|
133
133
|
len = (int)RSTRING_LEN(rs);
|
134
134
|
|
135
135
|
assure_size(out, len + 1);
|
@@ -635,7 +635,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
635
635
|
} else {
|
636
636
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
637
637
|
|
638
|
-
strcpy(buf,
|
638
|
+
strcpy(buf, RSTRING_PTR(rstr));
|
639
639
|
cnt = (int)RSTRING_LEN(rstr);
|
640
640
|
}
|
641
641
|
assure_size(out, cnt);
|
@@ -886,7 +886,7 @@ dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
|
|
886
886
|
} else {
|
887
887
|
assure_size(out, cnt);
|
888
888
|
}
|
889
|
-
memcpy(out->cur,
|
889
|
+
memcpy(out->cur, RSTRING_PTR(rs), cnt);
|
890
890
|
out->cur += cnt;
|
891
891
|
if (dump_as_string) {
|
892
892
|
*out->cur++ = '"';
|
data/ext/oj/dump_object.c
CHANGED
@@ -36,7 +36,7 @@ static void dump_data(VALUE obj, int depth, Out out, bool as_ok) {
|
|
36
36
|
} else {
|
37
37
|
if (oj_bigdecimal_class == clas) {
|
38
38
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
39
|
-
const char * str =
|
39
|
+
const char * str = RSTRING_PTR(rstr);
|
40
40
|
int len = (int)RSTRING_LEN(rstr);
|
41
41
|
|
42
42
|
if (No != out->opts->bigdec_as_num) {
|
@@ -65,7 +65,7 @@ static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
65
65
|
|
66
66
|
if (oj_bigdecimal_class == clas) {
|
67
67
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
68
|
-
const char * str =
|
68
|
+
const char * str = RSTRING_PTR(rstr);
|
69
69
|
int len = (int)RSTRING_LEN(rstr);
|
70
70
|
|
71
71
|
if (0 == strcasecmp("Infinity", str)) {
|
@@ -195,7 +195,7 @@ static void dump_str_class(VALUE obj, VALUE clas, int depth, Out out) {
|
|
195
195
|
if (Qundef != clas && rb_cString != clas) {
|
196
196
|
dump_obj_attrs(obj, clas, 0, depth, out);
|
197
197
|
} else {
|
198
|
-
const char *s =
|
198
|
+
const char *s = RSTRING_PTR(obj);
|
199
199
|
size_t len = (int)RSTRING_LEN(obj);
|
200
200
|
char s1 = s[1];
|
201
201
|
|
@@ -208,9 +208,9 @@ static void dump_str(VALUE obj, int depth, Out out, bool as_ok) {
|
|
208
208
|
}
|
209
209
|
|
210
210
|
static void dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
|
211
|
-
volatile VALUE s =
|
211
|
+
volatile VALUE s = rb_sym2str(obj);
|
212
212
|
|
213
|
-
oj_dump_cstr(
|
213
|
+
oj_dump_cstr(RSTRING_PTR(s), (int)RSTRING_LEN(s), 1, 0, out);
|
214
214
|
}
|
215
215
|
|
216
216
|
static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
@@ -414,7 +414,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
414
414
|
if (Qundef == v || T_STRING != rb_type(v)) {
|
415
415
|
rb_raise(rb_eEncodingError, "Invalid type for raw JSON.");
|
416
416
|
} else {
|
417
|
-
const char *s =
|
417
|
+
const char *s = RSTRING_PTR(v);
|
418
418
|
int len = (int)RSTRING_LEN(v);
|
419
419
|
const char *name = rb_id2name(*odd->attrs);
|
420
420
|
size_t nlen = strlen(name);
|
@@ -532,7 +532,7 @@ static void dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out)
|
|
532
532
|
*out->cur++ = 'f';
|
533
533
|
*out->cur++ = '"';
|
534
534
|
*out->cur++ = ':';
|
535
|
-
oj_dump_cstr(
|
535
|
+
oj_dump_cstr(RSTRING_PTR(obj), (int)RSTRING_LEN(obj), 0, 0, out);
|
536
536
|
break;
|
537
537
|
case T_ARRAY:
|
538
538
|
assure_size(out, d2 * out->indent + 14);
|
@@ -694,9 +694,9 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
|
|
694
694
|
|
695
695
|
*out->cur++ = '[';
|
696
696
|
for (i = 0; i < cnt; i++) {
|
697
|
-
volatile VALUE s =
|
697
|
+
volatile VALUE s = rb_sym2str(rb_ary_entry(ma, i));
|
698
698
|
|
699
|
-
name =
|
699
|
+
name = RSTRING_PTR(s);
|
700
700
|
len = (int)RSTRING_LEN(s);
|
701
701
|
size = len + 3;
|
702
702
|
assure_size(out, size);
|
data/ext/oj/dump_strict.c
CHANGED
@@ -98,7 +98,7 @@ static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
98
98
|
if ((int)sizeof(buf) <= cnt) {
|
99
99
|
cnt = sizeof(buf) - 1;
|
100
100
|
}
|
101
|
-
memcpy(buf,
|
101
|
+
memcpy(buf, RSTRING_PTR(rstr), cnt);
|
102
102
|
buf[cnt] = '\0';
|
103
103
|
} else {
|
104
104
|
cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
|
@@ -304,7 +304,7 @@ static void dump_data_strict(VALUE obj, int depth, Out out, bool as_ok) {
|
|
304
304
|
if (oj_bigdecimal_class == clas) {
|
305
305
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
306
306
|
|
307
|
-
oj_dump_raw(
|
307
|
+
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
308
308
|
} else {
|
309
309
|
raise_strict(obj);
|
310
310
|
}
|
@@ -316,7 +316,7 @@ static void dump_data_null(VALUE obj, int depth, Out out, bool as_ok) {
|
|
316
316
|
if (oj_bigdecimal_class == clas) {
|
317
317
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
318
318
|
|
319
|
-
oj_dump_raw(
|
319
|
+
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
320
320
|
} else {
|
321
321
|
oj_dump_nil(Qnil, depth, out, false);
|
322
322
|
}
|
data/ext/oj/err.h
CHANGED
@@ -4,12 +4,31 @@
|
|
4
4
|
#ifndef OJ_ERR_H
|
5
5
|
#define OJ_ERR_H
|
6
6
|
|
7
|
+
#include <errno.h>
|
7
8
|
#include "ruby.h"
|
9
|
+
|
8
10
|
// Needed to silence 2.4.0 warnings.
|
9
11
|
#ifndef NORETURN
|
10
12
|
#define NORETURN(x) x
|
11
13
|
#endif
|
12
14
|
|
15
|
+
#define OJ_ERR_START 300
|
16
|
+
|
17
|
+
typedef enum {
|
18
|
+
OJ_OK = 0,
|
19
|
+
OJ_ERR_MEMORY = ENOMEM,
|
20
|
+
OJ_ERR_PARSE = OJ_ERR_START,
|
21
|
+
OJ_ERR_READ,
|
22
|
+
OJ_ERR_WRITE,
|
23
|
+
OJ_ERR_OVERFLOW,
|
24
|
+
OJ_ERR_ARG,
|
25
|
+
OJ_ERR_TOO_MANY,
|
26
|
+
OJ_ERR_TYPE,
|
27
|
+
OJ_ERR_KEY,
|
28
|
+
OJ_ABORT,
|
29
|
+
OJ_ERR_LAST,
|
30
|
+
} ojStatus;
|
31
|
+
|
13
32
|
#define set_error(err, eclas, msg, json, current) \
|
14
33
|
_oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
|
15
34
|
|