oj 3.13.17 → 3.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -0
  3. data/README.md +4 -2
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +29 -26
  6. data/ext/oj/cache.h +3 -2
  7. data/ext/oj/cache8.c +10 -9
  8. data/ext/oj/circarray.c +7 -5
  9. data/ext/oj/circarray.h +2 -2
  10. data/ext/oj/code.c +5 -12
  11. data/ext/oj/code.h +2 -2
  12. data/ext/oj/compat.c +20 -60
  13. data/ext/oj/custom.c +44 -96
  14. data/ext/oj/debug.c +3 -9
  15. data/ext/oj/dump.c +69 -39
  16. data/ext/oj/dump.h +1 -4
  17. data/ext/oj/dump_compat.c +557 -592
  18. data/ext/oj/dump_leaf.c +3 -5
  19. data/ext/oj/dump_object.c +42 -48
  20. data/ext/oj/dump_strict.c +10 -22
  21. data/ext/oj/encoder.c +1 -1
  22. data/ext/oj/err.c +2 -13
  23. data/ext/oj/err.h +9 -12
  24. data/ext/oj/extconf.rb +16 -6
  25. data/ext/oj/fast.c +76 -106
  26. data/ext/oj/intern.c +63 -51
  27. data/ext/oj/intern.h +3 -7
  28. data/ext/oj/mem.c +318 -0
  29. data/ext/oj/mem.h +53 -0
  30. data/ext/oj/mimic_json.c +43 -30
  31. data/ext/oj/object.c +61 -70
  32. data/ext/oj/odd.c +8 -6
  33. data/ext/oj/odd.h +4 -4
  34. data/ext/oj/oj.c +243 -205
  35. data/ext/oj/oj.h +82 -78
  36. data/ext/oj/parse.c +123 -188
  37. data/ext/oj/parse.h +23 -24
  38. data/ext/oj/parser.c +103 -63
  39. data/ext/oj/parser.h +19 -9
  40. data/ext/oj/rails.c +68 -92
  41. data/ext/oj/reader.c +10 -15
  42. data/ext/oj/reader.h +4 -2
  43. data/ext/oj/resolve.c +3 -4
  44. data/ext/oj/rxclass.c +6 -5
  45. data/ext/oj/rxclass.h +1 -1
  46. data/ext/oj/saj.c +10 -9
  47. data/ext/oj/saj2.c +74 -92
  48. data/ext/oj/saj2.h +23 -0
  49. data/ext/oj/scp.c +3 -14
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +43 -35
  52. data/ext/oj/strict.c +20 -52
  53. data/ext/oj/string_writer.c +60 -34
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +125 -150
  56. data/ext/oj/usual.h +69 -0
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +14 -3
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/wab.c +25 -57
  61. data/lib/oj/active_support_helper.rb +1 -3
  62. data/lib/oj/bag.rb +7 -1
  63. data/lib/oj/easy_hash.rb +4 -5
  64. data/lib/oj/error.rb +0 -1
  65. data/lib/oj/json.rb +162 -150
  66. data/lib/oj/mimic.rb +6 -2
  67. data/lib/oj/state.rb +9 -6
  68. data/lib/oj/version.rb +1 -2
  69. data/lib/oj.rb +2 -0
  70. data/pages/Compatibility.md +1 -1
  71. data/pages/InstallOptions.md +20 -0
  72. data/pages/Options.md +10 -0
  73. data/test/_test_active.rb +8 -9
  74. data/test/_test_active_mimic.rb +7 -8
  75. data/test/_test_mimic_rails.rb +17 -20
  76. data/test/activerecord/result_test.rb +5 -6
  77. data/test/files.rb +15 -15
  78. data/test/foo.rb +9 -72
  79. data/test/helper.rb +11 -8
  80. data/test/isolated/shared.rb +3 -2
  81. data/test/json_gem/json_addition_test.rb +2 -2
  82. data/test/json_gem/json_common_interface_test.rb +8 -6
  83. data/test/json_gem/json_encoding_test.rb +0 -0
  84. data/test/json_gem/json_ext_parser_test.rb +1 -0
  85. data/test/json_gem/json_fixtures_test.rb +3 -2
  86. data/test/json_gem/json_generator_test.rb +53 -37
  87. data/test/json_gem/json_generic_object_test.rb +11 -11
  88. data/test/json_gem/json_parser_test.rb +47 -47
  89. data/test/json_gem/json_string_matching_test.rb +9 -9
  90. data/test/json_gem/test_helper.rb +7 -3
  91. data/test/mem.rb +13 -12
  92. data/test/perf.rb +21 -26
  93. data/test/perf_compat.rb +31 -33
  94. data/test/perf_dump.rb +28 -28
  95. data/test/perf_fast.rb +80 -82
  96. data/test/perf_file.rb +27 -29
  97. data/test/perf_object.rb +65 -69
  98. data/test/perf_once.rb +12 -11
  99. data/test/perf_parser.rb +42 -48
  100. data/test/perf_saj.rb +46 -54
  101. data/test/perf_scp.rb +57 -69
  102. data/test/perf_simple.rb +41 -39
  103. data/test/perf_strict.rb +68 -70
  104. data/test/perf_wab.rb +67 -69
  105. data/test/prec.rb +5 -5
  106. data/test/sample/change.rb +0 -1
  107. data/test/sample/dir.rb +0 -1
  108. data/test/sample/doc.rb +0 -1
  109. data/test/sample/file.rb +0 -1
  110. data/test/sample/group.rb +0 -1
  111. data/test/sample/hasprops.rb +0 -1
  112. data/test/sample/layer.rb +0 -1
  113. data/test/sample/rect.rb +0 -1
  114. data/test/sample/shape.rb +0 -1
  115. data/test/sample/text.rb +0 -1
  116. data/test/sample.rb +16 -16
  117. data/test/sample_json.rb +8 -8
  118. data/test/test_compat.rb +80 -53
  119. data/test/test_custom.rb +73 -51
  120. data/test/test_debian.rb +7 -10
  121. data/test/test_fast.rb +86 -90
  122. data/test/test_file.rb +28 -35
  123. data/test/test_gc.rb +16 -5
  124. data/test/test_generate.rb +5 -5
  125. data/test/test_hash.rb +4 -4
  126. data/test/test_integer_range.rb +9 -9
  127. data/test/test_null.rb +20 -20
  128. data/test/test_object.rb +94 -96
  129. data/test/test_parser.rb +6 -22
  130. data/test/test_parser_debug.rb +27 -0
  131. data/test/test_parser_saj.rb +61 -22
  132. data/test/test_parser_usual.rb +16 -6
  133. data/test/test_rails.rb +2 -2
  134. data/test/test_saj.rb +10 -8
  135. data/test/test_scp.rb +37 -39
  136. data/test/test_strict.rb +40 -32
  137. data/test/test_various.rb +148 -100
  138. data/test/test_wab.rb +48 -44
  139. data/test/test_writer.rb +47 -47
  140. data/test/tests.rb +13 -4
  141. data/test/tests_mimic.rb +12 -3
  142. data/test/tests_mimic_addition.rb +12 -3
  143. metadata +36 -27
  144. data/test/activesupport4/decoding_test.rb +0 -108
  145. data/test/activesupport4/encoding_test.rb +0 -531
  146. data/test/activesupport4/test_helper.rb +0 -41
  147. data/test/activesupport5/abstract_unit.rb +0 -45
  148. data/test/activesupport5/decoding_test.rb +0 -133
  149. data/test/activesupport5/encoding_test.rb +0 -500
  150. data/test/activesupport5/encoding_test_cases.rb +0 -98
  151. data/test/activesupport5/test_helper.rb +0 -72
  152. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  153. data/test/bar.rb +0 -11
  154. data/test/baz.rb +0 -16
  155. data/test/bug.rb +0 -16
  156. data/test/zoo.rb +0 -13
