oj 3.10.6 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/ext/oj/buf.h +36 -68
  4. data/ext/oj/cache8.c +59 -62
  5. data/ext/oj/cache8.h +9 -36
  6. data/ext/oj/circarray.c +36 -42
  7. data/ext/oj/circarray.h +12 -13
  8. data/ext/oj/code.c +172 -179
  9. data/ext/oj/code.h +22 -24
  10. data/ext/oj/compat.c +168 -181
  11. data/ext/oj/custom.c +800 -864
  12. data/ext/oj/dump.c +774 -776
  13. data/ext/oj/dump.h +50 -55
  14. data/ext/oj/dump_compat.c +2 -4
  15. data/ext/oj/dump_leaf.c +118 -162
  16. data/ext/oj/dump_object.c +610 -632
  17. data/ext/oj/dump_strict.c +319 -331
  18. data/ext/oj/encode.h +4 -33
  19. data/ext/oj/err.c +40 -29
  20. data/ext/oj/err.h +25 -44
  21. data/ext/oj/extconf.rb +2 -1
  22. data/ext/oj/fast.c +1054 -1081
  23. data/ext/oj/hash.c +78 -95
  24. data/ext/oj/hash.h +10 -35
  25. data/ext/oj/hash_test.c +451 -472
  26. data/ext/oj/mimic_json.c +415 -402
  27. data/ext/oj/object.c +588 -532
  28. data/ext/oj/odd.c +124 -132
  29. data/ext/oj/odd.h +28 -29
  30. data/ext/oj/oj.c +1178 -905
  31. data/ext/oj/oj.h +289 -298
  32. data/ext/oj/parse.c +946 -870
  33. data/ext/oj/parse.h +81 -79
  34. data/ext/oj/rails.c +837 -842
  35. data/ext/oj/rails.h +8 -11
  36. data/ext/oj/reader.c +139 -147
  37. data/ext/oj/reader.h +68 -84
  38. data/ext/oj/resolve.c +44 -47
  39. data/ext/oj/resolve.h +4 -6
  40. data/ext/oj/rxclass.c +69 -73
  41. data/ext/oj/rxclass.h +13 -14
  42. data/ext/oj/saj.c +453 -484
  43. data/ext/oj/scp.c +88 -113
  44. data/ext/oj/sparse.c +783 -714
  45. data/ext/oj/stream_writer.c +123 -157
  46. data/ext/oj/strict.c +133 -106
  47. data/ext/oj/string_writer.c +199 -247
  48. data/ext/oj/trace.c +34 -41
  49. data/ext/oj/trace.h +15 -15
  50. data/ext/oj/util.c +104 -104
  51. data/ext/oj/util.h +4 -3
  52. data/ext/oj/val_stack.c +48 -76
  53. data/ext/oj/val_stack.h +80 -115
  54. data/ext/oj/wab.c +317 -328
  55. data/lib/oj.rb +0 -8
  56. data/lib/oj/bag.rb +1 -0
  57. data/lib/oj/easy_hash.rb +5 -4
  58. data/lib/oj/mimic.rb +45 -13
  59. data/lib/oj/version.rb +1 -1
  60. data/pages/Modes.md +1 -0
  61. data/pages/Options.md +23 -11
  62. data/test/activerecord/result_test.rb +7 -2
  63. data/test/foo.rb +8 -40
  64. data/test/helper.rb +10 -0
  65. data/test/json_gem/json_common_interface_test.rb +8 -3
  66. data/test/json_gem/json_generator_test.rb +15 -3
  67. data/test/json_gem/test_helper.rb +8 -0
  68. data/test/perf.rb +1 -1
  69. data/test/perf_scp.rb +11 -10
  70. data/test/perf_strict.rb +17 -23
  71. data/test/prec.rb +23 -0
  72. data/test/sample_json.rb +1 -1
  73. data/test/test_compat.rb +16 -3
  74. data/test/test_custom.rb +11 -0
  75. data/test/test_fast.rb +32 -2
  76. data/test/test_generate.rb +21 -0
  77. data/test/test_hash.rb +10 -0
  78. data/test/test_rails.rb +9 -0
  79. data/test/test_scp.rb +1 -1
  80. data/test/test_various.rb +4 -2
  81. metadata +89 -85
