oj 3.14.2 → 3.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +0 -1
  4. data/ext/oj/buf.h +2 -2
  5. data/ext/oj/cache.c +16 -16
  6. data/ext/oj/cache8.c +7 -7
  7. data/ext/oj/circarray.c +2 -1
  8. data/ext/oj/circarray.h +2 -2
  9. data/ext/oj/code.c +2 -2
  10. data/ext/oj/code.h +2 -2
  11. data/ext/oj/compat.c +6 -14
  12. data/ext/oj/custom.c +6 -16
  13. data/ext/oj/debug.c +3 -9
  14. data/ext/oj/dump.c +43 -18
  15. data/ext/oj/dump_compat.c +551 -576
  16. data/ext/oj/dump_leaf.c +3 -5
  17. data/ext/oj/dump_object.c +35 -36
  18. data/ext/oj/dump_strict.c +2 -4
  19. data/ext/oj/encoder.c +1 -1
  20. data/ext/oj/err.c +2 -13
  21. data/ext/oj/err.h +9 -12
  22. data/ext/oj/extconf.rb +1 -1
  23. data/ext/oj/fast.c +24 -38
  24. data/ext/oj/intern.c +38 -42
  25. data/ext/oj/intern.h +3 -7
  26. data/ext/oj/mem.c +211 -217
  27. data/ext/oj/mem.h +10 -10
  28. data/ext/oj/mimic_json.c +39 -24
  29. data/ext/oj/object.c +12 -26
  30. data/ext/oj/odd.c +2 -1
  31. data/ext/oj/odd.h +4 -4
  32. data/ext/oj/oj.c +80 -81
  33. data/ext/oj/oj.h +56 -54
  34. data/ext/oj/parse.c +55 -118
  35. data/ext/oj/parse.h +5 -10
  36. data/ext/oj/parser.c +7 -8
  37. data/ext/oj/parser.h +7 -8
  38. data/ext/oj/rails.c +28 -59
  39. data/ext/oj/reader.c +5 -9
  40. data/ext/oj/reader.h +1 -1
  41. data/ext/oj/resolve.c +3 -4
  42. data/ext/oj/rxclass.c +1 -1
  43. data/ext/oj/rxclass.h +1 -1
  44. data/ext/oj/saj.c +4 -4
  45. data/ext/oj/saj2.c +32 -49
  46. data/ext/oj/saj2.h +1 -1
  47. data/ext/oj/scp.c +3 -14
  48. data/ext/oj/sparse.c +18 -67
  49. data/ext/oj/stream_writer.c +5 -18
  50. data/ext/oj/strict.c +16 -40
  51. data/ext/oj/string_writer.c +6 -14
  52. data/ext/oj/trace.h +27 -16
  53. data/ext/oj/usual.c +62 -61
  54. data/ext/oj/usual.h +6 -6
  55. data/ext/oj/util.h +1 -1
  56. data/ext/oj/val_stack.h +4 -4
  57. data/ext/oj/wab.c +16 -36
  58. data/lib/oj/active_support_helper.rb +0 -1
  59. data/lib/oj/bag.rb +7 -1
  60. data/lib/oj/easy_hash.rb +4 -5
  61. data/lib/oj/error.rb +0 -1
  62. data/lib/oj/json.rb +4 -2
  63. data/lib/oj/mimic.rb +4 -2
  64. data/lib/oj/state.rb +8 -5
  65. data/lib/oj/version.rb +1 -2
  66. data/lib/oj.rb +2 -0
  67. data/pages/Options.md +4 -0
  68. data/test/_test_active.rb +8 -9
  69. data/test/_test_active_mimic.rb +7 -8
  70. data/test/_test_mimic_rails.rb +17 -20
  71. data/test/activerecord/result_test.rb +5 -6
  72. data/test/files.rb +15 -15
  73. data/test/foo.rb +9 -52
  74. data/test/helper.rb +5 -8
  75. data/test/isolated/shared.rb +3 -2
  76. data/test/json_gem/json_addition_test.rb +2 -2
  77. data/test/json_gem/json_common_interface_test.rb +4 -4
  78. data/test/json_gem/json_encoding_test.rb +0 -0
  79. data/test/json_gem/json_ext_parser_test.rb +1 -0
  80. data/test/json_gem/json_fixtures_test.rb +3 -2
  81. data/test/json_gem/json_generator_test.rb +43 -32
  82. data/test/json_gem/json_generic_object_test.rb +11 -11
  83. data/test/json_gem/json_parser_test.rb +46 -46
  84. data/test/json_gem/json_string_matching_test.rb +9 -9
  85. data/test/mem.rb +13 -12
  86. data/test/perf.rb +21 -26
  87. data/test/perf_compat.rb +31 -33
  88. data/test/perf_dump.rb +25 -25
  89. data/test/perf_fast.rb +80 -82
  90. data/test/perf_file.rb +27 -29
  91. data/test/perf_object.rb +65 -69
  92. data/test/perf_once.rb +12 -11
  93. data/test/perf_parser.rb +41 -48
  94. data/test/perf_saj.rb +46 -54
  95. data/test/perf_scp.rb +57 -69
  96. data/test/perf_simple.rb +41 -39
  97. data/test/perf_strict.rb +68 -70
  98. data/test/perf_wab.rb +67 -69
  99. data/test/prec.rb +3 -3
  100. data/test/sample/change.rb +0 -1
  101. data/test/sample/dir.rb +0 -1
  102. data/test/sample/doc.rb +0 -1
  103. data/test/sample/file.rb +0 -1
  104. data/test/sample/group.rb +0 -1
  105. data/test/sample/hasprops.rb +0 -1
  106. data/test/sample/layer.rb +0 -1
  107. data/test/sample/rect.rb +0 -1
  108. data/test/sample/shape.rb +0 -1
  109. data/test/sample/text.rb +0 -1
  110. data/test/sample.rb +16 -16
  111. data/test/sample_json.rb +8 -8
  112. data/test/test_compat.rb +52 -52
  113. data/test/test_custom.rb +61 -51
  114. data/test/test_debian.rb +7 -10
  115. data/test/test_fast.rb +86 -90
  116. data/test/test_file.rb +24 -29
  117. data/test/test_gc.rb +5 -5
  118. data/test/test_generate.rb +5 -5
  119. data/test/test_hash.rb +4 -4
  120. data/test/test_integer_range.rb +9 -9
  121. data/test/test_null.rb +20 -20
  122. data/test/test_object.rb +78 -87
  123. data/test/test_parser.rb +4 -4
  124. data/test/test_parser_debug.rb +4 -4
  125. data/test/test_parser_saj.rb +27 -25
  126. data/test/test_parser_usual.rb +6 -6
  127. data/test/test_rails.rb +2 -2
  128. data/test/test_saj.rb +10 -8
  129. data/test/test_scp.rb +35 -35
  130. data/test/test_strict.rb +28 -32
  131. data/test/test_various.rb +140 -97
  132. data/test/test_wab.rb +46 -44
  133. data/test/test_writer.rb +47 -47
  134. data/test/tests.rb +7 -7
  135. data/test/tests_mimic.rb +6 -6
  136. data/test/tests_mimic_addition.rb +6 -6
  137. metadata +18 -30
  138. data/test/activesupport4/decoding_test.rb +0 -108
  139. data/test/activesupport4/encoding_test.rb +0 -531
  140. data/test/activesupport4/test_helper.rb +0 -41
  141. data/test/activesupport5/abstract_unit.rb +0 -45
  142. data/test/activesupport5/decoding_test.rb +0 -133
  143. data/test/activesupport5/encoding_test.rb +0 -500
  144. data/test/activesupport5/encoding_test_cases.rb +0 -98
  145. data/test/activesupport5/test_helper.rb +0 -72
  146. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  147. data/test/bar.rb +0 -11
  148. data/test/baz.rb +0 -16
  149. data/test/bug.rb +0 -16
  150. 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