data/ext/oj/dump_leaf.c CHANGED
@@ -17,9 +17,7 @@ inline static void dump_chars(const char *s, size_t size, Out out) {
17
17
  static void dump_leaf_str(Leaf leaf, Out out) {
18
18
  switch (leaf->value_type) {
19
19
  case STR_VAL: oj_dump_cstr(leaf->str, strlen(leaf->str), 0, 0, out); break;
20
- case RUBY_VAL:
21
- oj_dump_cstr(rb_string_value_cstr(&leaf->value), (int)RSTRING_LEN(leaf->value), 0, 0, out);
22
- break;
20
+ case RUBY_VAL: oj_dump_cstr(StringValueCStr(leaf->value), (int)RSTRING_LEN(leaf->value), 0, 0, out); break;
23
21
  case COL_VAL:
24
22
  default: rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type); break;
25
23
  }
@@ -142,11 +140,11 @@ void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out) {
142
140
  void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
143
141
  struct _out out;
144
142
  size_t size;
145
- FILE * f;
143
+ FILE *f;
146
144
 
147
145
  oj_out_init(&out);
148
146
 
149
- out.omit_nil = copts->dump_opts.omit_nil;
147
+ out.omit_nil = copts->dump_opts.omit_nil;
150
148
  oj_dump_leaf_to_json(leaf, copts, &out);
151
149
  size = out.cur - out.buf;
152
150
  if (0 == (f = fopen(path, "w"))) {
data/ext/oj/dump_object.c CHANGED
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT License. See LICENSE file in the project root for license details.
3
3
 
4
4
  #include "dump.h"
5
+ #include "mem.h"
5
6
  #include "odd.h"
6
7
  #include "trace.h"
7
8
 
@@ -30,8 +31,8 @@ static void dump_data(VALUE obj, int depth, Out out, bool as_ok) {
30
31
  *out->cur = '\0';
31
32
  } else {
32
33
  if (oj_bigdecimal_class == clas) {
33
- volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
34
- const char * str = RSTRING_PTR(rstr);
34
+ volatile VALUE rstr = oj_safe_string_convert(obj);
35
+ const char *str = RSTRING_PTR(rstr);
35
36
  int len = (int)RSTRING_LEN(rstr);
36
37
 
37
38
  if (No != out->opts->bigdec_as_num) {
@@ -59,8 +60,8 @@ static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
59
60
  VALUE clas = rb_obj_class(obj);
60
61
 
61
62
  if (oj_bigdecimal_class == clas) {
62
- volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
63
- const char * str = RSTRING_PTR(rstr);
63
+ volatile VALUE rstr = oj_safe_string_convert(obj);
64
+ const char *str = RSTRING_PTR(rstr);
64
65
  int len = (int)RSTRING_LEN(rstr);
65
66
 
66
67
  if (0 == strcasecmp("Infinity", str)) {
@@ -223,37 +224,36 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
223
224
  oj_dump_obj_val(value, depth, out);
224
225
  break;
225
226
 
226
- default:
227
- {
228
- int d2 = depth + 1;
229
- long s2 = size + out->indent + 1;
230
- int i;
231
- int started = 0;
232
- uint8_t b;
233
-
234
- assure_size(out, s2 + 15);
235
- APPEND_CHARS(out->cur, "\"^#", 3);
236
- out->hash_cnt++;
237
- for (i = 28; 0 <= i; i -= 4) {
238
- b = (uint8_t)((out->hash_cnt >> i) & 0x0000000F);
239
- if ('\0' != b) {
240
- started = 1;
241
- }
242
- if (started) {
243
- *out->cur++ = hex_chars[b];
244
- }
227
+ default: {
228
+ int d2 = depth + 1;
229
+ long s2 = size + out->indent + 1;
230
+ int i;
231
+ int started = 0;
232
+ uint8_t b;
233
+
234
+ assure_size(out, s2 + 15);
235
+ APPEND_CHARS(out->cur, "\"^#", 3);
236
+ out->hash_cnt++;
237
+ for (i = 28; 0 <= i; i -= 4) {
238
+ b = (uint8_t)((out->hash_cnt >> i) & 0x0000000F);
239
+ if ('\0' != b) {
240
+ started = 1;
241
+ }
242
+ if (started) {
243
+ *out->cur++ = hex_chars[b];
245
244
  }
246
- APPEND_CHARS(out->cur, "\":[", 3);
247
- fill_indent(out, d2);
248
- oj_dump_obj_val(key, d2, out);
249
- assure_size(out, s2);
250
- *out->cur++ = ',';
251
- fill_indent(out, d2);
252
- oj_dump_obj_val(value, d2, out);
253
- assure_size(out, size);
254
- fill_indent(out, depth);
255
- *out->cur++ = ']';
256
245
  }
246
+ APPEND_CHARS(out->cur, "\":[", 3);
247
+ fill_indent(out, d2);
248
+ oj_dump_obj_val(key, d2, out);
249
+ assure_size(out, s2);
250
+ *out->cur++ = ',';
251
+ fill_indent(out, d2);
252
+ oj_dump_obj_val(value, d2, out);
253
+ assure_size(out, size);
254
+ fill_indent(out, depth);
255
+ *out->cur++ = ']';
256
+ }
257
257
  }
258
258
  out->depth = depth;
259
259
  *out->cur++ = ',';
@@ -363,10 +363,10 @@ static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
363
363
  }
364
364
 
365
365
  static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
366
- ID * idp;
367
- AttrGetFunc * fp;
366
+ ID *idp;
367
+ AttrGetFunc *fp;
368
368
  volatile VALUE v;
369
- const char * name;
369
+ const char *name;
370
370
  size_t size;
371
371
  int d2 = depth + 1;
372
372
 
@@ -422,7 +422,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
422
422
  ID i;
423
423
 
424
424
  if (sizeof(nbuf) <= nlen) {
425
- if (NULL == (n2 = strdup(name))) {
425
+ if (NULL == (n2 = OJ_STRDUP(name))) {
426
426
  rb_raise(rb_eNoMemError, "for attribute name.");
427
427
  }
428
428
  } else {
@@ -439,7 +439,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
439
439
  i = rb_intern(n);
440
440
  v = rb_funcall(v, i, 0);
441
441
  if (nbuf != n2) {
442
- free(n2);
442
+ OJ_FREE(n2);
443
443
  }
444
444
  }
445
445
  fill_indent(out, d2);
@@ -643,7 +643,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
643
643
  #endif
644
644
  out->cur--;
645
645
  APPEND_CHARS(out->cur, "]}", 2);
646
- *out->cur = '\0';
646
+ *out->cur = '\0';
647
647
  }
648
648
 
649
649
  static void dump_complex(VALUE obj, int depth, Out out, bool as_ok) {
@@ -682,9 +682,7 @@ static DumpFunc obj_funcs[] = {
682
682
  void oj_dump_obj_val(VALUE obj, int depth, Out out) {
683
683
  int type = rb_type(obj);
684
684
 
685
- if (Yes == out->opts->trace) {
686
- oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
687
- }
685
+ TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
688
686
  if (MAX_DEPTH < depth) {
689
687
  rb_raise(rb_eNoMemError, "Too deeply nested.\n");
690
688
  }
@@ -693,14 +691,10 @@ void oj_dump_obj_val(VALUE obj, int depth, Out out) {
693
691
 
694
692
  if (NULL != f) {
695
693
  f(obj, depth, out, false);
696
- if (Yes == out->opts->trace) {
697
- oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
698
- }
694
+ TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
699
695
  return;
700
696
  }
701
697
  }
702
698
  oj_dump_nil(Qnil, depth, out, false);
703
- if (Yes == out->opts->trace) {
704
- oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
705
- }
699
+ TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
706
700
  }
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 * b;
31
+ char* b;
34
32
  double d = rb_num2dbl(obj);
35
33
  int cnt = 0;
36
34
 
@@ -92,7 +90,7 @@ 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 = rb_funcall(obj, oj_to_s_id, 0);
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) {
@@ -290,7 +288,7 @@ static void dump_data_strict(VALUE obj, int depth, Out out, bool as_ok) {
290
288
  VALUE clas = rb_obj_class(obj);
291
289
 
292
290
  if (oj_bigdecimal_class == clas) {
293
- volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
291
+ volatile VALUE rstr = oj_safe_string_convert(obj);
294
292
 
295
293
  oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
296
294
  } else {
@@ -302,7 +300,7 @@ static void dump_data_null(VALUE obj, int depth, Out out, bool as_ok) {
302
300
  VALUE clas = rb_obj_class(obj);
303
301
 
304
302
  if (oj_bigdecimal_class == clas) {
305
- volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
303
+ volatile VALUE rstr = oj_safe_string_convert(obj);
306
304
 
307
305
  oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
308
306
  } else {
@@ -338,9 +336,7 @@ static DumpFunc strict_funcs[] = {
338
336
  void oj_dump_strict_val(VALUE obj, int depth, Out out) {
339
337
  int type = rb_type(obj);
340
338
 
341
- if (Yes == out->opts->trace) {
342
- oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
343
- }
339
+ TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
344
340
  if (MAX_DEPTH < depth) {
345
341
  rb_raise(rb_eNoMemError, "Too deeply nested.\n");
346
342
  }
@@ -349,9 +345,7 @@ void oj_dump_strict_val(VALUE obj, int depth, Out out) {
349
345
 
350
346
  if (NULL != f) {
351
347
  f(obj, depth, out, false);
352
- if (Yes == out->opts->trace) {
353
- oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
354
- }
348
+ TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
355
349
  return;
356
350
  }
357
351
  }
@@ -386,9 +380,7 @@ static DumpFunc null_funcs[] = {
386
380
  void oj_dump_null_val(VALUE obj, int depth, Out out) {
387
381
  int type = rb_type(obj);
388
382
 
389
- if (Yes == out->opts->trace) {
390
- oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
391
- }
383
+ TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
392
384
  if (MAX_DEPTH < depth) {
393
385
  rb_raise(rb_eNoMemError, "Too deeply nested.\n");
394
386
  }
@@ -397,14 +389,10 @@ void oj_dump_null_val(VALUE obj, int depth, Out out) {
397
389
 
398
390
  if (NULL != f) {
399
391
  f(obj, depth, out, false);
400
- if (Yes == out->opts->trace) {
401
- oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
402
- }
392
+ TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
403
393
  return;
404
394
  }
405
395
  }
406
396
  oj_dump_nil(Qnil, depth, out, false);
407
- if (Yes == out->opts->trace) {
408
- oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
409
- }
397
+ TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
410
398
  }
data/ext/oj/encoder.c CHANGED
@@ -27,7 +27,7 @@ typedef struct _encoder {
27
27
  struct _dumpOpts dump_opts;
28
28
  struct _rxClass str_rx;
29
29
  VALUE* ignore; // Qnil terminated array of classes or NULL
30
- } * Encoder;
30
+ }* Encoder;
31
31
 
32
32
  /*
33
33
  rb_define_module_function(Oj, "encode", encode, -1);
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
@@ -5,6 +5,7 @@
5
5
  #define OJ_ERR_H
6
6
 
7
7
  #include <errno.h>
8
+
8
9
  #include "ruby.h"
9
10
 
10
11
  // Needed to silence 2.4.0 warnings.
@@ -12,12 +13,12 @@
12
13
  #define NORETURN(x) x
13
14
  #endif
14
15
 
15
- #define OJ_ERR_START 300
16
+ #define OJ_ERR_START 300
16
17
 
17
18
  typedef enum {
18
- OJ_OK = 0,
19
- OJ_ERR_MEMORY = ENOMEM,
20
- OJ_ERR_PARSE = OJ_ERR_START,
19
+ OJ_OK = 0,
20
+ OJ_ERR_MEMORY = ENOMEM,
21
+ OJ_ERR_PARSE = OJ_ERR_START,
21
22
  OJ_ERR_READ,
22
23
  OJ_ERR_WRITE,
23
24
  OJ_ERR_OVERFLOW,
@@ -29,13 +30,12 @@ typedef enum {
29
30
  OJ_ERR_LAST,
30
31
  } ojStatus;
31
32
 
32
- #define set_error(err, eclas, msg, json, current) \
33
- _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
33
+ #define set_error(err, eclas, msg, json, current) _oj_err_set_with_location(err, eclas, msg, json, current, FILE, LINE)
34
34
 
35
35
  typedef struct _err {
36
36
  VALUE clas;
37
37
  char msg[128];
38
- } * Err;
38
+ } *Err;
39
39
 
40
40
  extern VALUE oj_parse_error_class;
41
41
 
@@ -52,11 +52,8 @@ NORETURN(extern void oj_err_raise(Err e));
52
52
 
53
53
  #define raise_error(msg, json, current) _oj_raise_error(msg, json, current, __FILE__, __LINE__)
54
54
 
55
- NORETURN(extern void _oj_raise_error(const char *msg,
56
- const char *json,
57
- const char *current,
58
- const char *file,
59
- int line));
55
+ NORETURN(
56
+ extern void _oj_raise_error(const char *msg, const char *json, const char *current, const char *file, int line));
60
57
 
61
58
  inline static void err_init(Err e) {
62
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..-1] if type.start_with?('tcs-')
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('.')
@@ -34,12 +36,20 @@ have_func('rb_hash_bulk_insert', 'ruby.h') unless '2' == version[0] && '6' == ve
34
36
 
35
37
  dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?
36
38
 
37
- if try_cflags('-msse4.2')
38
- $CPPFLAGS += ' -msse4.2'
39
- dflags['OJ_USE_SSE4_2'] = 1
39
+ if with_config('--with-sse42')
40
+ if try_cflags('-msse4.2')
41
+ $CPPFLAGS += ' -msse4.2'
42
+ dflags['OJ_USE_SSE4_2'] = 1
43
+ else
44
+ warn 'SSE 4.2 is not supported on this platform.'
45
+ end
46
+ end
47
+
48
+ if enable_config('trace-log', false)
49
+ dflags['OJ_ENABLE_TRACE_LOG'] = 1
40
50
  end
41
51
 
42
- dflags.each do |k,v|
52
+ dflags.each do |k, v|
43
53
  if v.nil?
44
54
  $CPPFLAGS += " -D#{k}"
45
55
  else
@@ -48,7 +58,7 @@ dflags.each do |k,v|
48
58
  end
49
59
 
50
60
  $CPPFLAGS += ' -Wall'
51
- #puts "*** $CPPFLAGS: #{$CPPFLAGS}"
61
+ # puts "*** $CPPFLAGS: #{$CPPFLAGS}"
52
62
  # Adding the __attribute__ flag only works with gcc compilers and even then it
53
63
  # does not work to check args with varargs so just remove the check.
54
64
  CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)