data/ext/oj/trace.c CHANGED
@@ -1,30 +1,27 @@
1
- /* trace.h
2
- * Copyright (c) 2018, Peter Ohler
3
- * All rights reserved.
4
- */
1
+ // Copyright (c) 2018 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
5
3
 
6
- #include "parse.h"
7
4
  #include "trace.h"
8
5
 
9
- #define MAX_INDENT 256
6
+ #include "parse.h"
7
+
8
+ #define MAX_INDENT 256
10
9
 
11
- static void
12
- fill_indent(char *indent, int depth) {
10
+ static void fill_indent(char *indent, int depth) {
13
11
  if (MAX_INDENT <= depth) {
14
- depth = MAX_INDENT - 1;
12
+ depth = MAX_INDENT - 1;
15
13
  } else if (depth < 0) {
16
- depth = 0;
14
+ depth = 0;
17
15
  }
18
16
  if (0 < depth) {
19
- memset(indent, ' ', depth);
17
+ memset(indent, ' ', depth);
20
18
  }
21
19
  indent[depth] = '\0';
22
20
  }
23
21
 
24
- void
25
- oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where) {
26
- char fmt[64];
27
- char indent[MAX_INDENT];
22
+ void oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where) {
23
+ char fmt[64];
24
+ char indent[MAX_INDENT];
28
25
 
29
26
  depth *= 2;
30
27
  fill_indent(indent, depth);
@@ -32,47 +29,43 @@ oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, Tra
32
29
  printf(fmt, file, line, indent, func, rb_obj_classname(obj));
33
30
  }
34
31
 