- // To avoid using ruby_snprintf with C99.
44
- #undef snprintf
45
- #include <stdio.h>
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().
@@ -124,41 +124,42 @@ typedef struct _dumpOpts {
124
124
  uint8_t array_size;
125
125
  char nan_dump; // NanDump
126
126
  bool omit_nil;
127
+ bool omit_null_byte;
127
128
  int max_depth;
128
- } * DumpOpts;
129
+ } *DumpOpts;
129
130
 
130
131
  typedef struct _options {
131
- int indent; // indention for dump, default 2
132
- char circular; // YesNo
133
- char auto_define; // YesNo
134
- char sym_key; // YesNo
135
- char escape_mode; // Escape_Mode
136
- char mode; // Mode
137
- char class_cache; // YesNo
138
- char time_format; // TimeFormat
139
- char bigdec_as_num; // YesNo
140
- char bigdec_load; // BigLoad
141
- char compat_bigdec; // boolean (0 or 1)
142
- char to_hash; // YesNo
143
- char to_json; // YesNo
144
- char as_json; // YesNo
145
- char raw_json; // YesNo
146
- char nilnil; // YesNo
147
- char empty_string; // YesNo
148
- char allow_gc; // allow GC during parse
149
- char quirks_mode; // allow single JSON values instead of documents
150
- char allow_invalid; // YesNo - allow invalid unicode
151
- char create_ok; // YesNo allow create_id
152
- char allow_nan; // YEsyNo for parsing only
153
- char trace; // YesNo
154
- char safe; // YesNo
155
- char sec_prec_set; // boolean (0 or 1)
156
- char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
157
- char cache_keys; // YesNo
158
- char cache_str; // string short than or equal to this are cache
132
+ int indent; // indention for dump, default 2
133
+ char circular; // YesNo
134
+ char auto_define; // YesNo
135
+ char sym_key; // YesNo
136
+ char escape_mode; // Escape_Mode
137
+ char mode; // Mode
138
+ char class_cache; // YesNo
139
+ char time_format; // TimeFormat
140
+ char bigdec_as_num; // YesNo
141
+ char bigdec_load; // BigLoad
142
+ char compat_bigdec; // boolean (0 or 1)
143
+ char to_hash; // YesNo
144
+ char to_json; // YesNo
145
+ char as_json; // YesNo
146
+ char raw_json; // YesNo
147
+ char nilnil; // YesNo
148
+ char empty_string; // YesNo
149
+ char allow_gc; // allow GC during parse
150
+ char quirks_mode; // allow single JSON values instead of documents
151
+ char allow_invalid; // YesNo - allow invalid unicode
152
+ char create_ok; // YesNo allow create_id
153
+ char allow_nan; // YEsyNo for parsing only
154
+ char trace; // YesNo
155
+ char safe; // YesNo
156
+ char sec_prec_set; // boolean (0 or 1)
157
+ char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
158
+ char cache_keys; // YesNo
159
+ char cache_str; // string short than or equal to this are cache
159
160
  int64_t int_range_min; // dump numbers below as string
160
161
  int64_t int_range_max; // dump numbers above as string
161
- const char * create_id; // 0 or string
162
+ const char *create_id; // 0 or string
162
163
  size_t create_id_len; // length of create_id
163
164
  int sec_prec; // second precision when dumping time
164
165
  char float_prec; // float precision, linked to float_fmt
@@ -167,8 +168,8 @@ typedef struct _options {
167
168
  VALUE array_class; // class to use in place of Array on load
168
169
  struct _dumpOpts dump_opts;
169
170
  struct _rxClass str_rx;
170
- VALUE * ignore; // Qnil terminated array of classes or NULL
171
- } * Options;
171
+ VALUE *ignore; // Qnil terminated array of classes or NULL
172
+ } *Options;
172
173
 
