oj 3.14.1 → 3.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/oj/parser.c CHANGED
@@ -1148,7 +1148,7 @@ static void parser_free(void *ptr) {
1148
1148
  if (NULL != p->free) {
1149
1149
  p->free(p);
1150
1150
  }
1151
- xfree(ptr);
1151
+ OJ_R_FREE(ptr);
1152
1152
  }
1153
1153
 
1154
1154
  static void parser_mark(void *ptr) {
@@ -1205,7 +1205,7 @@ static int opt_cb(VALUE rkey, VALUE value, VALUE ptr) {
1205
1205
  * Oj::Parser.new(:usual, cache_keys: true).
1206
1206
  */
1207
1207
  static VALUE parser_new(int argc, VALUE *argv, VALUE self) {
1208
- ojParser p = ALLOC(struct _ojParser);
1208
+ ojParser p = OJ_R_ALLOC(struct _ojParser);
1209
1209
 
1210
1210
  #if HAVE_RB_EXT_RACTOR_SAFE
1211
1211
  // This doesn't seem to do anything.
@@ -1264,7 +1264,7 @@ static VALUE parser_new(int argc, VALUE *argv, VALUE self) {
1264
1264
  // used. Optionally oj_parser_set_options can be called if the options are not
1265
1265
  // set directly.
1266
1266
  VALUE oj_parser_new(void) {
1267
- ojParser p = ALLOC(struct _ojParser);
1267
+ ojParser p = OJ_R_ALLOC(struct _ojParser);
1268
1268
 
1269
1269
  #if HAVE_RB_EXT_RACTOR_SAFE
1270
1270
  // This doesn't seem to do anything.
@@ -1499,7 +1499,7 @@ static VALUE usual_parser = Qundef;
1499
1499
  */
1500
1500
  static VALUE parser_usual(VALUE self) {
1501
1501
  if (Qundef == usual_parser) {
1502
- ojParser p = ALLOC(struct _ojParser);
1502
+ ojParser p = OJ_R_ALLOC(struct _ojParser);
1503
1503
 
1504
1504
  memset(p, 0, sizeof(struct _ojParser));
1505
1505
  buf_init(&p->key);
@@ -1522,7 +1522,7 @@ static VALUE saj_parser = Qundef;
1522
1522
  */
1523
1523
  static VALUE parser_saj(VALUE self) {
1524
1524
  if (Qundef == saj_parser) {
1525
- ojParser p = ALLOC(struct _ojParser);
1525
+ ojParser p = OJ_R_ALLOC(struct _ojParser);
1526
1526
 
1527
1527
  memset(p, 0, sizeof(struct _ojParser));
1528
1528
  buf_init(&p->key);
@@ -1544,7 +1544,7 @@ static VALUE validate_parser = Qundef;
1544
1544
  */
1545
1545
  static VALUE parser_validate(VALUE self) {
1546
1546
  if (Qundef == validate_parser) {
1547
- ojParser p = ALLOC(struct _ojParser);
1547
+ ojParser p = OJ_R_ALLOC(struct _ojParser);
1548
1548
 
1549
1549
  memset(p, 0, sizeof(struct _ojParser));
1550
1550
  buf_init(&p->key);
data/ext/oj/rails.c CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "rails.h"
5
5
 
6
+ #include "mem.h"
6
7
  #include "code.h"
7
8
  #include "encode.h"
8
9
  #include "trace.h"
@@ -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;
@@ -373,7 +374,7 @@ static StrLen columns_array(VALUE rcols, int *ccnt) {
373
374
  int cnt = (int)RARRAY_LEN(rcols);
374
375
 
375
376
  *ccnt = cnt;
376
- cols = ALLOC_N(struct _strLen, cnt);
377
+ cols = OJ_R_ALLOC_N(struct _strLen, cnt);
377
378
  for (i = 0, cp = cols; i < cnt; i++, cp++) {
378
379
  v = RARRAY_AREF(rcols, i);
379
380
  if (T_STRING != rb_type(v)) {
@@ -481,7 +482,7 @@ static void dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok)
481
482
  *out->cur++ = ',';
482
483
  }
483
484
  }
484
- xfree(cols);
485
+ OJ_R_FREE(cols);
485
486
  size = depth * out->indent + 1;
486
487
  assure_size(out, size);
487
488
  if (out->opts->dump_opts.use) {
@@ -583,11 +584,11 @@ static ROpt create_opt(ROptTable rot, VALUE clas) {
583
584
  rot->len++;
584
585
  if (NULL == rot->table) {
585
586
  rot->alen = 256;
586
- rot->table = ALLOC_N(struct _rOpt, rot->alen);
587
+ rot->table = OJ_R_ALLOC_N(struct _rOpt, rot->alen);
587
588
  memset(rot->table, 0, sizeof(struct _rOpt) * rot->alen);
588
589
  } else if (rot->alen <= rot->len) {
589
590
  rot->alen *= 2;
590
- REALLOC_N(rot->table, struct _rOpt, rot->alen);
591
+ OJ_R_REALLOC_N(rot->table, struct _rOpt, rot->alen);
591
592
  memset(rot->table + olen, 0, sizeof(struct _rOpt) * olen);
592
593
  }
593
594
  if (0 == olen) {
@@ -640,9 +641,9 @@ static void encoder_free(void *ptr) {
640
641
  Encoder e = (Encoder)ptr;
641
642
 
642
643
  if (NULL != e->ropts.table) {
643
- xfree(e->ropts.table);
644
+ OJ_R_FREE(e->ropts.table);
644
645
  }
645
- xfree(ptr);
646
+ OJ_R_FREE(ptr);
646
647
  }
647
648
  }
648
649
 
@@ -663,7 +664,7 @@ static void encoder_mark(void *ptr) {
663
664
  * - *options* [_Hash_] formatting options
664
665
  */
665
666
  static VALUE encoder_new(int argc, VALUE *argv, VALUE self) {
666
- Encoder e = ALLOC(struct _encoder);
667
+ Encoder e = OJ_R_ALLOC(struct _encoder);
667
668
 
668
669
  e->opts = oj_default_options;
669
670
  e->arg = Qnil;
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"
@@ -107,10 +108,10 @@ int oj_reader_read(Reader reader) {
107
108
  size_t size = reader->end - reader->head + BUF_PAD;
108
109
 
109
110
  if (reader->head == reader->base) {
110
- reader->head = ALLOC_N(char, size * 2);
111
+ reader->head = OJ_R_ALLOC_N(char, size * 2);
111
112
  memcpy((char *)reader->head, old, size);
112
113
  } else {
113
- REALLOC_N(reader->head, char, size * 2);
114
+ OJ_R_REALLOC_N(reader->head, char, size * 2);
114
115
  }
115
116
  reader->free_head = 1;
116
117
  reader->end = reader->head + size * 2 - BUF_PAD;
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;
@@ -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/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 {
@@ -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/saj.c CHANGED
@@ -14,6 +14,7 @@
14
14
  // Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
15
15
  #define OJ_INFINITY (1.0 / 0.0)
16
16
 
17
+ #include "mem.h"
17
18
  #include "encode.h"
18
19
  #include "oj.h"
19
20
 
@@ -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,7 +641,7 @@ 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
+ json = OJ_R_ALLOC_N(char, len);
644
645
  strcpy(json, rb_string_value_cstr((VALUE *)&s));
645
646
  #if !IS_WINDOWS
646
647
  } else if (rb_cFile == clas && 0 == FIX2INT(rb_funcall(input, oj_pos_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
+ json = OJ_R_ALLOC_N(char, len);
662
663
  strcpy(json, rb_string_value_cstr((VALUE *)&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
  }
data/ext/oj/saj2.c CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) 2021, Peter Ohler, All rights reserved.
2
2
 
3
+ #include "mem.h"
3
4
  #include "cache.h"
4
5
  #include "oj.h"
5
6
  #include "parser.h"
@@ -24,7 +25,7 @@ static void push_key(Saj d, VALUE key) {
24
25
  size_t off = d->tail - d->keys;
25
26
 
26
27
  d->klen += d->klen / 2;
27
- REALLOC_N(d->keys, VALUE, d->klen);
28
+ OJ_R_REALLOC_N(d->keys, VALUE, d->klen);
28
29
  d->tail = d->keys + off;
29
30
  }
30
31
  *d->tail = key;
@@ -546,10 +547,10 @@ static void dfree(ojParser p) {
546
547
  Saj d = (Saj)p->ctx;
547
548
 
548
549
  if (NULL != d->keys) {
549
- xfree(d->keys);
550
+ OJ_R_FREE(d->keys);
550
551
  }
551
552
  cache_free(d->str_cache);
552
- xfree(p->ctx);
553
+ OJ_R_FREE(p->ctx);
553
554
  }
554
555
 
555
556
  static void mark(ojParser p) {
@@ -576,7 +577,7 @@ static VALUE form_str(const char *str, size_t len) {
576
577
 
577
578
  void oj_init_saj(ojParser p, Saj d) {
578
579
  d->klen = 256;
579
- d->keys = ALLOC_N(VALUE, d->klen);
580
+ d->keys = OJ_R_ALLOC_N(VALUE, d->klen);
580
581
  d->tail = d->keys;
581
582
  d->handler = Qnil;
582
583
  d->str_cache = cache_create(0, form_str, true, false);
@@ -594,7 +595,7 @@ void oj_init_saj(ojParser p, Saj d) {
594
595
  }
595
596
 
596
597
  void oj_set_parser_saj(ojParser p) {
597
- Saj d = ALLOC(struct _saj);
598
+ Saj d = OJ_R_ALLOC(struct _saj);
598
599
 
599
600
  oj_init_saj(p, d);
600
601
  }
data/ext/oj/sparse.c CHANGED
@@ -7,6 +7,7 @@
7
7
  #include <string.h>
8
8
  #include <unistd.h>
9
9
 
10
+ #include "mem.h"
10
11
  #include "buf.h"
11
12
  #include "encode.h"
12
13
  #include "intern.h" // for oj_strndup()
@@ -71,7 +72,7 @@ static void add_value(ParseInfo pi, VALUE rval) {
71
72
  case NEXT_HASH_VALUE:
72
73
  pi->hash_set_value(pi, parent, rval);
73
74
  if (parent->kalloc) {
74
- xfree((char *)parent->key);
75
+ OJ_R_FREE((char *)parent->key);
75
76
  }
76
77
  parent->key = 0;
77
78
  parent->kalloc = 0;
@@ -110,7 +111,7 @@ static void add_num_value(ParseInfo pi, NumInfo ni) {
110
111
  case NEXT_HASH_VALUE:
111
112
  pi->hash_set_num(pi, parent, ni);
112
113
  if (parent->kalloc) {
113
- xfree((char *)parent->key);
114
+ OJ_R_FREE((char *)parent->key);
114
115
  }
115
116
  parent->key = 0;
116
117
  parent->kalloc = 0;
@@ -315,7 +316,7 @@ static void read_escaped_str(ParseInfo pi) {
315
316
  case NEXT_HASH_VALUE:
316
317
  pi->hash_set_cstr(pi, parent, buf.head, buf_len(&buf), pi->rd.str);
317
318
  if (parent->kalloc) {
318
- xfree((char *)parent->key);
319
+ OJ_R_FREE((char *)parent->key);
319
320
  }
320
321
  parent->key = 0;
321
322
  parent->kalloc = 0;
@@ -386,7 +387,7 @@ static void read_str(ParseInfo pi) {
386
387
  case NEXT_HASH_VALUE:
387
388
  pi->hash_set_cstr(pi, parent, pi->rd.str, pi->rd.tail - pi->rd.str - 1, pi->rd.str);
388
389
  if (parent->kalloc) {
389
- xfree((char *)parent->key);
390
+ OJ_R_FREE((char *)parent->key);
390
391
  }
391
392
  parent->key = 0;
392
393
  parent->kalloc = 0;
@@ -4,6 +4,7 @@
4
4
  #include <errno.h>
5
5
  #include <ruby.h>
6
6
 
7
+ #include "mem.h"
7
8
  #include "encode.h"
8
9
 
9
10
  extern VALUE Oj;
@@ -15,9 +16,9 @@ static void stream_writer_free(void *ptr) {
15
16
  return;
16
17
  }
17
18
  sw = (StreamWriter)ptr;
18
- xfree(sw->sw.out.buf);
19
- xfree(sw->sw.types);
20
- xfree(ptr);
19
+ OJ_R_FREE(sw->sw.out.buf);
20
+ OJ_R_FREE(sw->sw.types);
21
+ OJ_R_FREE(ptr);
21
22
  }
22
23
 
23
24
  static void stream_writer_reset_buf(StreamWriter sw) {
@@ -91,7 +92,7 @@ static VALUE stream_writer_new(int argc, VALUE *argv, VALUE self) {
91
92
  } else {
92
93
  rb_raise(rb_eArgError, "expected an IO Object.");
93
94
  }
94
- sw = ALLOC(struct _streamWriter);
95
+ sw = OJ_R_ALLOC(struct _streamWriter);
95
96
  if (2 == argc && T_HASH == rb_type(argv[1])) {
96
97
  volatile VALUE v;
97
98
  int buf_size = 0;
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
2
2
  // Licensed under the MIT License. See LICENSE file in the project root for license details.
3
3
 
4
+ #include "mem.h"
4
5
  #include "dump.h"
5
6
  #include "encode.h"
6
7
 
@@ -20,7 +21,7 @@ static void push_type(StrWriter sw, DumpType type) {
20
21
  if (sw->types_end <= sw->types + sw->depth + 1) {
21
22
  size_t size = (sw->types_end - sw->types) * 2;
22
23
 
23
- REALLOC_N(sw->types, char, size);
24
+ OJ_R_REALLOC_N(sw->types, char, size);
24
25
  sw->types_end = sw->types + size;
25
26
  }
26
27
  sw->depth++;
@@ -43,7 +44,7 @@ static void maybe_comma(StrWriter sw) {
43
44
  void oj_str_writer_init(StrWriter sw, int buf_size) {
44
45
  sw->opts = oj_default_options;
45
46
  sw->depth = 0;
46
- sw->types = ALLOC_N(char, 256);
47
+ sw->types = OJ_R_ALLOC_N(char, 256);
47
48
  sw->types_end = sw->types + 256;
48
49
  *sw->types = '\0';
49
50
  sw->keyWritten = 0;
@@ -55,7 +56,7 @@ void oj_str_writer_init(StrWriter sw, int buf_size) {
55
56
  }
56
57
  // Must be allocated. Using the out.stack_buffer results in double frees
57
58
  // and I haven't figured out why yet.
58
- sw->out.buf = ALLOC_N(char, buf_size);
59
+ sw->out.buf = OJ_R_ALLOC_N(char, buf_size);
59
60
  sw->out.cur = sw->out.buf;
60
61
  sw->out.end = sw->out.buf + buf_size - BUFFER_EXTRA;
61
62
  sw->out.allocated = true;
@@ -235,8 +236,8 @@ static void str_writer_free(void *ptr) {
235
236
 
236
237
  oj_out_free(&sw->out);
237
238
 
238
- xfree(sw->types);
239
- xfree(ptr);
239
+ OJ_R_FREE(sw->types);
240
+ OJ_R_FREE(ptr);
240
241
  }
241
242
 
242
243
  /* Document-method: new
@@ -256,7 +257,7 @@ static void str_writer_free(void *ptr) {
256
257
  * - *options* [_Hash_] formatting options
257
258
  */
258
259
  static VALUE str_writer_new(int argc, VALUE *argv, VALUE self) {
259
- StrWriter sw = ALLOC(struct _strWriter);
260
+ StrWriter sw = OJ_R_ALLOC(struct _strWriter);
260
261
 
261
262
  oj_str_writer_init(sw, 0);
262
263
  if (1 == argc) {
data/ext/oj/usual.c CHANGED
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) 2021, Peter Ohler, All rights reserved.
2
2
 
3
+ #include "mem.h"
3
4
  #include "cache.h"
4
5
  #include "oj.h"
5
6
  #include "parser.h"
@@ -34,7 +35,7 @@ static ID ltlt_id = 0;
34
35
  static ID hset_id = 0;
35
36
 
36
37
  static char *str_dup(const char *s, size_t len) {
37
- char *d = ALLOC_N(char, len + 1);
38
+ char *d = OJ_R_ALLOC_N(char, len + 1);
38
39
 
39
40
  memcpy(d, s, len);
40
41
  d[len] = '\0';
@@ -54,7 +55,7 @@ static VALUE form_attr(const char *str, size_t len) {
54
55
  char buf[256];
55
56
 
56
57
  if (sizeof(buf) - 2 <= len) {
57
- char *b = ALLOC_N(char, len + 2);
58
+ char *b = OJ_R_ALLOC_N(char, len + 2);
58
59
  ID id;
59
60
 
60
61
  *b = '@';
@@ -62,7 +63,7 @@ static VALUE form_attr(const char *str, size_t len) {
62
63
  b[len + 1] = '\0';
63
64
 
64
65
  id = rb_intern3(buf, len + 1, oj_utf8_encoding);
65
- xfree(b);
66
+ OJ_R_FREE(b);
66
67
  return id;
67
68
  }
68
69
  *buf = '@';
@@ -130,7 +131,7 @@ static void assure_cstack(Usual d) {
130
131
  long pos = d->ctail - d->chead;
131
132
 
132
133
  cap *= 2;
133
- REALLOC_N(d->chead, struct _col, cap);
134
+ OJ_R_REALLOC_N(d->chead, struct _col, cap);
134
135
  d->ctail = d->chead + pos;
135
136
  d->cend = d->chead + cap;
136
137
  }
@@ -144,7 +145,7 @@ static void push(ojParser p, VALUE v) {
144
145
  long pos = d->vtail - d->vhead;
145
146
 
146
147
  cap *= 2;
147
- REALLOC_N(d->vhead, VALUE, cap);
148
+ OJ_R_REALLOC_N(d->vhead, VALUE, cap);
148
149
  d->vtail = d->vhead + pos;
149
150
  d->vend = d->vhead + cap;
150
151
  }
@@ -194,7 +195,7 @@ static void push_key(ojParser p) {
194
195
  long pos = d->ktail - d->khead;
195
196
 
196
197
  cap *= 2;
197
- REALLOC_N(d->khead, union _key, cap);
198
+ OJ_R_REALLOC_N(d->khead, union _key, cap);
198
199
  d->ktail = d->khead + pos;
199
200
  d->kend = d->khead + cap;
200
201
  }
@@ -216,7 +217,7 @@ static void push2(ojParser p, VALUE v) {
216
217
  long pos = d->vtail - d->vhead;
217
218
 
218
219
  cap *= 2;
219
- REALLOC_N(d->vhead, VALUE, cap);
220
+ OJ_R_REALLOC_N(d->vhead, VALUE, cap);
220
221
  d->vtail = d->vhead + pos;
221
222
  d->vend = d->vhead + cap;
222
223
  }
@@ -283,7 +284,7 @@ static void close_object(ojParser p) {
283
284
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
284
285
  *vp = d->get_key(p, kp);
285
286
  if (sizeof(kp->buf) <= (size_t)kp->len) {
286
- xfree(kp->key);
287
+ OJ_R_FREE(kp->key);
287
288
  }
288
289
  }
289
290
  rb_hash_bulk_insert(d->vtail - head, head, obj);
@@ -291,7 +292,7 @@ static void close_object(ojParser p) {
291
292
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
292
293
  rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
293
294
  if (sizeof(kp->buf) <= (size_t)kp->len) {
294
- xfree(kp->key);
295
+ OJ_R_FREE(kp->key);
295
296
  }
296
297
  }
297
298
  #endif
@@ -315,7 +316,7 @@ static void close_object_class(ojParser p) {
315
316
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
316
317
  rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
317
318
  if (sizeof(kp->buf) <= (size_t)kp->len) {
318
- xfree(kp->key);
319
+ OJ_R_FREE(kp->key);
319
320
  }
320
321
  }
321
322
  d->ktail = d->khead + c->ki;
@@ -343,7 +344,7 @@ static void close_object_create(ojParser p) {
343
344
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
344
345
  *vp = d->get_key(p, kp);
345
346
  if (sizeof(kp->buf) <= (size_t)kp->len) {
346
- xfree(kp->key);
347
+ OJ_R_FREE(kp->key);
347
348
  }
348
349
  }
349
350
  rb_hash_bulk_insert(d->vtail - head, head, obj);
@@ -351,7 +352,7 @@ static void close_object_create(ojParser p) {
351
352
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
352
353
  rb_hash_aset(obj, d->get_key(p, kp), *(vp + 1));
353
354
  if (sizeof(kp->buf) <= (size_t)kp->len) {
354
- xfree(kp->key);
355
+ OJ_R_FREE(kp->key);
355
356
  }
356
357
  }
357
358
  #endif
@@ -360,7 +361,7 @@ static void close_object_create(ojParser p) {
360
361
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
361
362
  rb_funcall(obj, hset_id, 2, d->get_key(p, kp), *(vp + 1));
362
363
  if (sizeof(kp->buf) <= (size_t)kp->len) {
363
- xfree(kp->key);
364
+ OJ_R_FREE(kp->key);
364
365
  }
365
366
  }
366
367
  }
@@ -375,7 +376,7 @@ static void close_object_create(ojParser p) {
375
376
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
376
377
  *vp = d->get_key(p, kp);
377
378
  if (sizeof(kp->buf) <= (size_t)kp->len) {
378
- xfree(kp->key);
379
+ OJ_R_FREE(kp->key);
379
380
  }
380
381
  }
381
382
  rb_hash_bulk_insert(d->vtail - head, head, arg);
@@ -383,7 +384,7 @@ static void close_object_create(ojParser p) {
383
384
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
384
385
  rb_hash_aset(arg, d->get_key(p, kp), *(vp + 1));
385
386
  if (sizeof(kp->buf) <= (size_t)kp->len) {
386
- xfree(kp->key);
387
+ OJ_R_FREE(kp->key);
387
388
  }
388
389
  }
389
390
  #endif
@@ -393,7 +394,7 @@ static void close_object_create(ojParser p) {
393
394
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
394
395
  rb_ivar_set(obj, get_attr_id(p, kp), *(vp + 1));
395
396
  if (sizeof(kp->buf) <= (size_t)kp->len) {
396
- xfree(kp->key);
397
+ OJ_R_FREE(kp->key);
397
398
  }
398
399
  }
399
400
  }
@@ -621,11 +622,11 @@ static void dfree(ojParser p) {
621
622
  if (NULL != d->class_cache) {
622
623
  cache_free(d->class_cache);
623
624
  }
624
- xfree(d->vhead);
625
- xfree(d->chead);
626
- xfree(d->khead);
627
- xfree(d->create_id);
628
- xfree(p->ctx);
625
+ OJ_R_FREE(d->vhead);
626
+ OJ_R_FREE(d->chead);
627
+ OJ_R_FREE(d->khead);
628
+ OJ_R_FREE(d->create_id);
629
+ OJ_R_FREE(p->ctx);
629
630
  p->ctx = NULL;
630
631
  }
631
632
 
@@ -777,14 +778,14 @@ static VALUE opt_capacity_set(ojParser p, VALUE value) {
777
778
  if (d->vend - d->vhead < cap) {
778
779
  long pos = d->vtail - d->vhead;
779
780
 
780
- REALLOC_N(d->vhead, VALUE, cap);
781
+ OJ_R_REALLOC_N(d->vhead, VALUE, cap);
781
782
  d->vtail = d->vhead + pos;
782
783
  d->vend = d->vhead + cap;
783
784
  }
784
785
  if (d->kend - d->khead < cap) {
785
786
  long pos = d->ktail - d->khead;
786
787
 
787
- REALLOC_N(d->khead, union _key, cap);
788
+ OJ_R_REALLOC_N(d->khead, union _key, cap);
788
789
  d->ktail = d->khead + pos;
789
790
  d->kend = d->khead + cap;
790
791
  }
@@ -1111,16 +1112,16 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
1111
1112
  void oj_init_usual(ojParser p, Usual d) {
1112
1113
  int cap = 4096;
1113
1114
 
1114
- d->vhead = ALLOC_N(VALUE, cap);
1115
+ d->vhead = OJ_R_ALLOC_N(VALUE, cap);
1115
1116
  d->vend = d->vhead + cap;
1116
1117
  d->vtail = d->vhead;
1117
1118
 
1118
- d->khead = ALLOC_N(union _key, cap);
1119
+ d->khead = OJ_R_ALLOC_N(union _key, cap);
1119
1120
  d->kend = d->khead + cap;
1120
1121
  d->ktail = d->khead;
1121
1122
 
1122
1123
  cap = 256;
1123
- d->chead = ALLOC_N(struct _col, cap);
1124
+ d->chead = OJ_R_ALLOC_N(struct _col, cap);
1124
1125
  d->cend = d->chead + cap;
1125
1126
  d->ctail = d->chead;
1126
1127
 
@@ -1201,7 +1202,7 @@ void oj_init_usual(ojParser p, Usual d) {
1201
1202
  }
1202
1203
 
1203
1204
  void oj_set_parser_usual(ojParser p) {
1204
- Usual d = ALLOC(struct _usual);
1205
+ Usual d = OJ_R_ALLOC(struct _usual);
1205
1206
 
1206
1207
  oj_init_usual(p, d);
1207
1208
  }
data/ext/oj/val_stack.h CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include <stdint.h>
8
8
 
9
+ #include "mem.h"
9
10
  #include "odd.h"
10
11
  #include "ruby.h"
11
12
  #ifdef HAVE_PTHREAD_MUTEX_INIT
@@ -62,7 +63,7 @@ inline static int stack_empty(ValStack stack) {
62
63
 
63
64
  inline static void stack_cleanup(ValStack stack) {
64
65
  if (stack->base != stack->head) {
65
- xfree(stack->head);
66
+ OJ_R_FREE(stack->head);
66
67
  stack->head = NULL;
67
68
  }
68
69
  }
@@ -76,10 +77,10 @@ inline static void stack_push(ValStack stack, VALUE val, ValNext next) {
76
77
  // A realloc can trigger a GC so make sure it happens outside the lock
77
78
  // but lock before changing pointers.
78
79
  if (stack->base == stack->head) {
79
- head = ALLOC_N(struct _val, len + STACK_INC);
80
+ head = OJ_R_ALLOC_N(struct _val, len + STACK_INC);
80
81
  memcpy(head, stack->base, sizeof(struct _val) * len);
81
82
  } else {
82
- REALLOC_N(head, struct _val, len + STACK_INC);
83
+ OJ_R_REALLOC_N(head, struct _val, len + STACK_INC);
83
84
  }
84
85
  #ifdef HAVE_PTHREAD_MUTEX_INIT
85
86
  pthread_mutex_lock(&stack->mutex);
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.14.1'
4
+ VERSION = '3.14.2'
5
5
  end