oj 3.7.5 → 3.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/ext/oj/buf.h +4 -4
  3. data/ext/oj/cache8.c +3 -3
  4. data/ext/oj/cache8.h +4 -4
  5. data/ext/oj/circarray.c +1 -1
  6. data/ext/oj/circarray.h +4 -4
  7. data/ext/oj/code.h +6 -6
  8. data/ext/oj/compat.c +5 -5
  9. data/ext/oj/custom.c +15 -13
  10. data/ext/oj/dump.c +15 -5
  11. data/ext/oj/dump.h +3 -3
  12. data/ext/oj/dump_compat.c +15 -11
  13. data/ext/oj/dump_leaf.c +1 -1
  14. data/ext/oj/dump_object.c +4 -2
  15. data/ext/oj/encode.h +3 -3
  16. data/ext/oj/err.c +1 -1
  17. data/ext/oj/err.h +5 -5
  18. data/ext/oj/fast.c +14 -14
  19. data/ext/oj/hash.c +7 -7
  20. data/ext/oj/hash.h +4 -4
  21. data/ext/oj/hash_test.c +2 -2
  22. data/ext/oj/mimic_json.c +9 -9
  23. data/ext/oj/object.c +3 -3
  24. data/ext/oj/odd.c +12 -8
  25. data/ext/oj/odd.h +5 -5
  26. data/ext/oj/oj.c +14 -12
  27. data/ext/oj/oj.h +23 -23
  28. data/ext/oj/parse.c +3 -3
  29. data/ext/oj/parse.h +26 -26
  30. data/ext/oj/rails.c +27 -23
  31. data/ext/oj/rails.h +3 -3
  32. data/ext/oj/reader.h +5 -5
  33. data/ext/oj/resolve.h +3 -3
  34. data/ext/oj/rxclass.c +5 -5
  35. data/ext/oj/rxclass.h +7 -7
  36. data/ext/oj/saj.c +2 -2
  37. data/ext/oj/scp.c +3 -3
  38. data/ext/oj/sparse.c +4 -4
  39. data/ext/oj/stream_writer.c +1 -1
  40. data/ext/oj/strict.c +6 -6
  41. data/ext/oj/string_writer.c +1 -1
  42. data/ext/oj/trace.h +8 -8
  43. data/ext/oj/val_stack.c +8 -2
  44. data/ext/oj/val_stack.h +9 -9
  45. data/ext/oj/wab.c +11 -7
  46. data/lib/oj/version.rb +1 -1
  47. data/test/bug.rb +51 -0
  48. data/test/bug2.rb +10 -0
  49. data/test/bug3.rb +46 -0
  50. data/test/bug_fast.rb +32 -0
  51. data/test/bug_load.rb +24 -0
  52. data/test/crash.rb +111 -0
  53. data/test/example.rb +11 -0
  54. data/test/foo.rb +4 -29
  55. data/test/io.rb +48 -0
  56. data/test/isolated/test_mimic_rails_datetime.rb +27 -0
  57. data/test/mem.rb +12 -27
  58. data/test/mod.rb +16 -0
  59. data/test/omit.rb +20 -0
  60. data/test/rails.rb +50 -0
  61. data/test/rails_datetime_test.rb +24 -0
  62. data/test/russian.rb +18 -0
  63. data/test/struct.rb +29 -0
  64. data/test/test_serializer.rb +59 -0
  65. data/test/write_timebars.rb +31 -0
  66. data/test/x_test.rb +185 -0
  67. metadata +102 -68
  68. data/test/big.rb +0 -15
@@ -3,10 +3,10 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #ifndef __OJ_H__
7
- #define __OJ_H__
6
+ #ifndef OJ_H
7
+ #define OJ_H
8
8
 
9
- #if defined(__cplusplus)
9
+ #if defined(cplusplus)
10
10
  extern "C" {
11
11
  #if 0
12
12
  } /* satisfy cc-mode */