173
174
  struct _out;
174
175
  typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
@@ -178,19 +179,19 @@ typedef struct _rOpt {
178
179
  VALUE clas;
179
180
  bool on;
180
181
  DumpFunc dump;
181
- } * ROpt;
182
+ } *ROpt;
182
183
 
183
184
  typedef struct _rOptTable {
184
185
  int len;
185
186
  int alen;
186
187
  ROpt table;
187
- } * ROptTable;
188
+ } *ROptTable;
188
189
 
189
190
  typedef struct _out {
190
191
  char stack_buffer[4096];
191
- char * buf;
192
- char * end;
193
- char * cur;
192
+ char *buf;
193
+ char *end;
194
+ char *cur;
194
195
  Cache8 circ_cache;
195
196
  slot_t circ_cnt;
196
197
  int indent;
@@ -199,21 +200,22 @@ typedef struct _out {
199
200
  uint32_t hash_cnt;
200
201
  bool allocated;
201
202
  bool omit_nil;
203
+ bool omit_null_byte;
202
204
  int argc;
203
- VALUE * argv;
205
+ VALUE *argv;
204
206
  DumpCaller caller; // used for the mimic json only
205
207
  ROptTable ropts;
206
- } * Out;
208
+ } *Out;
207
209
 
208
210
  typedef struct _strWriter {
209
211
  struct _out out;
210
212
  struct _options opts;
211
213
  int depth;
212
- char * types; // DumpType
213
- char * types_end;
214
+ char *types; // DumpType
215
+ char *types_end;
214
216
  int keyWritten;
215
217
 
216
- } * StrWriter;
218
+ } *StrWriter;
217
219
 
218
220
  typedef struct _streamWriter {
219
221
  struct _strWriter sw;
@@ -221,7 +223,7 @@ typedef struct _streamWriter {
221
223
  VALUE stream;
222
224
  int fd;
223
225
  int flush_limit; // indicator of when to flush
224
- } * StreamWriter;
226
+ } *StreamWriter;
225
227
 
226
228
  enum { NO_VAL = 0x00, STR_VAL = 0x01, COL_VAL = 0x02, RUBY_VAL = 0x03 };
