oj 3.14.1 → 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 +9 -1
  3. data/README.md +0 -1
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +25 -24
  6. data/ext/oj/cache8.c +10 -9
  7. data/ext/oj/circarray.c +7 -5
  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 +7 -14
  12. data/ext/oj/custom.c +3 -2
  13. data/ext/oj/debug.c +3 -9
  14. data/ext/oj/dump.c +18 -17
  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 +37 -37
  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 +33 -46
  24. data/ext/oj/intern.c +44 -46
  25. data/ext/oj/intern.h +3 -7
  26. data/ext/oj/mem.c +318 -0
  27. data/ext/oj/mem.h +53 -0
  28. data/ext/oj/mimic_json.c +20 -25
  29. data/ext/oj/object.c +7 -7
  30. data/ext/oj/odd.c +8 -6
  31. data/ext/oj/odd.h +4 -4
  32. data/ext/oj/oj.c +71 -85
  33. data/ext/oj/oj.h +53 -54
  34. data/ext/oj/parse.c +67 -128
  35. data/ext/oj/parse.h +5 -10
  36. data/ext/oj/parser.c +13 -14
  37. data/ext/oj/parser.h +7 -8
  38. data/ext/oj/rails.c +36 -66
  39. data/ext/oj/reader.c +8 -11
  40. data/ext/oj/reader.h +4 -2
  41. data/ext/oj/resolve.c +3 -4
  42. data/ext/oj/rxclass.c +6 -5
  43. data/ext/oj/rxclass.h +1 -1
  44. data/ext/oj/saj.c +9 -8
  45. data/ext/oj/saj2.c +36 -52
  46. data/ext/oj/saj2.h +1 -1
  47. data/ext/oj/scp.c +3 -14
  48. data/ext/oj/sparse.c +22 -70
  49. data/ext/oj/stream_writer.c +9 -21
  50. data/ext/oj/strict.c +7 -13
  51. data/ext/oj/string_writer.c +11 -18
  52. data/ext/oj/trace.h +27 -16
  53. data/ext/oj/usual.c +89 -87
  54. data/ext/oj/usual.h +6 -6
  55. data/ext/oj/util.h +1 -1
  56. data/ext/oj/val_stack.h +8 -7
  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 -3
  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 +2 -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 +20 -27
  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/rails.c CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  #include "code.h"
7
7
  #include "encode.h"
8
+ #include "mem.h"
8
9
  #include "trace.h"
9
10
  #include "util.h"
10
11
 
@@ -15,7 +16,7 @@ typedef struct _encoder {
15
16
  struct _rOptTable ropts;
16
17
  struct _options opts;
17
18
  VALUE arg;
18
- } * Encoder;
19
+ } *Encoder;
19
20
 
20
21
  bool oj_rails_hash_opt = false;
21
22
  bool oj_rails_array_opt = false;
