oj 3.13.23 → 3.16.10
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/CHANGELOG.md +86 -0
- data/README.md +2 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +26 -59
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +103 -53
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +16 -7
- data/ext/oj/fast.c +63 -98
- data/ext/oj/intern.c +62 -47
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +54 -38
- data/ext/oj/object.c +33 -43
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +245 -216
- data/ext/oj/oj.h +83 -81
- data/ext/oj/parse.c +109 -153
- data/ext/oj/parse.h +21 -24
- data/ext/oj/parser.c +80 -67
- data/ext/oj/parser.h +9 -8
- data/ext/oj/rails.c +71 -94
- data/ext/oj/reader.c +9 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +13 -15
- data/ext/oj/saj2.c +37 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +6 -20
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +46 -48
- data/ext/oj/strict.c +22 -56
- data/ext/oj/string_writer.c +64 -40
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -114
- data/ext/oj/usual.h +7 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +13 -2
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- 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 +0 -1
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +7 -7
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/Options.md +4 -0
- metadata +46 -121
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activerecord/result_test.rb +0 -32
- 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/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -507
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -49
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -486
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -77
- data/test/helper.rb +0 -42
- data/test/isolated/shared.rb +0 -308
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -153
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -20
- data/test/json_gem/json_fixtures_test.rb +0 -35
- data/test/json_gem/json_generator_test.rb +0 -396
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -33
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -130
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_once.rb +0 -58
- data/test/perf_parser.rb +0 -189
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -152
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -139
- data/test/perf_wab.rb +0 -131
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -540
- data/test/test_custom.rb +0 -544
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -530
- data/test/test_file.rb +0 -255
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1025
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -335
- data/test/test_parser_usual.rb +0 -217
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -435
- data/test/test_various.rb +0 -752
- data/test/test_wab.rb +0 -309
- data/test/test_writer.rb +0 -380
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/oj.h
CHANGED
@@ -40,9 +40,9 @@ enum st_retval { ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK };
|
|
40
40
|
#define NAN_VAL "3.3e14159265358979323846"
|
41
41
|
|
42
42
|
#if __STDC_VERSION__ >= 199901L
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
// To avoid using ruby_snprintf with C99.
|
44
|
+
#undef snprintf
|
45
|
+
#include <stdio.h>
|
46
46
|
#endif
|
47
47
|
|
48
48
|
// To avoid using ruby_nonempty_memcpy().
|
@@ -103,13 +103,6 @@ typedef enum {
|
|
103
103
|
FILE_IO = 'f',
|
104
104
|
} StreamWriterType;
|
105
105
|
|
106
|
-
typedef enum {
|
107
|
-
CALLER_DUMP = 'd',
|
108
|
-
CALLER_TO_JSON = 't',
|
109
|
-
CALLER_GENERATE = 'g',
|
110
|
-
// Add the fast versions if necessary. Maybe unparse as well if needed.
|
111
|
-
} DumpCaller;
|
112
|
-
|
113
106
|
typedef struct _dumpOpts {
|
114
107
|
bool use;
|
115
108
|
char indent_str[16];
|
@@ -124,41 +117,42 @@ typedef struct _dumpOpts {
|
|
124
117
|
uint8_t array_size;
|
125
118
|
char nan_dump; // NanDump
|
126
119
|
bool omit_nil;
|
120
|
+
bool omit_null_byte;
|
127
121
|
int max_depth;
|
128
|
-
} *
|
122
|
+
} *DumpOpts;
|
129
123
|
|
130
124
|
typedef struct _options {
|
131
|
-
int
|
132
|
-
char
|
133
|
-
char
|
134
|
-
char
|
135
|
-
char
|
136
|
-
char
|
137
|
-
char
|
138
|
-
char
|
139
|
-
char
|
140
|
-
char
|
141
|
-
char
|
142
|
-
char
|
143
|
-
char
|
144
|
-
char
|
145
|
-
char
|
146
|
-
char
|
147
|
-
char
|
148
|
-
char
|
149
|
-
char
|
150
|
-
char
|
151
|
-
char
|
152
|
-
char
|
153
|
-
char
|
154
|
-
char
|
155
|
-
char
|
156
|
-
char
|
157
|
-
char
|
158
|
-
char
|
125
|
+
int indent; // indention for dump, default 2
|
126
|
+
char circular; // YesNo
|
127
|
+
char auto_define; // YesNo
|
128
|
+
char sym_key; // YesNo
|
129
|
+
char escape_mode; // Escape_Mode
|
130
|
+
char mode; // Mode
|
131
|
+
char class_cache; // YesNo
|
132
|
+
char time_format; // TimeFormat
|
133
|
+
char bigdec_as_num; // YesNo
|
134
|
+
char bigdec_load; // BigLoad
|
135
|
+
char compat_bigdec; // boolean (0 or 1)
|
136
|
+
char to_hash; // YesNo
|
137
|
+
char to_json; // YesNo
|
138
|
+
char as_json; // YesNo
|
139
|
+
char raw_json; // YesNo
|
140
|
+
char nilnil; // YesNo
|
141
|
+
char empty_string; // YesNo
|
142
|
+
char allow_gc; // allow GC during parse
|
143
|
+
char quirks_mode; // allow single JSON values instead of documents
|
144
|
+
char allow_invalid; // YesNo - allow invalid unicode
|
145
|
+
char create_ok; // YesNo allow create_id
|
146
|
+
char allow_nan; // YEsyNo for parsing only
|
147
|
+
char trace; // YesNo
|
148
|
+
char safe; // YesNo
|
149
|
+
char sec_prec_set; // boolean (0 or 1)
|
150
|
+
char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
|
151
|
+
char cache_keys; // YesNo
|
152
|
+
char cache_str; // string short than or equal to this are cache
|
159
153
|
int64_t int_range_min; // dump numbers below as string
|
160
154
|
int64_t int_range_max; // dump numbers above as string
|
161
|
-
const char
|
155
|
+
const char *create_id; // 0 or string
|
162
156
|
size_t create_id_len; // length of create_id
|
163
157
|
int sec_prec; // second precision when dumping time
|
164
158
|
char float_prec; // float precision, linked to float_fmt
|
@@ -167,8 +161,8 @@ typedef struct _options {
|
|
167
161
|
VALUE array_class; // class to use in place of Array on load
|
168
162
|
struct _dumpOpts dump_opts;
|
169
163
|
struct _rxClass str_rx;
|
170
|
-
VALUE
|
171
|
-
} *
|
164
|
+
VALUE *ignore; // Qnil terminated array of classes or NULL
|
165
|
+
} *Options;
|
172
166
|
|
173
167
|
struct _out;
|
174
168
|
typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
|
@@ -178,42 +172,42 @@ typedef struct _rOpt {
|
|
178
172
|
VALUE clas;
|
179
173
|
bool on;
|
180
174
|
DumpFunc dump;
|
181
|
-
} *
|
175
|
+
} *ROpt;
|
182
176
|
|
183
177
|
typedef struct _rOptTable {
|
184
178
|
int len;
|
185
179
|
int alen;
|
186
180
|
ROpt table;
|
187
|
-
} *
|
181
|
+
} *ROptTable;
|
188
182
|
|
189
183
|
typedef struct _out {
|
190
|
-
char
|
191
|
-
char
|
192
|
-
char
|
193
|
-
char
|
194
|
-
Cache8
|
195
|
-
slot_t
|
196
|
-
int
|
197
|
-
int
|
198
|
-
Options
|
199
|
-
uint32_t
|
200
|
-
bool
|
201
|
-
bool
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
ROptTable
|
206
|
-
} *
|
184
|
+
char stack_buffer[4096];
|
185
|
+
char *buf;
|
186
|
+
char *end;
|
187
|
+
char *cur;
|
188
|
+
Cache8 circ_cache;
|
189
|
+
slot_t circ_cnt;
|
190
|
+
int indent;
|
191
|
+
int depth; // used by dump_hash
|
192
|
+
Options opts;
|
193
|
+
uint32_t hash_cnt;
|
194
|
+
bool allocated;
|
195
|
+
bool omit_nil;
|
196
|
+
bool omit_null_byte;
|
197
|
+
int argc;
|
198
|
+
VALUE *argv;
|
199
|
+
ROptTable ropts;
|
200
|
+
} *Out;
|
207
201
|
|
208
202
|
typedef struct _strWriter {
|
209
203
|
struct _out out;
|
210
204
|
struct _options opts;
|
211
205
|
int depth;
|
212
|
-
char
|
213
|
-
char
|
206
|
+
char *types; // DumpType
|
207
|
+
char *types_end;
|
214
208
|
int keyWritten;
|
215
209
|
|
216
|
-
} *
|
210
|
+
} *StrWriter;
|
217
211
|
|
218
212
|
typedef struct _streamWriter {
|
219
213
|
struct _strWriter sw;
|
@@ -221,7 +215,7 @@ typedef struct _streamWriter {
|
|
221
215
|
VALUE stream;
|
222
216
|
int fd;
|
223
217
|
int flush_limit; // indicator of when to flush
|
224
|
-
} *
|
218
|
+
} *StreamWriter;
|
225
219
|
|
226
220
|
enum { NO_VAL = 0x00, STR_VAL = 0x01, COL_VAL = 0x02, RUBY_VAL = 0x03 };
|
227
221
|
|
@@ -232,14 +226,14 @@ typedef struct _leaf {
|
|
232
226
|
size_t index; // array index, 0 is not set
|
233
227
|
};
|
234
228
|
union {
|
235
|
-
char
|
229
|
+
char *str; // pointer to location in json string or allocated
|
236
230
|
struct _leaf *elements; // array and hash elements
|
237
231
|
VALUE value;
|
238
232
|
};
|
239
233
|
uint8_t rtype;
|
240
234
|
uint8_t parent_type;
|
241
235
|
uint8_t value_type;
|
242
|
-
} *
|
236
|
+
} *Leaf;
|
243
237
|
|
244
238
|
extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
|
245
239
|
extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
|
@@ -260,13 +254,15 @@ extern VALUE oj_custom_parse_cstr(int argc, VALUE *argv, char *json, size_t len)
|
|
260
254
|
extern bool oj_hash_has_key(VALUE hash, VALUE key);
|
261
255
|
extern void oj_parse_options(VALUE ropts, Options copts);
|
262
256
|
|
263
|
-
extern void
|
264
|
-
extern void
|
265
|
-
|
266
|
-
extern void
|
267
|
-
extern void
|
268
|
-
extern void
|
269
|
-
extern
|
257
|
+
extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
|
258
|
+
extern void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
|
259
|
+
extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
|
260
|
+
extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
|
261
|
+
extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
|
262
|
+
extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
|
263
|
+
extern char *oj_longlong_to_string(long long num, bool negative, char *buf);
|
264
|
+
|
265
|
+
extern StrWriter oj_str_writer_unwrap(VALUE writer);
|
270
266
|
|
271
267
|
extern void oj_str_writer_push_key(StrWriter sw, const char *key);
|
272
268
|
extern void oj_str_writer_push_object(StrWriter sw, const char *key);
|
@@ -293,7 +289,7 @@ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
|
|
293
289
|
|
294
290
|
extern VALUE Oj;
|
295
291
|
extern struct _options oj_default_options;
|
296
|
-
extern rb_encoding
|
292
|
+
extern rb_encoding *oj_utf8_encoding;
|
297
293
|
extern int oj_utf8_encoding_index;
|
298
294
|
|
299
295
|
extern VALUE oj_bag_class;
|
@@ -317,13 +313,12 @@ extern VALUE oj_ascii_only_sym;
|
|
317
313
|
extern VALUE oj_create_additions_sym;
|
318
314
|
extern VALUE oj_decimal_class_sym;
|
319
315
|
extern VALUE oj_hash_class_sym;
|
320
|
-
extern VALUE oj_in_sym;
|
321
316
|
extern VALUE oj_indent_sym;
|
322
|
-
extern VALUE oj_nanosecond_sym;
|
323
317
|
extern VALUE oj_max_nesting_sym;
|
324
318
|
extern VALUE oj_object_class_sym;
|
325
319
|
extern VALUE oj_object_nl_sym;
|
326
320
|
extern VALUE oj_quirks_mode_sym;
|
321
|
+
extern VALUE oj_skip_null_byte_sym;
|
327
322
|
extern VALUE oj_space_before_sym;
|
328
323
|
extern VALUE oj_space_sym;
|
329
324
|
extern VALUE oj_symbolize_names_sym;
|
@@ -336,10 +331,10 @@ extern ID oj_array_append_id;
|
|
336
331
|
extern ID oj_array_end_id;
|
337
332
|
extern ID oj_array_start_id;
|
338
333
|
extern ID oj_as_json_id;
|
339
|
-
extern ID oj_at_id;
|
340
334
|
extern ID oj_begin_id;
|
341
335
|
extern ID oj_bigdecimal_id;
|
342
336
|
extern ID oj_end_id;
|
337
|
+
extern ID oj_eofq_id;
|
343
338
|
extern ID oj_error_id;
|
344
339
|
extern ID oj_exclude_end_id;
|
345
340
|
extern ID oj_file_id;
|
@@ -354,6 +349,7 @@ extern ID oj_json_create_id;
|
|
354
349
|
extern ID oj_length_id;
|
355
350
|
extern ID oj_new_id;
|
356
351
|
extern ID oj_parse_id;
|
352
|
+
extern ID oj_plus_id;
|
357
353
|
extern ID oj_pos_id;
|
358
354
|
extern ID oj_read_id;
|
359
355
|
extern ID oj_readpartial_id;
|
@@ -379,10 +375,16 @@ extern bool oj_use_hash_alt;
|
|
379
375
|
extern bool oj_use_array_alt;
|
380
376
|
extern bool string_writer_optimized;
|
381
377
|
|
378
|
+
static inline VALUE oj_safe_string_convert(VALUE obj) {
|
379
|
+
VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
380
|
+
StringValue(rstr);
|
381
|
+
return rstr;
|
382
|
+
}
|
383
|
+
|
382
384
|
#define APPEND_CHARS(buffer, chars, size) \
|
383
|
-
{
|
384
|
-
memcpy(buffer, chars, size);
|
385
|
-
buffer += size;
|
385
|
+
{ \
|
386
|
+
memcpy(buffer, chars, size); \
|
387
|
+
buffer += size; \
|
386
388
|
}
|
387
389
|
|
388
390
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|