227
229
 
@@ -232,14 +234,14 @@ typedef struct _leaf {
232
234
  size_t index; // array index, 0 is not set
233
235
  };
234
236
  union {
235
- char * str; // pointer to location in json string or allocated
237
+ char *str; // pointer to location in json string or allocated
236
238
  struct _leaf *elements; // array and hash elements
237
239
  VALUE value;
238
240
  };
239
241
  uint8_t rtype;
240
242
  uint8_t parent_type;
241
243
  uint8_t value_type;
242
- } * Leaf;
244
+ } *Leaf;
243
245
 
244
246
  extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
245
247
  extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
@@ -261,8 +263,7 @@ extern bool oj_hash_has_key(VALUE hash, VALUE key);
261
263
  extern void oj_parse_options(VALUE ropts, Options copts);
262
264
 
263
265
  extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
264
- extern void
265
- oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
266
+ extern void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
266
267
  extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
267
268
  extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
268
269
  extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
@@ -293,7 +294,7 @@ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
293
294
 
294
295
  extern VALUE Oj;
295
296
  extern struct _options oj_default_options;
296
- extern rb_encoding * oj_utf8_encoding;
297
+ extern rb_encoding *oj_utf8_encoding;
297
298
  extern int oj_utf8_encoding_index;
298
299
 
299
300
  extern VALUE oj_bag_class;
@@ -324,6 +325,7 @@ extern VALUE oj_max_nesting_sym;
324
325
  extern VALUE oj_object_class_sym;
325
326
  extern VALUE oj_object_nl_sym;
326
327
  extern VALUE oj_quirks_mode_sym;
328
+ extern VALUE oj_skip_null_byte_sym;
327
329
  extern VALUE oj_space_before_sym;
328
330
  extern VALUE oj_space_sym;
329
331
  extern VALUE oj_symbolize_names_sym;
@@ -386,9 +388,9 @@ static inline VALUE oj_safe_string_convert(VALUE obj) {
386
388
  }
387
389
 
388
390
  #define APPEND_CHARS(buffer, chars, size) \
389
- { \
390
- memcpy(buffer, chars, size); \
391
- buffer += size; \
391
+ { \
392
+ memcpy(buffer, chars, size); \
393
+ buffer += size; \
392
394
  }
393
395
 
394
396
  #ifdef HAVE_PTHREAD_MUTEX_INIT
data/ext/oj/parse.c CHANGED
@@ -10,9 +10,9 @@
10
10
  #include <string.h>
11
11
  #include <unistd.h>
12
12
 
13
- #include "mem.h"
14
13
  #include "buf.h"
15
14
  #include "encode.h"
15
+ #include "mem.h"
16
16
  #include "oj.h"
17
17
  #include "rxclass.h"
18
18
  #include "val_stack.h"
@@ -24,7 +24,7 @@
24
24
  // Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
25
25
  #define OJ_INFINITY (1.0 / 0.0)
26
26
 
27
- //#define EXP_MAX 1023
27
+ // #define EXP_MAX 1023
28
28
  #define EXP_MAX 100000
29
29
  #define DEC_MAX 15
30
30
 
@@ -49,11 +49,7 @@ static void skip_comment(ParseInfo pi) {
49
49
  pi->cur += 2;
50
50
  return;
51
51
  } else if (pi->end <= pi->cur) {
52
- oj_set_error_at(pi,
53
- oj_parse_error_class,
54
- __FILE__,
55
- __LINE__,
56
- "comment not terminated");
52
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "comment not terminated");
57
53
  return;
58
54
  }
59
55
  }
