oj 3.14.2 → 3.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -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 +1 -1
  13. data/ext/oj/debug.c +3 -9
  14. data/ext/oj/dump.c +16 -16
  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 +18 -24
  29. data/ext/oj/object.c +5 -5
  30. data/ext/oj/odd.c +2 -1
  31. data/ext/oj/odd.h +4 -4
  32. data/ext/oj/oj.c +60 -81
  33. data/ext/oj/oj.h +53 -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 +7 -13
  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 +7 -9
  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 +0 -1
  67. data/test/_test_active.rb +0 -1
  68. data/test/_test_active_mimic.rb +0 -1
  69. data/test/_test_mimic_rails.rb +0 -1
  70. data/test/activerecord/result_test.rb +5 -6
  71. data/test/bar.rb +3 -3
  72. data/test/files.rb +1 -1
  73. data/test/foo.rb +5 -48
  74. data/test/helper.rb +1 -4
  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 +7 -7
  86. data/test/perf.rb +2 -2
  87. data/test/perf_compat.rb +1 -1
  88. data/test/perf_fast.rb +1 -1
  89. data/test/perf_file.rb +2 -2
  90. data/test/perf_object.rb +1 -2
  91. data/test/perf_once.rb +4 -4
  92. data/test/perf_parser.rb +1 -2
  93. data/test/perf_saj.rb +1 -2
  94. data/test/perf_scp.rb +1 -1
  95. data/test/perf_simple.rb +3 -3
  96. data/test/perf_strict.rb +1 -1
  97. data/test/perf_wab.rb +1 -1
  98. data/test/sample/change.rb +0 -1
  99. data/test/sample/dir.rb +0 -1
  100. data/test/sample/doc.rb +0 -1
  101. data/test/sample/file.rb +0 -1
  102. data/test/sample/group.rb +0 -1
  103. data/test/sample/hasprops.rb +0 -1
  104. data/test/sample/layer.rb +0 -1
  105. data/test/sample/rect.rb +0 -1
  106. data/test/sample/shape.rb +0 -1
  107. data/test/sample/text.rb +0 -1
  108. data/test/sample.rb +2 -3
  109. data/test/sample_json.rb +0 -1
  110. data/test/test_compat.rb +11 -9
  111. data/test/test_custom.rb +5 -9
  112. data/test/test_debian.rb +1 -1
  113. data/test/test_fast.rb +10 -20
  114. data/test/test_file.rb +8 -8
  115. data/test/test_integer_range.rb +2 -2
  116. data/test/test_null.rb +5 -3
  117. data/test/test_object.rb +6 -5
  118. data/test/test_parser_saj.rb +23 -21
  119. data/test/test_parser_usual.rb +3 -3
  120. data/test/test_saj.rb +2 -0
  121. data/test/test_scp.rb +6 -6
  122. data/test/test_strict.rb +6 -4
  123. data/test/test_various.rb +21 -24
  124. data/test/test_wab.rb +6 -5
  125. data/test/test_writer.rb +1 -1
  126. metadata +17 -26
  127. data/test/activesupport4/decoding_test.rb +0 -108
  128. data/test/activesupport4/encoding_test.rb +0 -531
  129. data/test/activesupport4/test_helper.rb +0 -41
  130. data/test/activesupport5/abstract_unit.rb +0 -45
  131. data/test/activesupport5/decoding_test.rb +0 -133
  132. data/test/activesupport5/encoding_test.rb +0 -500
  133. data/test/activesupport5/encoding_test_cases.rb +0 -98
  134. data/test/activesupport5/test_helper.rb +0 -72
  135. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
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().
@@ -125,40 +125,40 @@ typedef struct _dumpOpts {
125
125
  char nan_dump; // NanDump
126
126
  bool omit_nil;
127
127
  int max_depth;
128
- } * DumpOpts;
128
+ } *DumpOpts;
129
129
 
130
130
  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
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
159
159
  int64_t int_range_min; // dump numbers below as string
160
160
  int64_t int_range_max; // dump numbers above as string
161
- const char * create_id; // 0 or string
161
+ const char *create_id; // 0 or string
162
162
  size_t create_id_len; // length of create_id
163
163
  int sec_prec; // second precision when dumping time
164
164
  char float_prec; // float precision, linked to float_fmt
@@ -167,8 +167,8 @@ typedef struct _options {
167
167
  VALUE array_class; // class to use in place of Array on load
168
168
  struct _dumpOpts dump_opts;
169
169
  struct _rxClass str_rx;
170
- VALUE * ignore; // Qnil terminated array of classes or NULL
171
- } * Options;
170
+ VALUE *ignore; // Qnil terminated array of classes or NULL
171
+ } *Options;
172
172
 
173
173
  struct _out;
174
174
  typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
@@ -178,19 +178,19 @@ typedef struct _rOpt {
178
178
  VALUE clas;
179
179
  bool on;
180
180
  DumpFunc dump;
181
- } * ROpt;
181
+ } *ROpt;
182
182
 
183
183
  typedef struct _rOptTable {
184
184
  int len;
185
185
  int alen;
186
186
  ROpt table;
187
- } * ROptTable;
187
+ } *ROptTable;
188
188
 
189
189
  typedef struct _out {
190
190
  char stack_buffer[4096];
191
- char * buf;
192
- char * end;
193
- char * cur;
191
+ char *buf;
192
+ char *end;
193
+ char *cur;
194
194
  Cache8 circ_cache;
195
195
  slot_t circ_cnt;
196
196
  int indent;
@@ -200,20 +200,20 @@ typedef struct _out {
200
200
  bool allocated;
201
201
  bool omit_nil;
202
202
  int argc;
203
- VALUE * argv;
203
+ VALUE *argv;
204
204
  DumpCaller caller; // used for the mimic json only
205
205
  ROptTable ropts;
206
- } * Out;
206
+ } *Out;
207
207
 