35
- void
36
- oj_trace_parse_call(const char *func, ParseInfo pi, const char *file, int line, VALUE obj) {
37
- char fmt[64];
38
- char indent[MAX_INDENT];
39
- int depth = (int)(stack_size(&pi->stack) * 2);
40
-
32
+ void oj_trace_parse_call(const char *func, ParseInfo pi, const char *file, int line, VALUE obj) {
33
+ char fmt[64];
34
+ char indent[MAX_INDENT];
35
+ int depth = (int)(stack_size(&pi->stack) * 2);
36
+
41
37
  fill_indent(indent, depth);
42
38
  sprintf(fmt, "#0:%%13s:%%3d:Oj:-:%%%ds %%s %%s\n", depth);
43
39
  printf(fmt, file, line, indent, func, rb_obj_classname(obj));
44
40
  }
45
41
 
46
- void
47
- oj_trace_parse_in(const char *func, ParseInfo pi, const char *file, int line) {
48
- char fmt[64];
49
- char indent[MAX_INDENT];
50
- int depth = (int)(stack_size(&pi->stack) * 2);
51
-
42
+ void oj_trace_parse_in(const char *func, ParseInfo pi, const char *file, int line) {
43
+ char fmt[64];
44
+ char indent[MAX_INDENT];
45
+ int depth = (int)(stack_size(&pi->stack) * 2);
46
+
52
47
  fill_indent(indent, depth);
53
48
  sprintf(fmt, "#0:%%13s:%%3d:Oj:}:%%%ds %%s\n", depth);
54
49
  printf(fmt, file, line, indent, func);
55
50
  }
56
51
 
57
- void
58
- oj_trace_parse_hash_end(ParseInfo pi, const char *file, int line) {
59
- char fmt[64];
60
- char indent[MAX_INDENT];
61
- int depth = (int)(stack_size(&pi->stack) * 2 - 2);
62
- Val v = stack_peek(&pi->stack);
63
- VALUE obj = v->val;
64
-
52
+ void oj_trace_parse_hash_end(ParseInfo pi, const char *file, int line) {
53
+ char fmt[64];
54
+ char indent[MAX_INDENT];
55
+ int depth = (int)(stack_size(&pi->stack) * 2 - 2);
56
+ Val v = stack_peek(&pi->stack);
57
+ VALUE obj = v->val;
58
+
65
59
  fill_indent(indent, depth);
66
60
  sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds hash_end %%s\n", depth);
67
61
  printf(fmt, file, line, indent, rb_obj_classname(obj));
68
62
  }
69
63
 
70
- void
71
- oj_trace_parse_array_end(ParseInfo pi, const char *file, int line) {
72
- char fmt[64];
73
- char indent[MAX_INDENT];
74
- int depth = (int)(stack_size(&pi->stack) * 2);
75
-
64
+ void oj_trace_parse_array_end(ParseInfo pi, const char *file, int line) {
65
+ char fmt[64];
66
+ char indent[MAX_INDENT];
67
+ int depth = (int)(stack_size(&pi->stack) * 2);
68
+
76
69
  fill_indent(indent, depth);
77
70
  sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds array_ned\n", depth);
78
71
  printf(fmt, file, line, indent);
data/ext/oj/trace.h CHANGED
@@ -1,28 +1,28 @@
1
- /* trace.h
2
- * Copyright (c) 2018, Peter Ohler
3
- * All rights reserved.
4
- */
1
+ // Copyright (c) 2018 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
5
3
 
6
4
  #ifndef OJ_TRACE_H
7
5
  #define OJ_TRACE_H
8
6
 
9
- #include <stdbool.h>
10
7
  #include <ruby.h>
8
+ #include <stdbool.h>
11
9
 
12
10
  typedef enum {
13
- TraceIn = '}',
14
- TraceOut = '{',
15
- TraceCall = '-',
16
- TraceRubyIn = '>',
17
- TraceRubyOut = '<',
11
+ TraceIn = '}',
12
+ TraceOut = '{',
13
+ TraceCall = '-',
14
+ TraceRubyIn = '>',
15
+ TraceRubyOut = '<',
18
16
  } TraceWhere;
19
17
 
20
18
  struct _parseInfo;
21
19
 
22
- extern void oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where);
23
- extern void oj_trace_parse_in(const char *func, struct _parseInfo *pi, const char *file, int line);
24
- extern void oj_trace_parse_call(const char *func, struct _parseInfo *pi, const char *file, int line, VALUE obj);
25
- extern void oj_trace_parse_hash_end(struct _parseInfo *pi, const char *file, int line);
26
- extern void oj_trace_parse_array_end(struct _parseInfo *pi, const char *file, int line);
20
+ extern void
21
+ oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where);
22
+ extern void oj_trace_parse_in(const char *func, struct _parseInfo *pi, const char *file, int line);
23
+ extern void
24
+ oj_trace_parse_call(const char *func, struct _parseInfo *pi, const char *file, int line, VALUE obj);
25
+ extern void oj_trace_parse_hash_end(struct _parseInfo *pi, const char *file, int line);
26
+ extern void oj_trace_parse_array_end(struct _parseInfo *pi, const char *file, int line);
27
27
 
28
28
  #endif /* OJ_TRACE_H */
data/ext/oj/util.c CHANGED
@@ -1,4 +1,5 @@
1
- // Copyright (c) 2019, Peter Ohler, All rights reserved.
1
+ // Copyright (c) 2019 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #include "util.h"
4
5
 
@@ -8,129 +9,128 @@
8
9
  #include <string.h>
9
10
  #include <time.h>
10
11
 
11
- #define SECS_PER_DAY 86400LL
12
- #define SECS_PER_YEAR 31536000LL
13
- #define SECS_PER_LEAP 31622400LL
14
- #define SECS_PER_QUAD_YEAR (SECS_PER_YEAR * 3 + SECS_PER_LEAP)
15
- #define SECS_PER_CENT (SECS_PER_QUAD_YEAR * 24 + SECS_PER_YEAR * 4)
16
- #define SECS_PER_LEAP_CENT (SECS_PER_CENT + SECS_PER_DAY)
17
- #define SECS_PER_QUAD_CENT (SECS_PER_CENT * 4 + SECS_PER_DAY)
12
+ #define SECS_PER_DAY 86400LL
13
+ #define SECS_PER_YEAR 31536000LL
14
+ #define SECS_PER_LEAP 31622400LL
15
+ #define SECS_PER_QUAD_YEAR (SECS_PER_YEAR * 3 + SECS_PER_LEAP)
16
+ #define SECS_PER_CENT (SECS_PER_QUAD_YEAR * 24 + SECS_PER_YEAR * 4)
17
+ #define SECS_PER_LEAP_CENT (SECS_PER_CENT + SECS_PER_DAY)
18
+ #define SECS_PER_QUAD_CENT (SECS_PER_CENT * 4 + SECS_PER_DAY)
18
19
 
19
- static int64_t eom_secs[] = {
20
- 2678400, // January (31)
21
- 5097600, // February (28) 2419200 2505600
22
- 7776000, // March (31)
23
- 10368000, // April (30 2592000
24
- 13046400, // May (31)
25
- 15638400, // June (30)
26
- 18316800, // July (31)
27
- 20995200, // August (31)
28
- 23587200, // September (30)
29
- 26265600, // October (31)
30
- 28857600, // November (30)
31
- 31536000, // December (31)
20
+ static int64_t eom_secs[] = {
21
+ 2678400, // January (31)
22
+ 5097600, // February (28) 2419200 2505600
23
+ 7776000, // March (31)
24
+ 10368000, // April (30 2592000
25
+ 13046400, // May (31)
26
+ 15638400, // June (30)
27
+ 18316800, // July (31)
28
+ 20995200, // August (31)
29
+ 23587200, // September (30)
30
+ 26265600, // October (31)
31
+ 28857600, // November (30)
32
+ 31536000, // December (31)
32
33
  };
33
34
 
34
- static int64_t eom_leap_secs[] = {
35
- 2678400, // January (31)
36
- 5184000, // February (28) 2419200 2505600
37
- 7862400, // March (31)
38
- 10454400, // April (30 2592000
39
- 13132800, // May (31)
40
- 15724800, // June (30)
41
- 18403200, // July (31)
42
- 21081600, // August (31)
43
- 23673600, // September (30)
44
- 26352000, // October (31)
45
- 28944000, // November (30)
46
- 31622400, // December (31)
35
+ static int64_t eom_leap_secs[] = {
36
+ 2678400, // January (31)
37
+ 5184000, // February (28) 2419200 2505600
38
+ 7862400, // March (31)
39
+ 10454400, // April (30 2592000
40
+ 13132800, // May (31)
41
+ 15724800, // June (30)
42
+ 18403200, // July (31)
43
+ 21081600, // August (31)
44
+ 23673600, // September (30)
45
+ 26352000, // October (31)
46
+ 28944000, // November (30)
47
+ 31622400, // December (31)
47
48
  };
48
49
 
50
+ void sec_as_time(int64_t secs, TimeInfo ti) {
51
+ int64_t qc = 0;
52
+ int64_t c = 0;
53
+ int64_t qy = 0;
54
+ int64_t y = 0;
55
+ bool leap = false;
56
+ int64_t *ms;
57
+ int m;
58
+ int shift = 0;
49
59
 
50
- void
51
- sec_as_time(int64_t secs, TimeInfo ti) {
52
- int64_t qc = 0;
53
- int64_t c = 0;
54
- int64_t qy = 0;
55
- int64_t y = 0;
56
- bool leap = false;
57
- int64_t *ms;
58
- int m;
59
- int shift = 0;
60
-
61
- secs += 62167219200LL; // normalize to first day of the year 0
60
+ secs += 62167219200LL; // normalize to first day of the year 0
62
61
  if (secs < 0) {
63
- shift = -secs / SECS_PER_QUAD_CENT;
64
- shift++;
65
- secs += shift * SECS_PER_QUAD_CENT;
62
+ shift = -secs / SECS_PER_QUAD_CENT;
63
+ shift++;
64
+ secs += shift * SECS_PER_QUAD_CENT;
66
65
  }
67
- qc = secs / SECS_PER_QUAD_CENT;
66
+ qc = secs / SECS_PER_QUAD_CENT;
68
67
  secs = secs - qc * SECS_PER_QUAD_CENT;
69
68
  if (secs < SECS_PER_LEAP) {
70
- leap = true;
69
+ leap = true;
71
70
  } else if (secs < SECS_PER_QUAD_YEAR) {
72
- if (SECS_PER_LEAP <= secs) {
73
- secs -= SECS_PER_LEAP;
74
- y = secs / SECS_PER_YEAR;
75
- secs = secs - y * SECS_PER_YEAR;
76
- y++;
77
- leap = false;
78
- }
79
- } else if (secs < SECS_PER_LEAP_CENT) { // first century in 400 years is a leap century (one extra day)
80
- qy = secs / SECS_PER_QUAD_YEAR;
81
- secs = secs - qy * SECS_PER_QUAD_YEAR;
82
- if (secs < SECS_PER_LEAP) {
83
- leap = true;
84
- } else {
85
- secs -= SECS_PER_LEAP;
86
- y = secs / SECS_PER_YEAR;
87
- secs = secs - y * SECS_PER_YEAR;
88
- y++;
89
- }
71
+ if (SECS_PER_LEAP <= secs) {
72
+ secs -= SECS_PER_LEAP;
73
+ y = secs / SECS_PER_YEAR;
74
+ secs = secs - y * SECS_PER_YEAR;
75
+ y++;
76
+ leap = false;
77
+ }
78
+ } else if (secs < SECS_PER_LEAP_CENT) { // first century in 400 years is a leap century (one
79
+ // extra day)
80
+ qy = secs / SECS_PER_QUAD_YEAR;
81
+ secs = secs - qy * SECS_PER_QUAD_YEAR;
82
+ if (secs < SECS_PER_LEAP) {
83
+ leap = true;
84
+ } else {
85
+ secs -= SECS_PER_LEAP;
86
+ y = secs / SECS_PER_YEAR;
87
+ secs = secs - y * SECS_PER_YEAR;
88
+ y++;
89
+ }
90
90
  } else {
91
- secs -= SECS_PER_LEAP_CENT;
92
- c = secs / SECS_PER_CENT;
93
- secs = secs - c * SECS_PER_CENT;
94
- c++;
95
- if (secs < SECS_PER_YEAR * 4) {
96
- y = secs / SECS_PER_YEAR;
97
- secs = secs - y * SECS_PER_YEAR;
98
- } else {
99
- secs -= SECS_PER_YEAR * 4;
100
- qy = secs / SECS_PER_QUAD_YEAR;
101
- secs = secs - qy * SECS_PER_QUAD_YEAR;
102
- qy++;
103
- if (secs < SECS_PER_LEAP) {
104
- leap = true;
105
- } else {
106
- secs -= SECS_PER_LEAP;
107
- y = secs / SECS_PER_YEAR;
108
- secs = secs - y * SECS_PER_YEAR;
109
- y++;
110
- }
111
- }
91
+ secs -= SECS_PER_LEAP_CENT;
92
+ c = secs / SECS_PER_CENT;
93
+ secs = secs - c * SECS_PER_CENT;
94
+ c++;
95
+ if (secs < SECS_PER_YEAR * 4) {
96
+ y = secs / SECS_PER_YEAR;
97
+ secs = secs - y * SECS_PER_YEAR;
98
+ } else {
99
+ secs -= SECS_PER_YEAR * 4;
100
+ qy = secs / SECS_PER_QUAD_YEAR;
101
+ secs = secs - qy * SECS_PER_QUAD_YEAR;
102
+ qy++;
103
+ if (secs < SECS_PER_LEAP) {
104
+ leap = true;
105
+ } else {
106
+ secs -= SECS_PER_LEAP;
107
+ y = secs / SECS_PER_YEAR;
108
+ secs = secs - y * SECS_PER_YEAR;
109
+ y++;
110
+ }
111
+ }
112
112
  }
113
113
  ti->year = (int)((qc - (int64_t)shift) * 400 + c * 100 + qy * 4 + y);
114
114
  if (leap) {
115
- ms = eom_leap_secs;
115
+ ms = eom_leap_secs;
116
116
  } else {
117
- ms = eom_secs;
117
+ ms = eom_secs;
118
118
  }
119
119
  for (m = 1; m <= 12; m++, ms++) {
120
- if (secs < *ms) {
121
- if (1 < m) {
122
- secs -= *(ms - 1);
123
- }
124
- ti->mon = m;
125
- break;
126
- }
120
+ if (secs < *ms) {
121
+ if (1 < m) {
122
+ secs -= *(ms - 1);
123
+ }
124
+ ti->mon = m;
125
+ break;
126
+ }
127
127
  }
128
128
  ti->day = (int)(secs / 86400LL);
129
- secs = secs - (int64_t)ti->day * 86400LL;
129
+ secs = secs - (int64_t)ti->day * 86400LL;
130
130
  ti->day++;
131
131
  ti->hour = (int)(secs / 3600LL);
132
- secs = secs - (int64_t)ti->hour * 3600LL;
133
- ti->min = (int)(secs / 60LL);
134
- secs = secs - (int64_t)ti->min * 60LL;
135
- ti->sec = (int)secs;
132
+ secs = secs - (int64_t)ti->hour * 3600LL;
133
+ ti->min = (int)(secs / 60LL);
134
+ secs = secs - (int64_t)ti->min * 60LL;
135
+ ti->sec = (int)secs;
136
136
  }
data/ext/oj/util.h CHANGED
@@ -1,4 +1,5 @@
1
- // Copyright (c) 2019, Peter Ohler, All rights reserved.
1
+ // Copyright (c) 2019 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #ifndef OJ_UTIL_H
4
5
  #define OJ_UTIL_H
@@ -12,8 +13,8 @@ typedef struct _timeInfo {
12
13
  int day;
13
14
  int mon;
14
15
  int year;
15
- } *TimeInfo;
16
+ } * TimeInfo;
16
17
 
17
- extern void sec_as_time(int64_t secs, TimeInfo ti);
18
+ extern void sec_as_time(int64_t secs, TimeInfo ti);
18
19
 
19
20
  #endif /* OJ_UTIL_H */
data/ext/oj/val_stack.c CHANGED
@@ -1,46 +1,19 @@
1
- /* val_stack.c
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- *
5
- * Redistribution and use in source and binary forms, with or without
6
- * modification, are permitted provided that the following conditions are met:
7
- *
8
- * - Redistributions of source code must retain the above copyright notice, this
9
- * list of conditions and the following disclaimer.
10
- *
11
- * - Redistributions in binary form must reproduce the above copyright notice,
12
- * this list of conditions and the following disclaimer in the documentation
13
- * and/or other materials provided with the distribution.
14
- *
15
- * - Neither the name of Peter Ohler nor the names of its contributors may be
16
- * used to endorse or promote products derived from this software without
17
- * specific prior written permission.
18
- *
19
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */
1
+ // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
3
+
4
+ #include "val_stack.h"
30
5
 
31
6
  #include <string.h>
32
7
 
33
- #include "oj.h"
34
8
  #include "odd.h"
35
- #include "val_stack.h"
9
+ #include "oj.h"
36
10
 
37
- static void
38
- mark(void *ptr) {
39
- ValStack stack = (ValStack)ptr;
40
- Val v;
11
+ static void mark(void *ptr) {
12
+ ValStack stack = (ValStack)ptr;
13
+ Val v;
41
14
 
42
15
  if (0 == ptr) {
43
- return;
16
+ return;
44
17
  }
45
18
  #ifdef HAVE_PTHREAD_MUTEX_INIT
46
19
  pthread_mutex_lock(&stack->mutex);
@@ -49,22 +22,22 @@ mark(void *ptr) {
49
22
  rb_gc_mark(stack->mutex);
50
23
  #endif
51
24
  for (v = stack->head; v < stack->tail; v++) {
52
- if (Qnil != v->val && Qundef != v->val) {
53
- rb_gc_mark(v->val);
54
- }
55
- if (Qnil != v->key_val && Qundef != v->key_val) {
56
- rb_gc_mark(v->key_val);
57
- }
58
- if (NULL != v->odd_args) {
59
- VALUE *a;
60
- int i;
25
+ if (Qnil != v->val && Qundef != v->val) {
26
+ rb_gc_mark(v->val);
27
+ }
28
+ if (Qnil != v->key_val && Qundef != v->key_val) {
29
+ rb_gc_mark(v->key_val);
30
+ }
31
+ if (NULL != v->odd_args) {
32
+ VALUE *a;
33
+ int i;
61
34
 
62
- for (i = v->odd_args->odd->attr_cnt, a = v->odd_args->args; 0 < i; i--, a++) {
63
- if (Qnil != *a) {
64
- rb_gc_mark(*a);
65
- }
66
- }
67
- }
35
+ for (i = v->odd_args->odd->attr_cnt, a = v->odd_args->args; 0 < i; i--, a++) {
36
+ if (Qnil != *a) {
37
+ rb_gc_mark(*a);
38
+ }
39
+ }
40
+ }
68
41
  }
69
42
  #ifdef HAVE_PTHREAD_MUTEX_INIT
70
43
  pthread_mutex_unlock(&stack->mutex);
@@ -76,43 +49,42 @@ mark(void *ptr) {
76
49
  VALUE
77
50
  oj_stack_init(ValStack stack) {
78
51
  #ifdef HAVE_PTHREAD_MUTEX_INIT
79
- int err;
52
+ int err;
80
53
 
81
54
  if (0 != (err = pthread_mutex_init(&stack->mutex, 0))) {
82
- rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
55
+ rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
83
56
  }
84
57
  #else
85
58
  stack->mutex = rb_mutex_new();
86
59
  #endif
87
- stack->head = stack->base;
88
- stack->end = stack->base + sizeof(stack->base) / sizeof(struct _val);
89
- stack->tail = stack->head;
90
- stack->head->val = Qundef;
91
- stack->head->key = NULL;
92
- stack->head->key_val = Qundef;
60
+ stack->head = stack->base;
61
+ stack->end = stack->base + sizeof(stack->base) / sizeof(struct _val);
62
+ stack->tail = stack->head;
63
+ stack->head->val = Qundef;
64
+ stack->head->key = NULL;
65
+ stack->head->key_val = Qundef;
93
66
  stack->head->classname = NULL;
94
- stack->head->odd_args = NULL;
95
- stack->head->clas = Qundef;
96
- stack->head->klen = 0;
97
- stack->head->clen = 0;
98
- stack->head->next = NEXT_NONE;
67
+ stack->head->odd_args = NULL;
68
+ stack->head->clas = Qundef;
69
+ stack->head->klen = 0;
70
+ stack->head->clen = 0;
71
+ stack->head->next = NEXT_NONE;
99
72
 
100
73
  return Data_Wrap_Struct(oj_cstack_class, mark, 0, stack);
101
74
  }
102
75
 
103
- const char*
104
- oj_stack_next_string(ValNext n) {
76
+ const char *oj_stack_next_string(ValNext n) {
105
77
  switch (n) {
106
- case NEXT_ARRAY_NEW: return "array element or close";
107
- case NEXT_ARRAY_ELEMENT: return "array element";
108
- case NEXT_ARRAY_COMMA: return "comma";
109
- case NEXT_HASH_NEW: return "hash pair or close";
110
- case NEXT_HASH_KEY: return "hash key";
111
- case NEXT_HASH_COLON: return "colon";
112
- case NEXT_HASH_VALUE: return "hash value";
113
- case NEXT_HASH_COMMA: return "comma";
114
- case NEXT_NONE: break;
115
- default: break;
78
+ case NEXT_ARRAY_NEW: return "array element or close";
79
+ case NEXT_ARRAY_ELEMENT: return "array element";
80
+ case NEXT_ARRAY_COMMA: return "comma";
81
+ case NEXT_HASH_NEW: return "hash pair or close";
82
+ case NEXT_HASH_KEY: return "hash key";
83
+ case NEXT_HASH_COLON: return "colon";
84
+ case NEXT_HASH_VALUE: return "hash value";
85
+ case NEXT_HASH_COMMA: return "comma";
86
+ case NEXT_NONE: break;
87
+ default: break;
116
88
  }
117
89
  return "nothing";
118
90
  }