@@ -86,8 +82,7 @@ static void add_value(ParseInfo pi, VALUE rval) {
86
82
  break;
87
83
  case NEXT_HASH_VALUE:
88
84
  pi->hash_set_value(pi, parent, rval);
89
- if (0 != parent->key && 0 < parent->klen &&
90
- (parent->key < pi->json || pi->cur < parent->key)) {
85
+ if (0 != parent->key && 0 < parent->klen && (parent->key < pi->json || pi->cur < parent->key)) {
91
86
  OJ_R_FREE((char *)parent->key);
92
87
  parent->key = 0;
93
88
  }
@@ -200,14 +195,18 @@ static inline const char *scan_string_noSIMD(const char *str, const char *end) {
200
195
  #ifdef OJ_USE_SSE4_2
201
196
  static inline const char *scan_string_SIMD(const char *str, const char *end) {
202
197
  static const char chars[16] = "\x00\\\"";
203
- const __m128i terminate = _mm_loadu_si128((const __m128i *)&chars[0]);
204
- const char *_end = (const char *)(end - 16);
198
+ const __m128i terminate = _mm_loadu_si128((const __m128i *)&chars[0]);
199
+ const char *_end = (const char *)(end - 16);
205
200
 
206
201
  for (; str <= _end; str += 16) {
207
202
  const __m128i string = _mm_loadu_si128((const __m128i *)str);
208
- const int r = _mm_cmpestri(terminate, 3, string, 16, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT);
203
+ const int r = _mm_cmpestri(terminate,
204
+ 3,
205
+ string,
206
+ 16,
207
+ _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT);
209
208
  if (r != 16) {
210
- str = (char*)(str + r);
209
+ str = (char *)(str + r);
211
210
  return str;
212
211
  }
213
212
  }
@@ -216,7 +215,7 @@ static inline const char *scan_string_SIMD(const char *str, const char *end) {
216
215
  }
217
216
  #endif
218
217
 
219
- static const char *(*scan_func) (const char *str, const char *end) = scan_string_noSIMD;
218
+ static const char *(*scan_func)(const char *str, const char *end) = scan_string_noSIMD;
220
219
 
221
220
  void oj_scanner_init(void) {
222
221
  #ifdef OJ_USE_SSE4_2
@@ -238,12 +237,8 @@ static void read_escaped_str(ParseInfo pi, const char *start) {
238
237
  for (s = pi->cur; '"' != *s;) {
239
238
  const char *scanned = scan_func(s, pi->end);
240
239
  if (scanned >= pi->end || '\0' == *scanned) {
241
- //if (scanned >= pi->end) {
242
- oj_set_error_at(pi,
243
- oj_parse_error_class,
244
- __FILE__,
245
- __LINE__,
246
- "quoted string not terminated");
240
+ // if (scanned >= pi->end) {
241
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "quoted string not terminated");
247
242
  buf_cleanup(&buf);
248
243
  return;
249
244
  }
@@ -280,11 +275,7 @@ static void read_escaped_str(ParseInfo pi, const char *start) {
280
275
  break;
281
276
  }
282
277
  pi->cur = s;
283
- oj_set_error_at(pi,
284
- oj_parse_error_class,
285
- __FILE__,
286
- __LINE__,
287
- "invalid escaped character");
278
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
288
279
  buf_cleanup(&buf);
289
280
  return;
290
281
  }
@@ -311,11 +302,7 @@ static void read_escaped_str(ParseInfo pi, const char *start) {
311
302
  break;
312
303
  }
313
304
  pi->cur = s;
314
- oj_set_error_at(pi,
315
- oj_parse_error_class,
316
- __FILE__,
317
- __LINE__,
318
- "invalid escaped character");
305
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
319
306
  buf_cleanup(&buf);
320
307
  return;
321
308
  }
@@ -347,8 +334,7 @@ static void read_escaped_str(ParseInfo pi, const char *start) {
347
334
  break;
348
335
  case NEXT_HASH_VALUE:
349
336
  pi->hash_set_cstr(pi, parent, buf.head, buf_len(&buf), start);
350
- if (0 != parent->key && 0 < parent->klen &&
351
- (parent->key < pi->json || pi->cur < parent->key)) {
337
+ if (0 != parent->key && 0 < parent->klen && (parent->key < pi->json || pi->cur < parent->key)) {
352
338
  OJ_R_FREE((char *)parent->key);
353
339
  parent->key = 0;
354
340
  }
@@ -378,11 +364,7 @@ static void read_str(ParseInfo pi) {
378
364
 
379
365
  pi->cur = scan_func(pi->cur, pi->end);
380
366
  if (RB_UNLIKELY(pi->end <= pi->cur)) {
381
- oj_set_error_at(pi,
382
- oj_parse_error_class,
383
- __FILE__,
384
- __LINE__,
385
- "quoted string not terminated");
367
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "quoted string not terminated");
386
368
  return;
387
369
  }
388
370
  if (RB_UNLIKELY('\0' == *pi->cur)) {
@@ -417,8 +399,7 @@ static void read_str(ParseInfo pi) {
417
399
  break;
418
400
  case NEXT_HASH_VALUE:
419
401
  pi->hash_set_cstr(pi, parent, str, pi->cur - str, str);
420
- if (0 != parent->key && 0 < parent->klen &&
421
- (parent->key < pi->json || pi->cur < parent->key)) {
402
+ if (0 != parent->key && 0 < parent->klen && (parent->key < pi->json || pi->cur < parent->key)) {
422
403
  OJ_R_FREE((char *)parent->key);
423
404
  parent->key = 0;
424
405
  }
@@ -461,7 +442,7 @@ static void read_num(ParseInfo pi) {
461
442
  ni.no_big = !pi->options.compat_bigdec;
462
443
  ni.bigdec_load = pi->options.compat_bigdec;
463
444
  } else {
464
- ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load ||
445
+ ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load ||
465
446
  RubyDec == pi->options.bigdec_load);
466
447
  ni.bigdec_load = pi->options.bigdec_load;
467
448
  }
@@ -471,33 +452,21 @@ static void read_num(ParseInfo pi) {
471
452
  ni.neg = 1;
472
453
  } else if ('+' == *pi->cur) {
473
454
  if (StrictMode == pi->options.mode) {
474
- oj_set_error_at(pi,
475
- oj_parse_error_class,
476
- __FILE__,
477
- __LINE__,
478
- "not a number or other value");
455
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
479
456
  return;
480
457
  }
481
458
  pi->cur++;
482
459
  }
483
460
  if ('I' == *pi->cur) {
484
461
  if (No == pi->options.allow_nan || 0 != strncmp("Infinity", pi->cur, 8)) {
485
- oj_set_error_at(pi,
486
- oj_parse_error_class,
487
- __FILE__,
488
- __LINE__,
489
- "not a number or other value");
462
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
490
463
  return;
491
464
  }
492
465
  pi->cur += 8;
493
466
  ni.infinity = 1;
494
467
  } else if ('N' == *pi->cur || 'n' == *pi->cur) {
495
468
  if ('a' != pi->cur[1] || ('N' != pi->cur[2] && 'n' != pi->cur[2])) {
496
- oj_set_error_at(pi,
497
- oj_parse_error_class,
498
- __FILE__,
499
- __LINE__,
500
- "not a number or other value");
469
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
501
470
  return;
502
471
  }
503
472
  pi->cur += 3;
@@ -520,11 +489,7 @@ static void read_num(ParseInfo pi) {
520
489
  ni.i = ni.i * 10 + d;
521
490
  }
522
491
  if (RB_UNLIKELY(0 != ni.i && zero1 && CompatMode == pi->options.mode)) {
523
- oj_set_error_at(pi,
524
- oj_parse_error_class,
525
- __FILE__,
526
- __LINE__,
527
- "not a number");
492
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number");
528
493
  return;
529
494
  }
530
495
  if (INT64_MAX <= ni.i || DEC_MAX < dec_cnt) {
@@ -616,8 +581,7 @@ static void read_num(ParseInfo pi) {
616
581
  break;
617
582
  case NEXT_HASH_VALUE:
618
583
  pi->hash_set_num(pi, parent, &ni);
619
- if (0 != parent->key && 0 < parent->klen &&
620
- (parent->key < pi->json || pi->cur < parent->key)) {
584
+ if (0 != parent->key && 0 < parent->klen && (parent->key < pi->json || pi->cur < parent->key)) {
621
585
  OJ_R_FREE((char *)parent->key);
622
586
  parent->key = 0;
623
587
  }
@@ -751,11 +715,7 @@ void oj_parse2(ParseInfo pi) {
751
715
  // case '+':
752
716
  case '+':
753
717
  if (CompatMode == pi->options.mode) {
754
- oj_set_error_at(pi,
755
- oj_parse_error_class,
756
- __FILE__,
757
- __LINE__,
758
- "unexpected character");
718
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
759
719
  return;
760
720
  }
761
721
  pi->cur--;
@@ -781,11 +741,7 @@ void oj_parse2(ParseInfo pi) {
781
741
  pi->cur--;
782
742
  read_num(pi);
783
743
  } else {
784
- oj_set_error_at(pi,
785
- oj_parse_error_class,
786
- __FILE__,
787
- __LINE__,
788
- "unexpected character");
744
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
789
745
  }
790
746
  break;
791
747
  case 't': read_true(pi); break;
@@ -805,9 +761,7 @@ void oj_parse2(ParseInfo pi) {
805
761
  }
806
762
  break;
807
763
  case '\0': pi->cur--; return;
808
- default:
809
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
810
- return;
764
+ default: oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character"); return;
811
765
  }
812
766
  if (err_has(&pi->err)) {
813
767
  return;
@@ -844,11 +798,10 @@ static VALUE parse_big_decimal(VALUE str) {
844
798
  }
845
799
 
846
800
  static long double exp_plus[] = {
847
- 1.0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8, 1.0e9,
848
- 1.0e10, 1.0e11, 1.0e12, 1.0e13, 1.0e14, 1.0e15, 1.0e16, 1.0e17, 1.0e18, 1.0e19,
849
- 1.0e20, 1.0e21, 1.0e22, 1.0e23, 1.0e24, 1.0e25, 1.0e26, 1.0e27, 1.0e28, 1.0e29,
850
- 1.0e30, 1.0e31, 1.0e32, 1.0e33, 1.0e34, 1.0e35, 1.0e36, 1.0e37, 1.0e38, 1.0e39,
851
- 1.0e40, 1.0e41, 1.0e42, 1.0e43, 1.0e44, 1.0e45, 1.0e46, 1.0e47, 1.0e48, 1.0e49,
801
+ 1.0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8, 1.0e9, 1.0e10, 1.0e11, 1.0e12,
802
+ 1.0e13, 1.0e14, 1.0e15, 1.0e16, 1.0e17, 1.0e18, 1.0e19, 1.0e20, 1.0e21, 1.0e22, 1.0e23, 1.0e24, 1.0e25,
803
+ 1.0e26, 1.0e27, 1.0e28, 1.0e29, 1.0e30, 1.0e31, 1.0e32, 1.0e33, 1.0e34, 1.0e35, 1.0e36, 1.0e37, 1.0e38,
804
+ 1.0e39, 1.0e40, 1.0e41, 1.0e42, 1.0e43, 1.0e44, 1.0e45, 1.0e46, 1.0e47, 1.0e48, 1.0e49,
852
805
  };
853
806
 
854
807
  VALUE
@@ -920,7 +873,7 @@ oj_num_as_value(NumInfo ni) {
920
873
 
921
874
  rnum = rb_funcall(sv, rb_intern("to_f"), 0);
922
875
  } else {
923
- char * end;
876
+ char *end;
924
877
  double d = strtod(ni->str, &end);
925
878
 
926
879
  if ((long)ni->len != (long)(end - ni->str)) {
@@ -932,28 +885,23 @@ oj_num_as_value(NumInfo ni) {
932
885
  return rnum;
933
886
  }
934
887
 
935
- void oj_set_error_at(ParseInfo pi,
936
- VALUE err_clas,
937
- const char *file,
938
- int line,
939
- const char *format,
940
- ...) {
888
+ void oj_set_error_at(ParseInfo pi, VALUE err_clas, const char *file, int line, const char *format, ...) {
941
889
  va_list ap;
942
890
  char msg[256];
943
- char * p = msg;
944
- char * end = p + sizeof(msg) - 2;
945
- char * start;
891
+ char *p = msg;
892
+ char *end = p + sizeof(msg) - 2;
893
+ char *start;
946
894
  Val vp;
947
- int mlen;
895
+ int mlen;
948
896
 
949
897
  va_start(ap, format);
950
898
  mlen = vsnprintf(msg, sizeof(msg) - 1, format, ap);
951
899
  if (0 < mlen) {
952
- if (sizeof(msg) - 2 < (size_t)mlen) {
953
- p = end - 2;
954
- } else {
955
- p += mlen;
956
- }
900
+ if (sizeof(msg) - 2 < (size_t)mlen) {
901
+ p = end - 2;
902
+ } else {
903
+ p += mlen;
904
+ }
957
905
  }
958
906
  va_end(ap);
959
907
  pi->err.clas = err_clas;
@@ -990,14 +938,7 @@ void oj_set_error_at(ParseInfo pi,
990
938
  }
991
939
  *p = '\0';
992
940
  if (0 == pi->json) {
993
- oj_err_set(&pi->err,
994
- err_clas,
995
- "%s at line %d, column %d [%s:%d]",
996
- msg,
997
- pi->rd.line,
998
- pi->rd.col,
999
- file,
1000
- line);
941
+ oj_err_set(&pi->err, err_clas, "%s at line %d, column %d [%s:%d]", msg, pi->rd.line, pi->rd.col, file, line);
1001
942
  } else {
1002
943
  _oj_err_set_with_location(&pi->err, err_clas, msg, pi->json, pi->cur - 1, file, line);
1003
944
  }
@@ -1016,7 +957,7 @@ static void oj_pi_set_input_str(ParseInfo pi, VALUE *inputp) {
1016
957
 
1017
958
  if (oj_utf8_encoding_index != idx) {
1018
959
  rb_encoding *enc = rb_enc_from_index(idx);
1019
- *inputp = rb_str_conv_enc(*inputp, enc, oj_utf8_encoding);
960
+ *inputp = rb_str_conv_enc(*inputp, enc, oj_utf8_encoding);
1020
961
  }
1021
962
  pi->json = RSTRING_PTR(*inputp);
1022
963
  pi->end = pi->json + RSTRING_LEN(*inputp);
@@ -1024,12 +965,12 @@ static void oj_pi_set_input_str(ParseInfo pi, VALUE *inputp) {
1024
965
 
1025
966
  VALUE
1026
967
  oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yieldOk) {
1027
- char * buf = 0;
1028
- VALUE input;
1029
- VALUE wrapped_stack;
1030
- VALUE result = Qnil;
1031
- int line = 0;
1032
- int free_json = 0;
968
+ char *buf = 0;
969
+ VALUE input;
970
+ VALUE wrapped_stack;
971
+ VALUE result = Qnil;
972
+ int line = 0;
973
+ int free_json = 0;
1033
974
 
1034
975
  if (argc < 1) {
1035
976
  rb_raise(rb_eArgError, "Wrong number of arguments to parse.");
@@ -1089,8 +1030,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
1089
1030
  }
1090
1031
  ((char *)pi->json)[len] = '\0';
1091
1032
  /* skip UTF-8 BOM if present */
1092
- if (0xEF == (uint8_t)*pi->json && 0xBB == (uint8_t)pi->json[1] &&
1093
- 0xBF == (uint8_t)pi->json[2]) {
1033
+ if (0xEF == (uint8_t)*pi->json && 0xBB == (uint8_t)pi->json[1] && 0xBF == (uint8_t)pi->json[2]) {
1094
1034
  pi->cur += 3;
1095
1035
  }
1096
1036
  #endif
@@ -1116,8 +1056,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
1116
1056
  wrapped_stack = oj_stack_init(&pi->stack);
1117
1057
  rb_protect(protect_parse, (VALUE)pi, &line);
1118
1058
  if (Qundef == pi->stack.head->val && !empty_ok(&pi->options)) {
1119
- if (No == pi->options.nilnil ||
1120
- (CompatMode == pi->options.mode && 0 < pi->cur - pi->json)) {
1059
+ if (No == pi->options.nilnil || (CompatMode == pi->options.mode && 0 < pi->cur - pi->json)) {
1121
1060
  oj_set_error_at(pi, oj_json_parser_error_class, __FILE__, __LINE__, "Empty input");
1122
1061
  }
1123
1062
  }
@@ -1145,9 +1084,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
1145
1084
  switch (v->next) {
1146
1085
  case NEXT_ARRAY_NEW:
1147
1086
  case NEXT_ARRAY_ELEMENT:
1148
- case NEXT_ARRAY_COMMA:
1149
- oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Array not terminated");
1150
- break;
1087
+ case NEXT_ARRAY_COMMA: oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Array not terminated"); break;
1151
1088
  case NEXT_HASH_NEW:
1152
1089
  case NEXT_HASH_KEY:
1153
1090
  case NEXT_HASH_COLON:
data/ext/oj/parse.h CHANGED
@@ -32,7 +32,7 @@ typedef struct _numInfo {
32
32
  int has_exp;
33
33
  int no_big;
34
34
  int bigdec_load;
35
- } * NumInfo;
35
+ } *NumInfo;
36
36
 
37
37
  typedef struct _parseInfo {
38
38
  // used for the string parser
@@ -54,11 +54,7 @@ typedef struct _parseInfo {
54
54
  VALUE (*start_hash)(struct _parseInfo *pi);
55
55
  void (*end_hash)(struct _parseInfo *pi);
56
56
  VALUE (*hash_key)(struct _parseInfo *pi, const char *key, size_t klen);
57
- void (*hash_set_cstr)(struct _parseInfo *pi,
58
- Val kval,
59
- const char * str,
60
- size_t len,
61
- const char * orig);
57
+ void (*hash_set_cstr)(struct _parseInfo *pi, Val kval, const char *str, size_t len, const char *orig);
62
58
  void (*hash_set_num)(struct _parseInfo *pi, Val kval, NumInfo ni);
63
59
  void (*hash_set_value)(struct _parseInfo *pi, Val kval, VALUE value);
64
60
 
@@ -73,11 +69,10 @@ typedef struct _parseInfo {
73
69
  void (*add_value)(struct _parseInfo *pi, VALUE val);
74
70
  VALUE err_class;
75
71
  bool has_callbacks;
76
- } * ParseInfo;
72
+ } *ParseInfo;
77
73
 
78
- extern void oj_parse2(ParseInfo pi);
79
- extern void
80
- oj_set_error_at(ParseInfo pi, VALUE err_clas, const char *file, int line, const char *format, ...);
74
+ extern void oj_parse2(ParseInfo pi);
75
+ extern void oj_set_error_at(ParseInfo pi, VALUE err_clas, const char *file, int line, const char *format, ...);
81
76
  extern VALUE oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yieldOk);
82
77
  extern VALUE oj_num_as_value(NumInfo ni);
83
78