208
208
  typedef struct _strWriter {
209
209
  struct _out out;
210
210
  struct _options opts;
211
211
  int depth;
212
- char * types; // DumpType
213
- char * types_end;
212
+ char *types; // DumpType
213
+ char *types_end;
214
214
  int keyWritten;
215
215
 
216
- } * StrWriter;
216
+ } *StrWriter;
217
217
 
218
218
  typedef struct _streamWriter {
219
219
  struct _strWriter sw;
@@ -221,7 +221,7 @@ typedef struct _streamWriter {
221
221
  VALUE stream;
222
222
  int fd;
223
223
  int flush_limit; // indicator of when to flush
224
- } * StreamWriter;
224
+ } *StreamWriter;
225
225
 
226
226
  enum { NO_VAL = 0x00, STR_VAL = 0x01, COL_VAL = 0x02, RUBY_VAL = 0x03 };
227
227
 
@@ -232,14 +232,14 @@ typedef struct _leaf {
232
232
  size_t index; // array index, 0 is not set
233
233
  };
234
234
  union {
235
- char * str; // pointer to location in json string or allocated
235
+ char *str; // pointer to location in json string or allocated
236
236
  struct _leaf *elements; // array and hash elements
237
237
  VALUE value;
238
238
  };
239
239
  uint8_t rtype;
240
240
  uint8_t parent_type;
241
241
  uint8_t value_type;
242
- } * Leaf;
242
+ } *Leaf;
243
243
 
244
244
  extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
245
245
  extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
@@ -261,8 +261,7 @@ extern bool oj_hash_has_key(VALUE hash, VALUE key);
261
261
  extern void oj_parse_options(VALUE ropts, Options copts);
262
262
 
263
263
  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);
264
+ extern void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
266
265
  extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
267
266
  extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
268
267
  extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
@@ -293,7 +292,7 @@ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
293
292
 
294
293
  extern VALUE Oj;
295
294
  extern struct _options oj_default_options;
296
- extern rb_encoding * oj_utf8_encoding;
295
+ extern rb_encoding *oj_utf8_encoding;
297
296
  extern int oj_utf8_encoding_index;
298
297
 
299
298
  extern VALUE oj_bag_class;
@@ -386,9 +385,9 @@ static inline VALUE oj_safe_string_convert(VALUE obj) {
386
385
  }
387
386
 
388
387
  #define APPEND_CHARS(buffer, chars, size) \
389
- { \
390
- memcpy(buffer, chars, size); \
391
- buffer += size; \
388
+ { \
389
+ memcpy(buffer, chars, size); \
390
+ buffer += size; \
392
391
  }
393
392
 
394
393
  #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
 
data/ext/oj/parser.c CHANGED
@@ -20,7 +20,7 @@
20
20
  #define FRAC_LIMIT 10000000000000000ULL
21
21
 
22
22
  // Give better performance with indented JSON but worse with unindented.
23
- //#define SPACE_JUMP
23
+ // #define SPACE_JUMP
24
24
 
25
25
  enum {
26
26
  SKIP_CHAR = 'a',
@@ -1180,7 +1180,7 @@ static int opt_cb(VALUE rkey, VALUE value, VALUE ptr) {
1180
1180
  rkey = rb_sym2str(rkey);
1181
1181
  // fall through
1182
1182
  case RUBY_T_STRING:
1183
- key = rb_string_value_ptr(&rkey);
1183
+ key = StringValuePtr(rkey);
1184
1184
  klen = RSTRING_LEN(rkey);
1185
1185
  break;
1186
1186
  default: rb_raise(rb_eArgError, "option keys must be a symbol or string");
@@ -1349,7 +1349,7 @@ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) {
1349
1349
  case RUBY_T_SYMBOL:
1350
1350
  rkey = rb_sym2str(rkey);
1351
1351
  // fall through
1352
- case RUBY_T_STRING: key = rb_string_value_ptr(&rkey); break;
1352
+ case RUBY_T_STRING: key = StringValuePtr(rkey); break;
1353
1353
  default: rb_raise(rb_eArgError, "option method must be a symbol or string");
1354
1354
  }
1355
1355
  if (1 < argc) {
@@ -1366,12 +1366,12 @@ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) {
1366
1366
  * Returns the result according to the delegate of the parser.
1367
1367
  */
1368
1368
  static VALUE parser_parse(VALUE self, VALUE json) {
1369
- ojParser p = (ojParser)DATA_PTR(self);
1369
+ ojParser p = (ojParser)DATA_PTR(self);
1370
+ const byte *ptr = (const byte *)StringValuePtr(json);
1370
1371
 
1371
- Check_Type(json, T_STRING);
1372
1372
  parser_reset(p);
1373
1373
  p->start(p);
1374
- parse(p, (const byte *)rb_string_value_ptr(&json));
1374
+ parse(p, ptr);
1375
1375
 
1376
1376
  return p->result(p);
1377
1377
  }
@@ -1424,8 +1424,7 @@ static VALUE parser_file(VALUE self, VALUE filename) {
1424
1424
  const char *path;
1425
1425
  int fd;
1426
1426
 
1427
- Check_Type(filename, T_STRING);
1428
- path = rb_string_value_ptr(&filename);
1427
+ path = StringValuePtr(filename);
1429
1428
 
1430
1429
  parser_reset(p);
1431
1430
  p->start(p);