@@ -108,7 +108,7 @@ typedef enum {
108
108
  // Add the fast versions if necessary. Maybe unparse as well if needed.
109
109
  } DumpCaller;
110
110
 
111
- typedef struct _DumpOpts {
111
+ typedef struct _dumpOpts {
112
112
  bool use;
113
113
  char indent_str[16];
114
114
  char before_sep[16];
@@ -125,7 +125,7 @@ typedef struct _DumpOpts {
125
125
  int max_depth;
126
126
  } *DumpOpts;
127
127
 
128
- typedef struct _Options {
128
+ typedef struct _options {
129
129
  int indent; // indention for dump, default 2
130
130
  char circular; // YesNo
131
131
  char auto_define; // YesNo
@@ -156,28 +156,28 @@ typedef struct _Options {
156
156
  char float_fmt[7]; // float format for dumping, if empty use Ruby
157
157
  VALUE hash_class; // class to use in place of Hash on load
158
158
  VALUE array_class; // class to use in place of Array on load
159
- struct _DumpOpts dump_opts;
160
- struct _RxClass str_rx;
159
+ struct _dumpOpts dump_opts;
160
+ struct _rxClass str_rx;
161
161
  VALUE *ignore; // Qnil terminated array of classes or NULL
162
162
  } *Options;
163
163
 
164
- struct _Out;
165
- typedef void (*DumpFunc)(VALUE obj, int depth, struct _Out *out, bool as_ok);
164
+ struct _out;
165
+ typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
166
166
 
167
167
  // rails optimize
168
- typedef struct _ROpt {
168
+ typedef struct _rOpt {
169
169
  VALUE clas;
170
170
  bool on;
171
171
  DumpFunc dump;
172
172
  } *ROpt;
173
173
 
174
- typedef struct _ROptTable {
174
+ typedef struct _rOptTable {
175
175
  int len;
176
176
  int alen;
177
177
  ROpt table;
178
178
  } *ROptTable;
179
179
 
180
- typedef struct _Out {
180
+ typedef struct _out {
181
181
  char *buf;
182
182
  char *end;
183
183
  char *cur;
@@ -195,9 +195,9 @@ typedef struct _Out {
195
195
  ROptTable ropts;
196
196
  } *Out;
197
197
 
198
- typedef struct _StrWriter {
199
- struct _Out out;
200
- struct _Options opts;
198
+ typedef struct _strWriter {
199
+ struct _out out;
200
+ struct _options opts;
201
201
  int depth;
202
202
  char *types; // DumpType
203
203
  char *types_end;
@@ -205,8 +205,8 @@ typedef struct _StrWriter {
205
205
 
206
206
  } *StrWriter;
207
207
 
208
- typedef struct _StreamWriter {
209
- struct _StrWriter sw;
208
+ typedef struct _streamWriter {
209
+ struct _strWriter sw;
210
210
  StreamWriterType type;
211
211
  VALUE stream;
212
212
  int fd;
@@ -220,15 +220,15 @@ enum {
220
220
  RUBY_VAL = 0x03
221
221
  };
222
222
 
223
- typedef struct _Leaf {
224
- struct _Leaf *next;
223
+ typedef struct _leaf {
224
+ struct _leaf *next;
225
225
  union {
226
226
  const char *key; // hash key
227
227
  size_t index; // array index, 0 is not set
228
228
  };
229
229
  union {
230
230
  char *str; // pointer to location in json string or allocated
231
- struct _Leaf *elements; // array and hash elements
231
+ struct _leaf *elements; // array and hash elements
232
232
  VALUE value;
233
233
  };
234
234
  uint8_t rtype;
@@ -285,7 +285,7 @@ extern void oj_parse_opt_match_string(RxClass rc, VALUE ropts);
285
285
  extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
286
286
 
287
287
  extern VALUE Oj;
288
- extern struct _Options oj_default_options;
288
+ extern struct _options oj_default_options;
289
289
  extern rb_encoding *oj_utf8_encoding;
290
290
 
291
291
  extern VALUE oj_bag_class;
@@ -372,10 +372,10 @@ extern pthread_mutex_t oj_cache_mutex;
372
372
  extern VALUE oj_cache_mutex;
373
373
  #endif
374
374
 
375
- #if defined(__cplusplus)
375
+ #if defined(cplusplus)
376
376
  #if 0
377
377
  { /* satisfy cc-mode */
378
378
  #endif
379
379
  } /* extern "C" { */
380
380
  #endif
381
- #endif /* __OJ_H__ */
381
+ #endif /* OJ_H */
@@ -188,7 +188,7 @@ unicode_to_chars(ParseInfo pi, Buf buf, uint32_t code) {
188
188
  // entered at /
189
189
  static void
190
190
  read_escaped_str(ParseInfo pi, const char *start) {
191
- struct _Buf buf;
191
+ struct _buf buf;
192
192
  const char *s;
193
193
  int cnt = (int)(pi->cur - start);
194
194
  uint32_t code;
@@ -378,7 +378,7 @@ read_str(ParseInfo pi) {
378
378
 
379
379
  static void
380
380
  read_num(ParseInfo pi) {
381
- struct _NumInfo ni;
381
+ struct _numInfo ni;
382
382
  Val parent = stack_peek(&pi->stack);
383
383
 
384
384
  ni.str = pi->cur;
@@ -1050,7 +1050,7 @@ CLEANUP:
1050
1050
  case T_CLASS:
1051
1051
  case T_STRING:
1052
1052
  case T_SYMBOL: {
1053
- struct _Err err;
1053
+ struct _err err;
1054
1054
 
1055
1055
  if (Qnil == pi->err_class) {
1056
1056
  err.clas = oj_parse_error_class;
@@ -3,8 +3,8 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #ifndef __OJ_PARSE_H__
7
- #define __OJ_PARSE_H__
6
+ #ifndef OJ_PARSE_H
7
+ #define OJ_PARSE_H
8
8
 
9
9
  #include <stdarg.h>
10
10
  #include <stdio.h>
@@ -17,9 +17,9 @@
17
17
  #include "reader.h"
18
18
  #include "rxclass.h"
19
19
 
20
- struct _RxClass;
20
+ struct _rxClass;
21
21
 
22
- typedef struct _NumInfo {
22
+ typedef struct _numInfo {
23
23
  int64_t i;
24
24
  int64_t num;
25
25
  int64_t div;
@@ -35,39 +35,39 @@ typedef struct _NumInfo {
35
35
  int no_big;
36
36
  } *NumInfo;
37
37
 
38
- typedef struct _ParseInfo {
38
+ typedef struct _parseInfo {
39
39
  // used for the string parser
40
40
  const char *json;
41
41
  const char *cur;
42
42
  const char *end;
43
43
  // used for the stream parser
44
- struct _Reader rd;
44
+ struct _reader rd;
45
45
 
46
- struct _Err err;
47
- struct _Options options;
46
+ struct _err err;
47
+ struct _options options;
48
48
  VALUE handler;
49
- struct _ValStack stack;
49
+ struct _valStack stack;
50
50
  CircArray circ_array;
51
- struct _RxClass str_rx;
51
+ struct _rxClass str_rx;
52
52
  int expect_value;
53
53
  int max_depth; // just for the json gem
54
54
  VALUE proc;
55
- VALUE (*start_hash)(struct _ParseInfo *pi);
56
- void (*end_hash)(struct _ParseInfo *pi);
57
- VALUE (*hash_key)(struct _ParseInfo *pi, const char *key, size_t klen);
58
- void (*hash_set_cstr)(struct _ParseInfo *pi, Val kval, const char *str, size_t len, const char *orig);
59
- void (*hash_set_num)(struct _ParseInfo *pi, Val kval, NumInfo ni);
60
- void (*hash_set_value)(struct _ParseInfo *pi, Val kval, VALUE value);
55
+ VALUE (*start_hash)(struct _parseInfo *pi);
56
+ void (*end_hash)(struct _parseInfo *pi);
57
+ VALUE (*hash_key)(struct _parseInfo *pi, const char *key, size_t klen);
58
+ void (*hash_set_cstr)(struct _parseInfo *pi, Val kval, const char *str, size_t len, const char *orig);
59
+ void (*hash_set_num)(struct _parseInfo *pi, Val kval, NumInfo ni);
60
+ void (*hash_set_value)(struct _parseInfo *pi, Val kval, VALUE value);
61
61
 
62
- VALUE (*start_array)(struct _ParseInfo *pi);
63
- void (*end_array)(struct _ParseInfo *pi);
64
- void (*array_append_cstr)(struct _ParseInfo *pi, const char *str, size_t len, const char *orig);
65
- void (*array_append_num)(struct _ParseInfo *pi, NumInfo ni);
66
- void (*array_append_value)(struct _ParseInfo *pi, VALUE value);
62
+ VALUE (*start_array)(struct _parseInfo *pi);
63
+ void (*end_array)(struct _parseInfo *pi);
64
+ void (*array_append_cstr)(struct _parseInfo *pi, const char *str, size_t len, const char *orig);
65
+ void (*array_append_num)(struct _parseInfo *pi, NumInfo ni);
66
+ void (*array_append_value)(struct _parseInfo *pi, VALUE value);
67
67
 
68
- void (*add_cstr)(struct _ParseInfo *pi, const char *str, size_t len, const char *orig);
69
- void (*add_num)(struct _ParseInfo *pi, NumInfo ni);
70
- void (*add_value)(struct _ParseInfo *pi, VALUE val);
68
+ void (*add_cstr)(struct _parseInfo *pi, const char *str, size_t len, const char *orig);
69
+ void (*add_num)(struct _parseInfo *pi, NumInfo ni);
70
+ void (*add_value)(struct _parseInfo *pi, VALUE val);
71
71
  VALUE err_class;
72
72
  bool has_callbacks;
73
73
  } *ParseInfo;
@@ -87,7 +87,7 @@ extern VALUE oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd);
87
87
 
88
88
  static inline void
89
89
  parse_info_init(ParseInfo pi) {
90
- memset(pi, 0, sizeof(struct _ParseInfo));
90
+ memset(pi, 0, sizeof(struct _parseInfo));
91
91
  }
92
92
 
93
93
  static inline bool
@@ -108,4 +108,4 @@ empty_ok(Options options) {
108
108
  return Yes == options->empty_string;
109
109
  }
110
110
 
111
- #endif /* __OJ_PARSE_H__ */
111
+ #endif /* OJ_PARSE_H */
@@ -12,9 +12,9 @@
12
12
  #define OJ_INFINITY (1.0/0.0)
13
13
 
14
14
  // TBD keep static array of strings and functions to help with rails optimization
15
- typedef struct _Encoder {
16
- struct _ROptTable ropts;
17
- struct _Options opts;
15
+ typedef struct _encoder {
16
+ struct _rOptTable ropts;
17
+ struct _options opts;
18
18
  VALUE arg;
19
19
  } *Encoder;
20
20
 
@@ -28,7 +28,7 @@ static void dump_rails_val(VALUE obj, int depth, Out out, bool as_ok);
28
28
 
29
29
  extern VALUE Oj;
30
30
 
31
- static struct _ROptTable ropts = { 0, 0, NULL };
31
+ static struct _rOptTable ropts = { 0, 0, NULL };
32
32
 
33
33
  static VALUE encoder_class = Qnil;
34
34
  static bool escape_html = true;
@@ -79,8 +79,8 @@ copy_opts(ROptTable src, ROptTable dest) {
79
79
  if (NULL == src->table) {
80
80
  dest->table = NULL;
81
81
  } else {
82
- dest->table = ALLOC_N(struct _ROpt, dest->alen);
83
- memcpy(dest->table, src->table, sizeof(struct _ROpt) * dest->alen);
82
+ dest->table = ALLOC_N(struct _rOpt, dest->alen);
83
+ memcpy(dest->table, src->table, sizeof(struct _rOpt) * dest->alen);
84
84
  }
85
85
  return NULL;
86
86
  }
@@ -301,14 +301,18 @@ dump_sec_nano(VALUE obj, time_t sec, long nsec, Out out) {
301
301
 
302
302
  static void
303
303
  dump_time(VALUE obj, int depth, Out out, bool as_ok) {
304
- time_t sec;
304
+ long long sec;
305
305
  long long nsec;
306
306
 
307
307
  #ifdef HAVE_RB_TIME_TIMESPEC
308
- {
308
+ if (16 <= sizeof(struct timespec)) {
309
309
  struct timespec ts = rb_time_timespec(obj);
310
- sec = ts.tv_sec;
310
+
311
+ sec = (long long)ts.tv_sec;
311
312
  nsec = ts.tv_nsec;
313
+ } else {
314
+ sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
315
+ nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
312
316
  }
313
317
  #else
314
318
  sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
@@ -339,7 +343,7 @@ dump_to_s(VALUE obj, int depth, Out out, bool as_ok) {
339
343
 
340
344
  static ID parameters_id = 0;
341
345
 
342
- typedef struct _StrLen {
346
+ typedef struct _strLen {
343
347
  const char *str;
344
348
  int len;
345
349
  } *StrLen;
@@ -362,7 +366,7 @@ columns_array(VALUE rcols, int *ccnt) {
362
366
  int cnt = (int)RARRAY_LEN(rcols);
363
367
 
364
368
  *ccnt = cnt;
365
- cols = ALLOC_N(struct _StrLen, cnt);
369
+ cols = ALLOC_N(struct _strLen, cnt);
366
370
  for (i = 0, cp = cols; i < cnt; i++, cp++) {
367
371
  v = rb_ary_entry(rcols, i);
368
372
  if (T_STRING != rb_type(v)) {
@@ -500,7 +504,7 @@ dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok) {
500
504
  *out->cur++ = ']';
501
505
  }
502
506
 
503
- typedef struct _NamedFunc {
507
+ typedef struct _namedFunc {
504
508
  const char *name;
505
509
  DumpFunc func;
506
510
  } *NamedFunc;
@@ -557,7 +561,7 @@ dump_regexp(VALUE obj, int depth, Out out, bool as_ok) {
557
561
  dump_as_string(obj, depth, out, as_ok);
558
562
  }
559
563
 
560
- static struct _NamedFunc dump_map[] = {
564
+ static struct _namedFunc dump_map[] = {
561
565
  { "ActionController::Parameters", dump_actioncontroller_parameters },
562
566
  { "ActiveRecord::Result", dump_activerecord_result },
563
567
  { "ActiveSupport::TimeWithZone", dump_timewithzone },
@@ -591,12 +595,12 @@ create_opt(ROptTable rot, VALUE clas) {
591
595
  rot->len++;
592
596
  if (NULL == rot->table) {
593
597
  rot->alen = 256;
594
- rot->table = ALLOC_N(struct _ROpt, rot->alen);
595
- memset(rot->table, 0, sizeof(struct _ROpt) * rot->alen);
598
+ rot->table = ALLOC_N(struct _rOpt, rot->alen);
599
+ memset(rot->table, 0, sizeof(struct _rOpt) * rot->alen);
596
600
  } else if (rot->alen <= rot->len) {
597
601
  rot->alen *= 2;
598
- REALLOC_N(rot->table, struct _ROpt, rot->alen);
599
- memset(rot->table + olen, 0, sizeof(struct _ROpt) * olen);
602
+ REALLOC_N(rot->table, struct _rOpt, rot->alen);
603
+ memset(rot->table + olen, 0, sizeof(struct _rOpt) * olen);
600
604
  }
601
605
  if (0 == olen) {
602
606
  ro = rot->table;
@@ -607,7 +611,7 @@ create_opt(ROptTable rot, VALUE clas) {
607
611
 
608
612
  for (i = 0, ro = rot->table; i < olen; i++, ro++) {
609
613
  if (clas < ro->clas) {
610
- memmove(ro + 1, ro, sizeof(struct _ROpt) * (olen - i));
614
+ memmove(ro + 1, ro, sizeof(struct _rOpt) * (olen - i));
611
615
  break;
612
616
  }
613
617
  }
@@ -674,7 +678,7 @@ encoder_mark(void *ptr) {
674
678
  */
675
679
  static VALUE
676
680
  encoder_new(int argc, VALUE *argv, VALUE self) {
677
- Encoder e = ALLOC(struct _Encoder);
681
+ Encoder e = ALLOC(struct _encoder);
678
682
 
679
683
  e->opts = oj_default_options;
680
684
  e->arg = Qnil;
@@ -888,7 +892,7 @@ rails_optimized(VALUE self, VALUE clas) {
888
892
  return (ro->on) ? Qtrue : Qfalse;
889
893
  }
890
894
 
891
- typedef struct _OO {
895
+ typedef struct _oo {
892
896
  Out out;
893
897
  VALUE obj;
894
898
  } *OO;
@@ -905,10 +909,10 @@ protect_dump(VALUE ov) {
905
909
  static VALUE
906
910
  encode(VALUE obj, ROptTable ropts, Options opts, int argc, VALUE *argv) {
907
911
  char buf[4096];
908
- struct _Out out;
909
- struct _Options copts = *opts;
912
+ struct _out out;
913
+ struct _options copts = *opts;
910
914
  volatile VALUE rstr = Qnil;
911
- struct _OO oo;
915
+ struct _oo oo;
912
916
  int line = 0;
913
917
 
914
918
  oo.out = &out;
@@ -3,8 +3,8 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #ifndef __OJ_RAILS_H__
7
- #define __OJ_RAILS_H__
6
+ #ifndef OJ_RAILS_H
7
+ #define OJ_RAILS_H
8
8
 
9
9
  #include "dump.h"
10
10
 
@@ -18,4 +18,4 @@ extern bool oj_rails_float_opt;
18
18
  extern VALUE oj_optimize_rails(VALUE self);
19
19
 
20
20
 
21
- #endif /* __OJ_RAILS_H__ */
21
+ #endif /* OJ_RAILS_H */
@@ -3,10 +3,10 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #ifndef __OJ_READER_H__
7
- #define __OJ_READER_H__
6
+ #ifndef OJ_READER_H
7
+ #define OJ_READER_H
8
8
 
9
- typedef struct _Reader {
9
+ typedef struct _reader {
10
10
  char base[0x00001000];
11
11
  char *head;
12
12
  char *end;
@@ -18,7 +18,7 @@ typedef struct _Reader {
18
18
  int line;
19
19
  int col;
20
20
  int free_head;
21
- int (*read_func)(struct _Reader *reader);
21
+ int (*read_func)(struct _reader *reader);
22
22
  union {
23
23
  int fd;
24
24
  VALUE io;
@@ -148,4 +148,4 @@ is_white(char c) {
148
148
  return 0;
149
149
  }
150
150
 
151
- #endif /* __OJ_READER_H__ */
151
+ #endif /* OJ_READER_H */
@@ -3,12 +3,12 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
- #ifndef __OJ_RESOLVE_H__
7
- #define __OJ_RESOLVE_H__
6
+ #ifndef OJ_RESOLVE_H
7
+ #define OJ_RESOLVE_H
8
8
 
9
9
  #include "ruby.h"
10
10
 
11
11
  extern VALUE oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE error_class);
12
12
  extern VALUE oj_name2struct(ParseInfo pi, VALUE nameVal, VALUE error_class);
13
13
 
14
- #endif /* __OJ_RESOLVE_H__ */
14
+ #endif /* OJ_RESOLVE_H */