oj 3.11.5 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1421 -0
- data/README.md +19 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +20 -6
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +27 -77
- data/ext/oj/custom.c +86 -179
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +256 -249
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +65 -187
- data/ext/oj/dump_strict.c +27 -51
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +24 -8
- data/ext/oj/extconf.rb +21 -6
- data/ext/oj/fast.c +149 -149
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +121 -106
- data/ext/oj/object.c +85 -162
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +542 -411
- data/ext/oj/oj.h +99 -73
- data/ext/oj/parse.c +175 -187
- data/ext/oj/parse.h +26 -24
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +112 -159
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +5 -24
- data/ext/oj/rxclass.c +7 -6
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +22 -33
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +5 -28
- data/ext/oj/sparse.c +28 -72
- data/ext/oj/stream_writer.c +50 -40
- data/ext/oj/strict.c +56 -61
- data/ext/oj/string_writer.c +72 -39
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +63 -88
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -7
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +16 -45
- data/test/helper.rb +11 -8
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +8 -6
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +56 -38
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +95 -43
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +5 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +74 -128
- data/ext/oj/hash.c +0 -131
- data/ext/oj/hash.h +0 -19
- data/ext/oj/hash_test.c +0 -491
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/dump_strict.c
CHANGED
@@ -22,15 +22,13 @@ static const char ninf_val[] = NINF_VAL;
|
|
22
22
|
static const char nan_val[] = NAN_VAL;
|
23
23
|
|
24
24
|
static void raise_strict(VALUE obj) {
|
25
|
-
rb_raise(rb_eTypeError,
|
26
|
-
"Failed to dump %s Object to JSON in strict mode.\n",
|
27
|
-
rb_class2name(rb_obj_class(obj)));
|
25
|
+
rb_raise(rb_eTypeError, "Failed to dump %s Object to JSON in strict mode.\n", rb_class2name(rb_obj_class(obj)));
|
28
26
|
}
|
29
27
|
|
30
28
|
// Removed dependencies on math due to problems with CentOS 5.4.
|
31
29
|
static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
32
30
|
char buf[64];
|
33
|
-
char
|
31
|
+
char* b;
|
34
32
|
double d = rb_num2dbl(obj);
|
35
33
|
int cnt = 0;
|
36
34
|
|
@@ -92,22 +90,20 @@ static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
92
90
|
} else if (d == (double)(long long int)d) {
|
93
91
|
cnt = snprintf(buf, sizeof(buf), "%.1f", d);
|
94
92
|
} else if (0 == out->opts->float_prec) {
|
95
|
-
volatile VALUE rstr =
|
93
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
96
94
|
|
97
95
|
cnt = (int)RSTRING_LEN(rstr);
|
98
96
|
if ((int)sizeof(buf) <= cnt) {
|
99
97
|
cnt = sizeof(buf) - 1;
|
100
98
|
}
|
101
|
-
|
99
|
+
memcpy(buf, RSTRING_PTR(rstr), cnt);
|
102
100
|
buf[cnt] = '\0';
|
103
101
|
} else {
|
104
102
|
cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
|
105
103
|
}
|
106
104
|
}
|
107
105
|
assure_size(out, cnt);
|
108
|
-
|
109
|
-
*out->cur++ = *b;
|
110
|
-
}
|
106
|
+
APPEND_CHARS(out->cur, buf, cnt);
|
111
107
|
*out->cur = '\0';
|
112
108
|
}
|
113
109
|
|
@@ -134,28 +130,26 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
134
130
|
} else {
|
135
131
|
size = d2 * out->indent + 2;
|
136
132
|
}
|
133
|
+
assure_size(out, size * cnt);
|
137
134
|
cnt--;
|
138
135
|
for (i = 0; i <= cnt; i++) {
|
139
|
-
assure_size(out, size);
|
140
136
|
if (out->opts->dump_opts.use) {
|
141
137
|
if (0 < out->opts->dump_opts.array_size) {
|
142
|
-
|
143
|
-
out->cur += out->opts->dump_opts.array_size;
|
138
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
|
144
139
|
}
|
145
140
|
if (0 < out->opts->dump_opts.indent_size) {
|
146
141
|
int i;
|
147
142
|
for (i = d2; 0 < i; i--) {
|
148
|
-
|
149
|
-
out->cur += out->opts->dump_opts.indent_size;
|
143
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
150
144
|
}
|
151
145
|
}
|
152
146
|
} else {
|
153
147
|
fill_indent(out, d2);
|
154
148
|
}
|
155
149
|
if (NullMode == out->opts->mode) {
|
156
|
-
oj_dump_null_val(
|
150
|
+
oj_dump_null_val(RARRAY_AREF(a, i), d2, out);
|
157
151
|
} else {
|
158
|
-
oj_dump_strict_val(
|
152
|
+
oj_dump_strict_val(RARRAY_AREF(a, i), d2, out);
|
159
153
|
}
|
160
154
|
if (i < cnt) {
|
161
155
|
*out->cur++ = ',';
|
@@ -167,15 +161,13 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
167
161
|
// printf("*** d2: %u indent: %u '%s'\n", d2, out->opts->dump_opts->indent_size,
|
168
162
|
// out->opts->dump_opts->indent);
|
169
163
|
if (0 < out->opts->dump_opts.array_size) {
|
170
|
-
|
171
|
-
out->cur += out->opts->dump_opts.array_size;
|
164
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
|
172
165
|
}
|
173
166
|
if (0 < out->opts->dump_opts.indent_size) {
|
174
167
|
int i;
|
175
168
|
|
176
169
|
for (i = depth; 0 < i; i--) {
|
177
|
-
|
178
|
-
out->cur += out->opts->dump_opts.indent_size;
|
170
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
179
171
|
}
|
180
172
|
}
|
181
173
|
} else {
|
@@ -214,14 +206,12 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
214
206
|
size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
|
215
207
|
assure_size(out, size);
|
216
208
|
if (0 < out->opts->dump_opts.hash_size) {
|
217
|
-
|
218
|
-
out->cur += out->opts->dump_opts.hash_size;
|
209
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.hash_nl, out->opts->dump_opts.hash_size);
|
219
210
|
}
|
220
211
|
if (0 < out->opts->dump_opts.indent_size) {
|
221
212
|
int i;
|
222
213
|
for (i = depth; 0 < i; i--) {
|
223
|
-
|
224
|
-
out->cur += out->opts->dump_opts.indent_size;
|
214
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
225
215
|
}
|
226
216
|
}
|
227
217
|
if (rtype == T_STRING) {
|
@@ -232,13 +222,11 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
232
222
|
size = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
|
233
223
|
assure_size(out, size);
|
234
224
|
if (0 < out->opts->dump_opts.before_size) {
|
235
|
-
|
236
|
-
out->cur += out->opts->dump_opts.before_size;
|
225
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
237
226
|
}
|
238
227
|
*out->cur++ = ':';
|
239
228
|
if (0 < out->opts->dump_opts.after_size) {
|
240
|
-
|
241
|
-
out->cur += out->opts->dump_opts.after_size;
|
229
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
242
230
|
}
|
243
231
|
}
|
244
232
|
if (NullMode == out->opts->mode) {
|
@@ -281,15 +269,13 @@ static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
281
269
|
size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
|
282
270
|
assure_size(out, size);
|
283
271
|
if (0 < out->opts->dump_opts.hash_size) {
|
284
|
-
|
285
|
-
out->cur += out->opts->dump_opts.hash_size;
|
272
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.hash_nl, out->opts->dump_opts.hash_size);
|
286
273
|
}
|
287
274
|
if (0 < out->opts->dump_opts.indent_size) {
|
288
275
|
int i;
|
289
276
|
|
290
277
|
for (i = depth; 0 < i; i--) {
|
291
|
-
|
292
|
-
out->cur += out->opts->dump_opts.indent_size;
|
278
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
293
279
|
}
|
294
280
|
}
|
295
281
|
}
|
@@ -302,9 +288,9 @@ static void dump_data_strict(VALUE obj, int depth, Out out, bool as_ok) {
|
|
302
288
|
VALUE clas = rb_obj_class(obj);
|
303
289
|
|
304
290
|
if (oj_bigdecimal_class == clas) {
|
305
|
-
volatile VALUE rstr =
|
291
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
306
292
|
|
307
|
-
oj_dump_raw(
|
293
|
+
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
308
294
|
} else {
|
309
295
|
raise_strict(obj);
|
310
296
|
}
|
@@ -314,9 +300,9 @@ static void dump_data_null(VALUE obj, int depth, Out out, bool as_ok) {
|
|
314
300
|
VALUE clas = rb_obj_class(obj);
|
315
301
|
|
316
302
|
if (oj_bigdecimal_class == clas) {
|
317
|
-
volatile VALUE rstr =
|
303
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
318
304
|
|
319
|
-
oj_dump_raw(
|
305
|
+
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
320
306
|
} else {
|
321
307
|
oj_dump_nil(Qnil, depth, out, false);
|
322
308
|
}
|
@@ -350,9 +336,7 @@ static DumpFunc strict_funcs[] = {
|
|
350
336
|
void oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
351
337
|
int type = rb_type(obj);
|
352
338
|
|
353
|
-
|
354
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
355
|
-
}
|
339
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
356
340
|
if (MAX_DEPTH < depth) {
|
357
341
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
358
342
|
}
|
@@ -361,9 +345,7 @@ void oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
|
361
345
|
|
362
346
|
if (NULL != f) {
|
363
347
|
f(obj, depth, out, false);
|
364
|
-
|
365
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
366
|
-
}
|
348
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
367
349
|
return;
|
368
350
|
}
|
369
351
|
}
|
@@ -398,9 +380,7 @@ static DumpFunc null_funcs[] = {
|
|
398
380
|
void oj_dump_null_val(VALUE obj, int depth, Out out) {
|
399
381
|
int type = rb_type(obj);
|
400
382
|
|
401
|
-
|
402
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
403
|
-
}
|
383
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
404
384
|
if (MAX_DEPTH < depth) {
|
405
385
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
406
386
|
}
|
@@ -409,14 +389,10 @@ void oj_dump_null_val(VALUE obj, int depth, Out out) {
|
|
409
389
|
|
410
390
|
if (NULL != f) {
|
411
391
|
f(obj, depth, out, false);
|
412
|
-
|
413
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
414
|
-
}
|
392
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
415
393
|
return;
|
416
394
|
}
|
417
395
|
}
|
418
396
|
oj_dump_nil(Qnil, depth, out, false);
|
419
|
-
|
420
|
-
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
421
|
-
}
|
397
|
+
TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
|
422
398
|
}
|
data/ext/oj/encoder.c
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
// Copyright (c) 2011, 2022 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
3
|
+
|
4
|
+
#include "oj.h"
|
5
|
+
|
6
|
+
typedef struct _encoder {
|
7
|
+
int indent; // indention for dump, default 2
|
8
|
+
char circular; // YesNo
|
9
|
+
char escape_mode; // Escape_Mode
|
10
|
+
char mode; // Mode
|
11
|
+
char time_format; // TimeFormat
|
12
|
+
char bigdec_as_num; // YesNo
|
13
|
+
char to_hash; // YesNo
|
14
|
+
char to_json; // YesNo
|
15
|
+
char as_json; // YesNo
|
16
|
+
char raw_json; // YesNo
|
17
|
+
char trace; // YesNo
|
18
|
+
char sec_prec_set; // boolean (0 or 1)
|
19
|
+
char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
|
20
|
+
int64_t int_range_min; // dump numbers below as string
|
21
|
+
int64_t int_range_max; // dump numbers above as string
|
22
|
+
const char* create_id; // 0 or string
|
23
|
+
size_t create_id_len; // length of create_id
|
24
|
+
int sec_prec; // second precision when dumping time
|
25
|
+
char float_prec; // float precision, linked to float_fmt
|
26
|
+
char float_fmt[7]; // float format for dumping, if empty use Ruby
|
27
|
+
struct _dumpOpts dump_opts;
|
28
|
+
struct _rxClass str_rx;
|
29
|
+
VALUE* ignore; // Qnil terminated array of classes or NULL
|
30
|
+
}* Encoder;
|
31
|
+
|
32
|
+
/*
|
33
|
+
rb_define_module_function(Oj, "encode", encode, -1);
|
34
|
+
rb_define_module_function(Oj, "to_file", to_file, -1); // or maybe just write
|
35
|
+
rb_define_module_function(Oj, "to_stream", to_stream, -1);
|
36
|
+
*/
|
37
|
+
|
38
|
+
// write(to, obj)
|
39
|
+
// if to is a string then open file
|
40
|
+
// else if stream then write to stream
|
41
|
+
// handle non-blocking
|
42
|
+
|
43
|
+
// should each mode have a different encoder or use delegates like the parser?
|
data/ext/oj/err.c
CHANGED
@@ -39,11 +39,7 @@ void _oj_err_set_with_location(Err err,
|
|
39
39
|
oj_err_set(err, eclas, "%s at line %d, column %d [%s:%d]", msg, n, col, file, line);
|
40
40
|
}
|
41
41
|
|
42
|
-
void _oj_raise_error(const char *msg,
|
43
|
-
const char *json,
|
44
|
-
const char *current,
|
45
|
-
const char *file,
|
46
|
-
int line) {
|
42
|
+
void _oj_raise_error(const char *msg, const char *json, const char *current, const char *file, int line) {
|
47
43
|
struct _err err;
|
48
44
|
int n = 1;
|
49
45
|
int col = 1;
|
@@ -56,13 +52,6 @@ void _oj_raise_error(const char *msg,
|
|
56
52
|
n++;
|
57
53
|
}
|
58
54
|
}
|
59
|
-
oj_err_set(&err,
|
60
|
-
oj_parse_error_class,
|
61
|
-
"%s at line %d, column %d [%s:%d]",
|
62
|
-
msg,
|
63
|
-
n,
|
64
|
-
col,
|
65
|
-
file,
|
66
|
-
line);
|
55
|
+
oj_err_set(&err, oj_parse_error_class, "%s at line %d, column %d [%s:%d]", msg, n, col, file, line);
|
67
56
|
rb_raise(err.clas, "%s", err.msg);
|
68
57
|
}
|
data/ext/oj/err.h
CHANGED
@@ -4,19 +4,38 @@
|
|
4
4
|
#ifndef OJ_ERR_H
|
5
5
|
#define OJ_ERR_H
|
6
6
|
|
7
|
+
#include <errno.h>
|
8
|
+
|
7
9
|
#include "ruby.h"
|
10
|
+
|
8
11
|
// Needed to silence 2.4.0 warnings.
|
9
12
|
#ifndef NORETURN
|
10
13
|
#define NORETURN(x) x
|
11
14
|
#endif
|
12
15
|
|
13
|
-
#define
|
14
|
-
|
16
|
+
#define OJ_ERR_START 300
|
17
|
+
|
18
|
+
typedef enum {
|
19
|
+
OJ_OK = 0,
|
20
|
+
OJ_ERR_MEMORY = ENOMEM,
|
21
|
+
OJ_ERR_PARSE = OJ_ERR_START,
|
22
|
+
OJ_ERR_READ,
|
23
|
+
OJ_ERR_WRITE,
|
24
|
+
OJ_ERR_OVERFLOW,
|
25
|
+
OJ_ERR_ARG,
|
26
|
+
OJ_ERR_TOO_MANY,
|
27
|
+
OJ_ERR_TYPE,
|
28
|
+
OJ_ERR_KEY,
|
29
|
+
OJ_ABORT,
|
30
|
+
OJ_ERR_LAST,
|
31
|
+
} ojStatus;
|
32
|
+
|
33
|
+
#define set_error(err, eclas, msg, json, current) _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
|
15
34
|
|
16
35
|
typedef struct _err {
|
17
36
|
VALUE clas;
|
18
37
|
char msg[128];
|
19
|
-
} *
|
38
|
+
} *Err;
|
20
39
|
|
21
40
|
extern VALUE oj_parse_error_class;
|
22
41
|
|
@@ -33,11 +52,8 @@ NORETURN(extern void oj_err_raise(Err e));
|
|
33
52
|
|
34
53
|
#define raise_error(msg, json, current) _oj_raise_error(msg, json, current, __FILE__, __LINE__)
|
35
54
|
|
36
|
-
NORETURN(
|
37
|
-
|
38
|
-
const char *current,
|
39
|
-
const char *file,
|
40
|
-
int line));
|
55
|
+
NORETURN(
|
56
|
+
extern void _oj_raise_error(const char *msg, const char *json, const char *current, const char *file, int line));
|
41
57
|
|
42
58
|
inline static void err_init(Err e) {
|
43
59
|
e->clas = Qnil;
|
data/ext/oj/extconf.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mkmf'
|
2
4
|
require 'rbconfig'
|
3
5
|
|
@@ -6,7 +8,7 @@ dir_config(extension_name)
|
|
6
8
|
|
7
9
|
parts = RUBY_DESCRIPTION.split(' ')
|
8
10
|
type = parts[0]
|
9
|
-
type = type[4
|
11
|
+
type = type[4..] if type.start_with?('tcs-')
|
10
12
|
is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
11
13
|
platform = RUBY_PLATFORM
|
12
14
|
version = RUBY_VERSION.split('.')
|
@@ -23,17 +25,30 @@ dflags = {
|
|
23
25
|
'RSTRUCT_LEN_RETURNS_INTEGER_OBJECT' => ('ruby' == type && '2' == version[0] && '4' == version[1] && '1' >= version[2]) ? 1 : 0,
|
24
26
|
}
|
25
27
|
|
26
|
-
have_func('rb_time_timespec')
|
27
|
-
have_func('rb_ivar_count')
|
28
|
-
have_func('rb_ivar_foreach')
|
29
28
|
# Support for compaction.
|
30
29
|
have_func('rb_gc_mark_movable')
|
31
30
|
have_func('stpcpy')
|
32
31
|
have_func('pthread_mutex_init')
|
32
|
+
have_func('getrlimit', 'sys/resource.h')
|
33
|
+
have_func('rb_enc_interned_str')
|
34
|
+
have_func('rb_ext_ractor_safe', 'ruby.h')
|
33
35
|
|
34
36
|
dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?
|
35
37
|
|
36
|
-
|
38
|
+
if with_config('--with-sse42')
|
39
|
+
if try_cflags('-msse4.2')
|
40
|
+
$CPPFLAGS += ' -msse4.2'
|
41
|
+
dflags['OJ_USE_SSE4_2'] = 1
|
42
|
+
else
|
43
|
+
warn 'SSE 4.2 is not supported on this platform.'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if enable_config('trace-log', false)
|
48
|
+
dflags['OJ_ENABLE_TRACE_LOG'] = 1
|
49
|
+
end
|
50
|
+
|
51
|
+
dflags.each do |k, v|
|
37
52
|
if v.nil?
|
38
53
|
$CPPFLAGS += " -D#{k}"
|
39
54
|
else
|
@@ -42,7 +57,7 @@ dflags.each do |k,v|
|
|
42
57
|
end
|
43
58
|
|
44
59
|
$CPPFLAGS += ' -Wall'
|
45
|
-
#puts "*** $CPPFLAGS: #{$CPPFLAGS}"
|
60
|
+
# puts "*** $CPPFLAGS: #{$CPPFLAGS}"
|
46
61
|
# Adding the __attribute__ flag only works with gcc compilers and even then it
|
47
62
|
# does not work to check args with varargs so just remove the check.
|
48
63
|
CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)
|