@@ -76,7 +77,7 @@ static ROptTable copy_opts(ROptTable src, ROptTable dest) {
76
77
  if (NULL == src->table) {
77
78
  dest->table = NULL;
78
79
  } else {
79
- dest->table = ALLOC_N(struct _rOpt, dest->alen);
80
+ dest->table = OJ_R_ALLOC_N(struct _rOpt, dest->alen);
80
81
  memcpy(dest->table, src->table, sizeof(struct _rOpt) * dest->alen);
81
82
  }
82
83
  return NULL;
@@ -140,7 +141,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
140
141
  int cnt;
141
142
  int i;
142
143
  int len;
143
- const char * name;
144
+ const char *name;
144
145
 
145
146
  #ifdef RSTRUCT_LEN
146
147
  #if RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
@@ -199,7 +200,7 @@ static void dump_enumerable(VALUE obj, int depth, Out out, bool as_ok) {
199
200
 
200
201
  static void dump_bigdecimal(VALUE obj, int depth, Out out, bool as_ok) {
201
202
  volatile VALUE rstr = oj_safe_string_convert(obj);
202
- const char * str = RSTRING_PTR(rstr);
203
+ const char *str = RSTRING_PTR(rstr);
203
204
 
204
205
  if ('I' == *str || 'N' == *str || ('-' == *str && 'I' == str[1])) {
205
206
  oj_dump_nil(Qnil, depth, out, false);
@@ -262,14 +263,7 @@ static void dump_sec_nano(VALUE obj, int64_t sec, long nsec, Out out) {
262
263
  tzmin);
263
264
  } else if (0 == out->opts->sec_prec) {
264
265
  if (0 == tzsecs && rb_funcall2(obj, oj_utcq_id, 0, 0)) {
265
- len = sprintf(buf,
266
- "%04d-%02d-%02dT%02d:%02d:%02dZ",
267
- ti.year,
268
- ti.mon,
269
- ti.day,
270
- ti.hour,
271
- ti.min,
272
- ti.sec);
266
+ len = sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02dZ", ti.year, ti.mon, ti.day, ti.hour, ti.min, ti.sec);
273
267
  } else {
274
268
  len = sprintf(buf,
275
269
  "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
@@ -300,18 +294,7 @@ static void dump_sec_nano(VALUE obj, int64_t sec, long nsec, Out out) {
300
294
  format[32] = '0' + out->opts->sec_prec;
301
295
  len -= 9 - out->opts->sec_prec;
302
296
  }
303
- len = sprintf(buf,
304
- format,
305
- ti.year,
306
- ti.mon,
307
- ti.day,
308
- ti.hour,
309
- ti.min,
310
- ti.sec,
311
- nsec,
312
- tzsign,
313
- tzhour,
314
- tzmin);
297
+ len = sprintf(buf, format, ti.year, ti.mon, ti.day, ti.hour, ti.min, ti.sec, nsec, tzsign, tzhour, tzmin);
315
298
  }
316
299
  oj_dump_cstr(buf, len, 0, 0, out);
317
300
  }
@@ -355,7 +338,7 @@ static ID parameters_id = 0;
355
338
  typedef struct _strLen {
356
339
  const char *str;
357
340
  int len;
358
- } * StrLen;
341
+ } *StrLen;
359
342
 
360
343
  static void dump_actioncontroller_parameters(VALUE obj, int depth, Out out, bool as_ok) {
361
344
  if (0 == parameters_id) {
@@ -373,7 +356,7 @@ static StrLen columns_array(VALUE rcols, int *ccnt) {
373
356
  int cnt = (int)RARRAY_LEN(rcols);
374
357
 
375
358
  *ccnt = cnt;
376
- cols = ALLOC_N(struct _strLen, cnt);
359
+ cols = OJ_R_ALLOC_N(struct _strLen, cnt);
377
360
  for (i = 0, cp = cols; i < cnt; i++, cp++) {
378
361
  v = RARRAY_AREF(rcols, i);
379
362
  if (T_STRING != rb_type(v)) {
@@ -481,7 +464,7 @@ static void dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok)
481
464
  *out->cur++ = ',';
482
465
  }
483
466
  }
484
- xfree(cols);
467
+ OJ_R_FREE(cols);
485
468
  size = depth * out->indent + 1;
486
469
  assure_size(out, size);
487
470
  if (out->opts->dump_opts.use) {
@@ -504,7 +487,7 @@ static void dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok)
504
487
  typedef struct _namedFunc {
505
488
  const char *name;
506
489
  DumpFunc func;
507
- } * NamedFunc;
490
+ } *NamedFunc;
508
491
 
509
492
  static void dump_as_string(VALUE obj, int depth, Out out, bool as_ok) {
510
493
  if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
@@ -583,11 +566,11 @@ static ROpt create_opt(ROptTable rot, VALUE clas) {
583
566
  rot->len++;
584
567
  if (NULL == rot->table) {
585
568
  rot->alen = 256;
586
- rot->table = ALLOC_N(struct _rOpt, rot->alen);
569
+ rot->table = OJ_R_ALLOC_N(struct _rOpt, rot->alen);
587
570
  memset(rot->table, 0, sizeof(struct _rOpt) * rot->alen);
588
571
  } else if (rot->alen <= rot->len) {
589
572
  rot->alen *= 2;
590
- REALLOC_N(rot->table, struct _rOpt, rot->alen);
573
+ OJ_R_REALLOC_N(rot->table, struct _rOpt, rot->alen);
591
574
  memset(rot->table + olen, 0, sizeof(struct _rOpt) * olen);
592
575
  }
593
576
  if (0 == olen) {
@@ -640,9 +623,9 @@ static void encoder_free(void *ptr) {
640
623
  Encoder e = (Encoder)ptr;
641
624
 
642
625
  if (NULL != e->ropts.table) {
643
- xfree(e->ropts.table);
626
+ OJ_R_FREE(e->ropts.table);
644
627
  }
645
- xfree(ptr);
628
+ OJ_R_FREE(ptr);
646
629
  }
647
630
  }
648
631
 
@@ -663,7 +646,7 @@ static void encoder_mark(void *ptr) {
663
646
  * - *options* [_Hash_] formatting options
664
647
  */
665
648
  static VALUE encoder_new(int argc, VALUE *argv, VALUE self) {
666
- Encoder e = ALLOC(struct _encoder);
649
+ Encoder e = OJ_R_ALLOC(struct _encoder);
667
650
 
668
651
  e->opts = oj_default_options;
669
652
  e->arg = Qnil;
@@ -679,8 +662,8 @@ static VALUE encoder_new(int argc, VALUE *argv, VALUE self) {
679
662
  static VALUE resolve_classpath(const char *name) {
680
663
  char class_name[1024];
681
664
  VALUE clas;
682
- char * end = class_name + sizeof(class_name) - 1;
683
- char * s;
665
+ char *end = class_name + sizeof(class_name) - 1;
666
+ char *s;
684
667
  const char *n = name;
685
668
  ID cid;
686
669
 
@@ -746,8 +729,7 @@ static void optimize(int argc, VALUE *argv, ROptTable rot, bool on) {
746
729
  oj_rails_float_opt = on;
747
730
  } else if (oj_string_writer_class == *argv) {
748
731
  string_writer_optimized = on;
749
- } else if (NULL != (ro = oj_rails_get_opt(rot, *argv)) ||
750
- NULL != (ro = create_opt(rot, *argv))) {
732
+ } else if (NULL != (ro = oj_rails_get_opt(rot, *argv)) || NULL != (ro = create_opt(rot, *argv))) {
751
733
  ro->on = on;
752
734
  }
753
735
  }
@@ -809,7 +791,7 @@ rails_mimic_json(VALUE self) {
809
791
  }
810
792
  oj_mimic_json_methods(json);
811
793
  // Setting the default mode breaks the prmoise in the docs not to.
812
- //oj_default_options.mode = RailsMode;
794
+ // oj_default_options.mode = RailsMode;
813
795
 
814
796
  return Qnil;
815
797
  }
@@ -877,7 +859,7 @@ static VALUE rails_optimized(VALUE self, VALUE clas) {
877
859
  typedef struct _oo {
878
860
  Out out;
879
861
  VALUE obj;
880
- } * OO;
862
+ } *OO;
881
863
 
882
864
  static VALUE protect_dump(VALUE ov) {
883
865
  OO oo = (OO)ov;
@@ -907,16 +889,16 @@ static VALUE encode(VALUE obj, ROptTable ropts, Options opts, int argc, VALUE *a
907
889
 
908
890
  oj_out_init(&out);
909
891
 
910
- out.omit_nil = copts.dump_opts.omit_nil;
911
- out.caller = 0;
912
- out.cur = out.buf;
913
- out.circ_cnt = 0;
914
- out.opts = &copts;
915
- out.hash_cnt = 0;
916
- out.indent = copts.indent;
917
- out.argc = argc;
918
- out.argv = argv;
919
- out.ropts = ropts;
892
+ out.omit_nil = copts.dump_opts.omit_nil;
893
+ out.caller = 0;
894
+ out.cur = out.buf;
895
+ out.circ_cnt = 0;
896
+ out.opts = &copts;
897
+ out.hash_cnt = 0;
898
+ out.indent = copts.indent;
899
+ out.argc = argc;
900
+ out.argv = argv;
901
+ out.ropts = ropts;
920
902
  if (Yes == copts.circular) {
921
903
  oj_cache8_new(&out.circ_cache);
922
904
  }
@@ -1061,28 +1043,16 @@ static VALUE rails_set_encoder(VALUE self) {
1061
1043
  verbose = rb_gv_get("$VERBOSE");
1062
1044
  rb_gv_set("$VERBOSE", Qfalse);
1063
1045
  rb_undef_method(encoding, "use_standard_json_time_format=");
1064
- rb_define_module_function(encoding,
1065
- "use_standard_json_time_format=",
1066
- rails_use_standard_json_time_format,
1067
- 1);
1046
+ rb_define_module_function(encoding, "use_standard_json_time_format=", rails_use_standard_json_time_format, 1);
1068
1047
  rb_undef_method(encoding, "use_standard_json_time_format");
1069
- rb_define_module_function(encoding,
1070
- "use_standard_json_time_format",
1071
- rails_use_standard_json_time_format_get,
1072
- 0);
1048
+ rb_define_module_function(encoding, "use_standard_json_time_format", rails_use_standard_json_time_format_get, 0);
1073
1049
 
1074
1050
  pv = rb_iv_get(encoding, "@escape_html_entities_in_json");
1075
1051
  escape_html = Qtrue == pv;
1076
1052
  rb_undef_method(encoding, "escape_html_entities_in_json=");
1077
- rb_define_module_function(encoding,
1078
- "escape_html_entities_in_json=",
1079
- rails_escape_html_entities_in_json,
1080
- 1);
1053
+ rb_define_module_function(encoding, "escape_html_entities_in_json=", rails_escape_html_entities_in_json, 1);
1081
1054
  rb_undef_method(encoding, "escape_html_entities_in_json");
1082
- rb_define_module_function(encoding,
1083
- "escape_html_entities_in_json",
1084
- rails_escape_html_entities_in_json_get,
1085
- 0);
1055
+ rb_define_module_function(encoding, "escape_html_entities_in_json", rails_escape_html_entities_in_json_get, 0);
1086
1056
 
1087
1057
  pv = rb_iv_get(encoding, "@time_precision");
1088
1058
  oj_default_options.sec_prec = NUM2INT(pv);
@@ -1184,7 +1154,7 @@ static void dump_to_hash(VALUE obj, int depth, Out out) {
1184
1154
 
1185
1155
  static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
1186
1156
  char buf[64];
1187
- char * b;
1157
+ char *b;
1188
1158
  double d = rb_num2dbl(obj);
1189
1159
  int cnt = 0;
1190
1160
 
data/ext/oj/reader.c CHANGED
@@ -14,6 +14,7 @@
14
14
  #include <time.h>
15
15
  #include <unistd.h>
16
16
 
17
+ #include "mem.h"
17
18
  #include "oj.h"
18
19
  #include "reader.h"
19
20
  #include "ruby.h"
@@ -63,8 +64,7 @@ void oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
63
64
  reader->tail = reader->head;
64
65
  reader->read_end = reader->head + RSTRING_LEN(s);
65
66
  } else if (rb_cFile == io_class && Qnil != (stat = rb_funcall(io, oj_stat_id, 0)) &&
66
- Qnil != (ftype = rb_funcall(stat, oj_ftype_id, 0)) &&
67
- 0 == strcmp("file", StringValuePtr(ftype)) &&
67
+ Qnil != (ftype = rb_funcall(stat, oj_ftype_id, 0)) && 0 == strcmp("file", StringValuePtr(ftype)) &&
68
68
  0 == FIX2INT(rb_funcall(io, oj_pos_id, 0))) {
69
69
  reader->read_func = read_from_fd;
70
70
  reader->fd = FIX2INT(rb_funcall(io, oj_fileno_id, 0));
@@ -83,8 +83,7 @@ void oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
83
83
  reader->tail = reader->head;
84
84
  reader->read_end = reader->head + RSTRING_LEN(rstr);
85
85
  } else {
86
- rb_raise(rb_eArgError,
87
- "parser io argument must be a String or respond to readpartial() or read().\n");
86
+ rb_raise(rb_eArgError, "parser io argument must be a String or respond to readpartial() or read().\n");
88
87
  }
89
88
  }
90
89
 
@@ -107,10 +106,10 @@ int oj_reader_read(Reader reader) {
107
106
  size_t size = reader->end - reader->head + BUF_PAD;
108
107
 
109
108
  if (reader->head == reader->base) {
110
- reader->head = ALLOC_N(char, size * 2);
109
+ reader->head = OJ_R_ALLOC_N(char, size * 2);
111
110
  memcpy((char *)reader->head, old, size);
112
111
  } else {
113
- REALLOC_N(reader->head, char, size * 2);
112
+ OJ_R_REALLOC_N(reader->head, char, size * 2);
114
113
  }
115
114
  reader->free_head = 1;
116
115
  reader->end = reader->head + size * 2 - BUF_PAD;
@@ -123,9 +122,7 @@ int oj_reader_read(Reader reader) {
123
122
  reader->str = reader->head + (reader->str - old);
124
123
  }
125
124
  } else {
126
- memmove((char *)reader->head,
127
- reader->head + shift,
128
- reader->read_end - (reader->head + shift));
125
+ memmove((char *)reader->head, reader->head + shift, reader->read_end - (reader->head + shift));
129
126
  reader->tail -= shift;
130
127
  reader->read_end -= shift;
131
128
  if (0 != reader->pro) {
@@ -157,7 +154,7 @@ static VALUE partial_io_cb(VALUE rbuf) {
157
154
  Reader reader = (Reader)rbuf;
158
155
  VALUE args[1];
159
156
  VALUE rstr;
160
- char * str;
157
+ char *str;
161
158
  size_t cnt;
162
159
 
163
160
  args[0] = ULONG2NUM(reader->end - reader->tail);
@@ -178,7 +175,7 @@ static VALUE io_cb(VALUE rbuf) {
178
175
  Reader reader = (Reader)rbuf;
179
176
  VALUE args[1];
180
177
  VALUE rstr;
181
- char * str;
178
+ char *str;
182
179
  size_t cnt;
183
180
 
184
181
  args[0] = ULONG2NUM(reader->end - reader->tail);
data/ext/oj/reader.h CHANGED
@@ -4,6 +4,8 @@
4
4
  #ifndef OJ_READER_H
5
5
  #define OJ_READER_H
6
6
 
7
+ #include "mem.h"
8
+
7
9
  typedef struct _reader {
8
10
  char base[0x00001000];
9
11
  char *head;
@@ -22,7 +24,7 @@ typedef struct _reader {
22
24
  VALUE io;
23
25
  const char *in_str;
24
26
  };
25
- } * Reader;
27
+ } *Reader;
26
28
 
27
29
  extern void oj_reader_init(Reader reader, VALUE io, int fd, bool to_s);
28
30
  extern int oj_reader_read(Reader reader);
@@ -114,7 +116,7 @@ static inline int reader_expect(Reader reader, const char *s) {
114
116
 
115
117
  static inline void reader_cleanup(Reader reader) {
116
118
  if (reader->free_head && 0 != reader->head) {
117
- xfree((char *)reader->head);
119
+ OJ_R_FREE((char *)reader->head);
118
120
  reader->head = 0;
119
121
  reader->free_head = 0;
120
122
  }
data/ext/oj/resolve.c CHANGED
@@ -27,12 +27,11 @@ inline static VALUE resolve_classname(VALUE mod, const char *classname, int auto
27
27
  return clas;
28
28
  }
29
29
 
30
- static VALUE
31
- resolve_classpath(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class) {
30
+ static VALUE resolve_classpath(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class) {
32
31
  char class_name[1024];
33
32
  VALUE clas;
34
- char * end = class_name + sizeof(class_name) - 1;
35
- char * s;
33
+ char *end = class_name + sizeof(class_name) - 1;
34
+ char *s;
36
35
  const char *n = name;
37
36
 
38
37
  clas = rb_cObject;
data/ext/oj/rxclass.c CHANGED
@@ -10,6 +10,7 @@
10
10
  #include <regex.h>
11
11
  #endif
12
12
 
13
+ #include "mem.h"
13
14
  #include "rxclass.h"
14
15
 
15
16
  typedef struct _rxC {
@@ -20,7 +21,7 @@ typedef struct _rxC {
20
21
  #endif
21
22
  VALUE clas;
22
23
  char src[256];
23
- } * RxC;
24
+ } *RxC;
24
25
 
25
26
  void oj_rxclass_init(RxClass rc) {
26
27
  *rc->err = '\0';
@@ -37,13 +38,13 @@ void oj_rxclass_cleanup(RxClass rc) {
37
38
  if (Qnil == rxc->rrx) {
38
39
  regfree(&rxc->rx);
39
40
  }
40
- xfree(rxc);
41
+ OJ_R_FREE(rxc);
41
42
  #endif
42
43
  }
43
44
  }
44
45
 
45
46
  void oj_rxclass_rappend(RxClass rc, VALUE rx, VALUE clas) {
46
- RxC rxc = ALLOC_N(struct _rxC, 1);
47
+ RxC rxc = OJ_R_ALLOC_N(struct _rxC, 1);
47
48
 
48
49
  memset(rxc, 0, sizeof(struct _rxC));
49
50
  rxc->rrx = rx;
@@ -70,7 +71,7 @@ int oj_rxclass_append(RxClass rc, const char *expr, VALUE clas) {
70
71
  (unsigned long)sizeof(rxc->src));
71
72
  return EINVAL;
72
73
  }
73
- rxc = ALLOC_N(struct _rxC, 1);
74
+ rxc = OJ_R_ALLOC_N(struct _rxC, 1);
74
75
  rxc->next = 0;
75
76
  rxc->clas = clas;
76
77
 
@@ -80,7 +81,7 @@ int oj_rxclass_append(RxClass rc, const char *expr, VALUE clas) {
80
81
  rxc->rrx = Qnil;
81
82
  if (0 != (err = regcomp(&rxc->rx, expr, flags))) {
82
83
  regerror(err, &rxc->rx, rc->err, sizeof(rc->err));
83
- free(rxc);
84
+ OJ_FREE(rxc);
84
85
  return err;
85
86
  }
86
87
  #endif
data/ext/oj/rxclass.h CHANGED
@@ -14,7 +14,7 @@ typedef struct _rxClass {
14
14
  struct _rxC *head;
15
15
  struct _rxC *tail;
16
16
  char err[128];
17
- } * RxClass;
17
+ } *RxClass;
18
18
 
19
19
  extern void oj_rxclass_init(RxClass rc);
20
20
  extern void oj_rxclass_cleanup(RxClass rc);
data/ext/oj/saj.c CHANGED
@@ -15,6 +15,7 @@
15
15
  #define OJ_INFINITY (1.0 / 0.0)
16
16
 
17
17
  #include "encode.h"
18
+ #include "mem.h"
18
19
  #include "oj.h"
19
20
 
20
21
  typedef struct _parseInfo {
@@ -28,7 +29,7 @@ typedef struct _parseInfo {
28
29
  int has_array_end;
29
30
  int has_add_value;
30
31
  int has_error;
31
- } * ParseInfo;
32
+ } *ParseInfo;
32
33
 
33
34
  static void read_next(ParseInfo pi, const char *key);
34
35
  static void read_hash(ParseInfo pi, const char *key);
@@ -631,7 +632,7 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
631
632
  if (rb_type(input) == T_STRING) {
632
633
  // the json string gets modified so make a copy of it
633
634
  len = RSTRING_LEN(input) + 1;
634
- json = ALLOC_N(char, len);
635
+ json = OJ_R_ALLOC_N(char, len);
635
636
  strcpy(json, StringValuePtr(input));
636
637
  } else {
637
638
  VALUE clas = rb_obj_class(input);
@@ -640,8 +641,8 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
640
641
  if (oj_stringio_class == clas) {
641
642
  s = rb_funcall2(input, oj_string_id, 0, 0);
642
643
  len = RSTRING_LEN(s) + 1;
643
- json = ALLOC_N(char, len);
644
- strcpy(json, rb_string_value_cstr((VALUE *)&s));
644
+ json = OJ_R_ALLOC_N(char, len);
645
+ strcpy(json, StringValueCStr(s));
645
646
  #if !IS_WINDOWS
646
647
  } else if (rb_cFile == clas && 0 == FIX2INT(rb_funcall(input, oj_pos_id, 0))) {
647
648
  int fd = FIX2INT(rb_funcall(input, oj_fileno_id, 0));
@@ -649,7 +650,7 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
649
650
 
650
651
  len = lseek(fd, 0, SEEK_END);
651
652
  lseek(fd, 0, SEEK_SET);
652
- json = ALLOC_N(char, len + 1);
653
+ json = OJ_R_ALLOC_N(char, len + 1);
653
654
  if (0 >= (cnt = read(fd, json, len)) || cnt != (ssize_t)len) {
654
655
  rb_raise(rb_eIOError, "failed to read from IO Object.");
655
656
  }
@@ -658,14 +659,14 @@ oj_saj_parse(int argc, VALUE *argv, VALUE self) {
658
659
  } else if (rb_respond_to(input, oj_read_id)) {
659
660
  s = rb_funcall2(input, oj_read_id, 0, 0);
660
661
  len = RSTRING_LEN(s) + 1;
661
- json = ALLOC_N(char, len);
662
- strcpy(json, rb_string_value_cstr((VALUE *)&s));
662
+ json = OJ_R_ALLOC_N(char, len);
663
+ strcpy(json, StringValueCStr(s));
663
664
  } else {
664
665
  rb_raise(rb_eArgError, "saj_parse() expected a String or IO Object.");
665
666
  }
666
667
  }
667
668
  saj_parse(*argv, json);
668
- xfree(json);
669
+ OJ_R_FREE(json);
669
670
 
670
671
  return Qnil;
671
672
  }