oj 3.9.1 → 3.16.11

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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1452 -0
  3. data/README.md +21 -6
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +50 -68
  6. data/ext/oj/cache.c +329 -0
  7. data/ext/oj/cache.h +22 -0
  8. data/ext/oj/cache8.c +60 -62
  9. data/ext/oj/cache8.h +9 -36
  10. data/ext/oj/circarray.c +38 -42
  11. data/ext/oj/circarray.h +12 -13
  12. data/ext/oj/code.c +158 -179
  13. data/ext/oj/code.h +20 -22
  14. data/ext/oj/compat.c +145 -205
  15. data/ext/oj/custom.c +740 -880
  16. data/ext/oj/debug.c +126 -0
  17. data/ext/oj/dump.c +1145 -844
  18. data/ext/oj/dump.h +71 -57
  19. data/ext/oj/dump_compat.c +575 -655
  20. data/ext/oj/dump_leaf.c +96 -186
  21. data/ext/oj/dump_object.c +533 -660
  22. data/ext/oj/dump_strict.c +306 -340
  23. data/ext/oj/encode.h +4 -33
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +28 -28
  26. data/ext/oj/err.h +39 -42
  27. data/ext/oj/extconf.rb +28 -7
  28. data/ext/oj/fast.c +1052 -1113
  29. data/ext/oj/intern.c +313 -0
  30. data/ext/oj/intern.h +22 -0
  31. data/ext/oj/mem.c +318 -0
  32. data/ext/oj/mem.h +53 -0
  33. data/ext/oj/mimic_json.c +471 -430
  34. data/ext/oj/object.c +532 -580
  35. data/ext/oj/odd.c +156 -142
  36. data/ext/oj/odd.h +25 -26
  37. data/ext/oj/oj.c +1346 -961
  38. data/ext/oj/oj.h +307 -290
  39. data/ext/oj/parse.c +954 -858
  40. data/ext/oj/parse.h +74 -72
  41. data/ext/oj/parser.c +1600 -0
  42. data/ext/oj/parser.h +103 -0
  43. data/ext/oj/rails.c +819 -836
  44. data/ext/oj/rails.h +8 -11
  45. data/ext/oj/reader.c +136 -147
  46. data/ext/oj/reader.h +69 -83
  47. data/ext/oj/resolve.c +41 -63
  48. data/ext/oj/resolve.h +4 -6
  49. data/ext/oj/rxclass.c +69 -72
  50. data/ext/oj/rxclass.h +12 -13
  51. data/ext/oj/saj.c +440 -485
  52. data/ext/oj/saj2.c +584 -0
  53. data/ext/oj/saj2.h +23 -0
  54. data/ext/oj/scp.c +79 -118
  55. data/ext/oj/simd.h +10 -0
  56. data/ext/oj/sparse.c +739 -709
  57. data/ext/oj/stream_writer.c +141 -175
  58. data/ext/oj/strict.c +103 -128
  59. data/ext/oj/string_writer.c +244 -261
  60. data/ext/oj/trace.c +34 -41
  61. data/ext/oj/trace.h +42 -15
  62. data/ext/oj/usual.c +1218 -0
  63. data/ext/oj/usual.h +69 -0
  64. data/ext/oj/util.c +107 -107
  65. data/ext/oj/util.h +4 -3
  66. data/ext/oj/val_stack.c +61 -78
  67. data/ext/oj/val_stack.h +80 -114
  68. data/ext/oj/validate.c +46 -0
  69. data/ext/oj/wab.c +316 -361
  70. data/lib/oj/active_support_helper.rb +1 -3
  71. data/lib/oj/bag.rb +8 -1
  72. data/lib/oj/easy_hash.rb +9 -9
  73. data/lib/oj/error.rb +1 -2
  74. data/lib/oj/json.rb +162 -150
  75. data/lib/oj/mimic.rb +54 -20
  76. data/lib/oj/saj.rb +20 -6
  77. data/lib/oj/schandler.rb +5 -4
  78. data/lib/oj/state.rb +12 -8
  79. data/lib/oj/version.rb +1 -2
  80. data/lib/oj.rb +2 -8
  81. data/pages/Compatibility.md +1 -1
  82. data/pages/Encoding.md +1 -1
  83. data/pages/InstallOptions.md +20 -0
  84. data/pages/JsonGem.md +15 -0
  85. data/pages/Modes.md +9 -3
  86. data/pages/Options.md +62 -12
  87. data/pages/Parser.md +309 -0
  88. data/pages/Rails.md +73 -22
  89. metadata +68 -192
  90. data/ext/oj/hash.c +0 -163
  91. data/ext/oj/hash.h +0 -46
  92. data/ext/oj/hash_test.c +0 -512
  93. data/test/_test_active.rb +0 -76
  94. data/test/_test_active_mimic.rb +0 -96
  95. data/test/_test_mimic_rails.rb +0 -126
  96. data/test/activerecord/result_test.rb +0 -27
  97. data/test/activesupport4/decoding_test.rb +0 -108
  98. data/test/activesupport4/encoding_test.rb +0 -531
  99. data/test/activesupport4/test_helper.rb +0 -41
  100. data/test/activesupport5/decoding_test.rb +0 -125
  101. data/test/activesupport5/encoding_test.rb +0 -485
  102. data/test/activesupport5/encoding_test_cases.rb +0 -90
  103. data/test/activesupport5/test_helper.rb +0 -50
  104. data/test/activesupport5/time_zone_test_helpers.rb +0 -24
  105. data/test/bar.rb +0 -25
  106. data/test/files.rb +0 -29
  107. data/test/foo.rb +0 -21
  108. data/test/helper.rb +0 -26
  109. data/test/isolated/shared.rb +0 -308
  110. data/test/isolated/test_mimic_after.rb +0 -13
  111. data/test/isolated/test_mimic_alone.rb +0 -12
  112. data/test/isolated/test_mimic_as_json.rb +0 -45
  113. data/test/isolated/test_mimic_before.rb +0 -13
  114. data/test/isolated/test_mimic_define.rb +0 -28
  115. data/test/isolated/test_mimic_rails_after.rb +0 -22
  116. data/test/isolated/test_mimic_rails_before.rb +0 -21
  117. data/test/isolated/test_mimic_redefine.rb +0 -15
  118. data/test/json_gem/json_addition_test.rb +0 -216
  119. data/test/json_gem/json_common_interface_test.rb +0 -148
  120. data/test/json_gem/json_encoding_test.rb +0 -107
  121. data/test/json_gem/json_ext_parser_test.rb +0 -20
  122. data/test/json_gem/json_fixtures_test.rb +0 -35
  123. data/test/json_gem/json_generator_test.rb +0 -383
  124. data/test/json_gem/json_generic_object_test.rb +0 -90
  125. data/test/json_gem/json_parser_test.rb +0 -470
  126. data/test/json_gem/json_string_matching_test.rb +0 -42
  127. data/test/json_gem/test_helper.rb +0 -18
  128. data/test/perf.rb +0 -107
  129. data/test/perf_compat.rb +0 -130
  130. data/test/perf_fast.rb +0 -164
  131. data/test/perf_file.rb +0 -64
  132. data/test/perf_object.rb +0 -138
  133. data/test/perf_saj.rb +0 -109
  134. data/test/perf_scp.rb +0 -151
  135. data/test/perf_simple.rb +0 -287
  136. data/test/perf_strict.rb +0 -145
  137. data/test/perf_wab.rb +0 -131
  138. data/test/sample/change.rb +0 -14
  139. data/test/sample/dir.rb +0 -19
  140. data/test/sample/doc.rb +0 -36
  141. data/test/sample/file.rb +0 -48
  142. data/test/sample/group.rb +0 -16
  143. data/test/sample/hasprops.rb +0 -16
  144. data/test/sample/layer.rb +0 -12
  145. data/test/sample/line.rb +0 -20
  146. data/test/sample/oval.rb +0 -10
  147. data/test/sample/rect.rb +0 -10
  148. data/test/sample/shape.rb +0 -35
  149. data/test/sample/text.rb +0 -20
  150. data/test/sample.rb +0 -54
  151. data/test/sample_json.rb +0 -37
  152. data/test/test_compat.rb +0 -509
  153. data/test/test_custom.rb +0 -503
  154. data/test/test_debian.rb +0 -53
  155. data/test/test_fast.rb +0 -470
  156. data/test/test_file.rb +0 -239
  157. data/test/test_gc.rb +0 -49
  158. data/test/test_hash.rb +0 -29
  159. data/test/test_integer_range.rb +0 -73
  160. data/test/test_null.rb +0 -376
  161. data/test/test_object.rb +0 -1018
  162. data/test/test_saj.rb +0 -186
  163. data/test/test_scp.rb +0 -433
  164. data/test/test_strict.rb +0 -410
  165. data/test/test_various.rb +0 -741
  166. data/test/test_wab.rb +0 -307
  167. data/test/test_writer.rb +0 -380
  168. data/test/tests.rb +0 -24
  169. data/test/tests_mimic.rb +0 -14
  170. data/test/tests_mimic_addition.rb +0 -7
  171. data/test/zoo.rb +0 -13
data/ext/oj/odd.c CHANGED
@@ -1,81 +1,109 @@
1
- /* odd.c
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- */
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 "odd.h"
5
5
 
6
6
  #include <string.h>
7
7
 
8
- #include "odd.h"
8
+ #include "mem.h"
9
+
10
+ static Odd odds = NULL;
11
+ static ID sec_id;
12
+ static ID sec_fraction_id;
13
+ static ID to_f_id;
14
+ static ID numerator_id;
15
+ static ID denominator_id;
16
+ static ID rational_id;
9
17
 
10
- static struct _odd _odds[4]; // bump up if new initial Odd classes are added
11
- static struct _odd *odds = _odds;
12
- static long odd_cnt = 0;
13
- static ID sec_id;
14
- static ID sec_fraction_id;
15
- static ID to_f_id;
16
- static ID numerator_id;
17
- static ID denominator_id;
18
- static ID rational_id;
19
- static VALUE rational_class;
20
-
21
- static void
22
- set_class(Odd odd, const char *classname) {
23
- const char **np;
24
- ID *idp;
18
+ static void set_class(Odd odd, const char *classname) {
19
+ const char **np;
20
+ ID *idp;
25
21
 
26
22
  odd->classname = classname;
27
- odd->clen = strlen(classname);
28
- odd->clas = rb_const_get(rb_cObject, rb_intern(classname));
23
+ odd->clen = strlen(classname);
24
+ odd->clas = rb_const_get(rb_cObject, rb_intern(classname));
25
+ rb_gc_register_mark_object(odd->clas);
29
26
  odd->create_obj = odd->clas;
27
+ rb_gc_register_mark_object(odd->create_obj);
30
28
  odd->create_op = rb_intern("new");
31
29
  odd->is_module = (T_MODULE == rb_type(odd->clas));
32
- odd->raw = 0;
30
+ odd->raw = 0;
33
31
  for (np = odd->attr_names, idp = odd->attrs; 0 != *np; np++, idp++) {
34
- *idp = rb_intern(*np);
32
+ *idp = rb_intern(*np);
35
33
  }
36
34
  *idp = 0;
37
35
  }
38
36
 
39
- static VALUE
40
- get_datetime_secs(VALUE obj) {
41
- volatile VALUE rsecs = rb_funcall(obj, sec_id, 0);
42
- volatile VALUE rfrac = rb_funcall(obj, sec_fraction_id, 0);
43
- long sec = NUM2LONG(rsecs);
44
- long long num = rb_num2ll(rb_funcall(rfrac, numerator_id, 0));
45
- long long den = rb_num2ll(rb_funcall(rfrac, denominator_id, 0));
37
+ static VALUE get_datetime_secs(VALUE obj) {
38
+ volatile VALUE rsecs = rb_funcall(obj, sec_id, 0);
39
+ volatile VALUE rfrac = rb_funcall(obj, sec_fraction_id, 0);
40
+ long sec = NUM2LONG(rsecs);
41
+ long long num = NUM2LL(rb_funcall(rfrac, numerator_id, 0));
42
+ long long den = NUM2LL(rb_funcall(rfrac, denominator_id, 0));
46
43
 
47
44
  num += sec * den;
48
45
 
49
46
  return rb_funcall(rb_cObject, rational_id, 2, rb_ll2inum(num), rb_ll2inum(den));
50
47
  }
51
48
 
52
- void
53
- oj_odd_init() {
54
- Odd odd;
55
- const char **np;
49
+ static void print_odd(Odd odd) {
50
+ const char **np;
51
+ int i;
52
+
53
+ printf(" %s {\n", odd->classname);
54
+ printf(" attr_cnt: %d %p\n", odd->attr_cnt, (void *)odd->attr_names);
55
+ printf(" attr_names: %p\n", (void *)*odd->attr_names);
56
+ printf(" attr_names: %c\n", **odd->attr_names);
57
+ for (i = odd->attr_cnt, np = odd->attr_names; 0 < i; i--, np++) {
58
+ printf(" %d %s\n", i, *np);
59
+ }
60
+ printf(" }\n");
61
+ }
56
62
 
57
- sec_id = rb_intern("sec");
63
+ void print_all_odds(const char *label) {
64
+ Odd odd;
65
+ printf("@ %s {\n", label);
66
+ for (odd = odds; NULL != odd; odd = odd->next) {
67
+ print_odd(odd);
68
+ }
69
+ printf("}\n");
70
+ }
71
+
72
+ static Odd odd_create(void) {
73
+ Odd odd = OJ_R_ALLOC(struct _odd);
74
+
75
+ memset(odd, 0, sizeof(struct _odd));
76
+ odd->next = odds;
77
+ odds = odd;
78
+
79
+ return odd;
80
+ }
81
+
82
+ void oj_odd_init(void) {
83
+ Odd odd;
84
+ const char **np;
85
+
86
+ sec_id = rb_intern("sec");
58
87
  sec_fraction_id = rb_intern("sec_fraction");
59
- to_f_id = rb_intern("to_f");
60
- numerator_id = rb_intern("numerator");
61
- denominator_id = rb_intern("denominator");
62
- rational_id = rb_intern("Rational");
63
- rational_class = rb_const_get(rb_cObject, rational_id);
64
-
65
- memset(_odds, 0, sizeof(_odds));
66
- odd = odds;
88
+ to_f_id = rb_intern("to_f");
89
+ numerator_id = rb_intern("numerator");
90
+ denominator_id = rb_intern("denominator");
91
+ rational_id = rb_intern("Rational");
92
+
67
93
  // Rational
68
- np = odd->attr_names;
94
+ odd = odd_create();
95
+ np = odd->attr_names;
69
96
  *np++ = "numerator";
70
97
  *np++ = "denominator";
71
- *np = 0;
98
+ *np = 0;
72
99
  set_class(odd, "Rational");
73
100
  odd->create_obj = rb_cObject;
74
- odd->create_op = rational_id;
75
- odd->attr_cnt = 2;
101
+ odd->create_op = rational_id;
102
+ odd->attr_cnt = 2;
103
+
76
104
  // Date
77
- odd++;
78
- np = odd->attr_names;
105
+ odd = odd_create();
106
+ np = odd->attr_names;
79
107
  *np++ = "year";
80
108
  *np++ = "month";
81
109
  *np++ = "day";
@@ -83,9 +111,10 @@ oj_odd_init() {
83
111
  *np++ = 0;
84
112
  set_class(odd, "Date");
85
113
  odd->attr_cnt = 4;
114
+
86
115
  // DateTime
87
- odd++;
88
- np = odd->attr_names;
116
+ odd = odd_create();
117
+ np = odd->attr_names;
89
118
  *np++ = "year";
90
119
  *np++ = "month";
91
120
  *np++ = "day";
@@ -96,136 +125,121 @@ oj_odd_init() {
96
125
  *np++ = "start";
97
126
  *np++ = 0;
98
127
  set_class(odd, "DateTime");
99
- odd->attr_cnt = 8;
128
+ odd->attr_cnt = 8;
100
129
  odd->attrFuncs[5] = get_datetime_secs;
130
+
101
131
  // Range
102
- odd++;
103
- np = odd->attr_names;
132
+ odd = odd_create();
133
+ np = odd->attr_names;
104
134
  *np++ = "begin";
105
135
  *np++ = "end";
106
136
  *np++ = "exclude_end?";
107
137
  *np++ = 0;
108
138
  set_class(odd, "Range");
109
139
  odd->attr_cnt = 3;
110
-
111
- odd_cnt = odd - odds + 1;
112
140
  }
113
141
 
114
- Odd
115
- oj_get_odd(VALUE clas) {
116
- Odd odd;
117
- const char *classname = NULL;
118
-
119
- for (odd = odds + odd_cnt - 1; odds <= odd; odd--) {
120
- if (clas == odd->clas) {
121
- return odd;
122
- }
123
- if (odd->is_module) {
124
- if (NULL == classname) {
125
- classname = rb_class2name(clas);
126
- }
127
- if (0 == strncmp(odd->classname, classname, odd->clen) &&
128
- ':' == classname[odd->clen]) {
129
- return odd;
130
- }
131
- }
142
+ Odd oj_get_odd(VALUE clas) {
143
+ Odd odd;
144
+ const char *classname = NULL;
145
+
146
+ for (odd = odds; NULL != odd; odd = odd->next) {
147
+ if (clas == odd->clas) {
148
+ return odd;
149
+ }
150
+ if (odd->is_module) {
151
+ if (NULL == classname) {
152
+ classname = rb_class2name(clas);
153
+ }
154
+ if (0 == strncmp(odd->classname, classname, odd->clen) && ':' == classname[odd->clen]) {
155
+ return odd;
156
+ }
157
+ }
132
158
  }
133
159
  return NULL;
134
160
  }
135
161
 
136
- Odd
137
- oj_get_oddc(const char *classname, size_t len) {
138
- Odd odd;
139
-
140
- for (odd = odds + odd_cnt - 1; odds <= odd; odd--) {
141
- if (len == odd->clen && 0 == strncmp(classname, odd->classname, len)) {
142
- return odd;
143
- }
144
- if (odd->is_module &&
145
- 0 == strncmp(odd->classname, classname, odd->clen) &&
146
- ':' == classname[odd->clen]) {
147
- return odd;
148
- }
162
+ Odd oj_get_oddc(const char *classname, size_t len) {
163
+ Odd odd;
164
+
165
+ for (odd = odds; NULL != odd; odd = odd->next) {
166
+ if (len == odd->clen && 0 == strncmp(classname, odd->classname, len)) {
167
+ return odd;
168
+ }
169
+ if (odd->is_module && 0 == strncmp(odd->classname, classname, odd->clen) && ':' == classname[odd->clen]) {
170
+ return odd;
171
+ }
149
172
  }
150
- return 0;
173
+ return NULL;
151
174
  }
152
175
 
153
- OddArgs
154
- oj_odd_alloc_args(Odd odd) {
155
- OddArgs oa = ALLOC_N(struct _oddArgs, 1);
156
- VALUE *a;
157
- int i;
176
+ OddArgs oj_odd_alloc_args(Odd odd) {
177
+ OddArgs oa = OJ_R_ALLOC_N(struct _oddArgs, 1);
178
+ VALUE *a;
179
+ int i;
158
180
 
159
181
  oa->odd = odd;
160
182
  for (i = odd->attr_cnt, a = oa->args; 0 < i; i--, a++) {
161
- *a = Qnil;
183
+ *a = Qnil;
162
184
  }
163
185
  return oa;
164
186
  }
165
187
 
166
- void
167
- oj_odd_free(OddArgs args) {
168
- xfree(args);
188
+ void oj_odd_free(OddArgs args) {
189
+ OJ_R_FREE(args);
169
190
  }
170
191
 
171
- int
172
- oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value) {
173
- const char **np;
174
- VALUE *vp;
175
- int i;
192
+ int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value) {
193
+ const char **np;
194
+ VALUE *vp;
195
+ int i;
176
196
 
177
197
  for (i = args->odd->attr_cnt, np = args->odd->attr_names, vp = args->args; 0 < i; i--, np++, vp++) {
178
- if (0 == strncmp(key, *np, klen) && '\0' == *((*np) + klen)) {
179
- *vp = value;
180
- return 0;
181
- }
198
+ if (0 == strncmp(key, *np, klen) && '\0' == *((*np) + klen)) {
199
+ *vp = value;
200
+ return 0;
201
+ }
182
202
  }
183
203
  return -1;
184
204
  }
185
205
 
186
- void
187
- oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw) {
188
- Odd odd;
189
- const char **np;
190
- ID *ap;
191
- AttrGetFunc *fp;
192
-
193
- if (_odds == odds) {
194
- odds = ALLOC_N(struct _odd, odd_cnt + 1);
206
+ void oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw) {
207
+ Odd odd;
208
+ const char **np;
209
+ ID *ap;
210
+ AttrGetFunc *fp;
195
211
 
196
- memcpy(odds, _odds, sizeof(struct _odd) * odd_cnt);
197
- } else {
198
- REALLOC_N(odds, struct _odd, odd_cnt + 1);
199
- }
200
- odd = odds + odd_cnt;
212
+ odd = odd_create();
201
213
  odd->clas = clas;
202
- if (NULL == (odd->classname = strdup(rb_class2name(clas)))) {
203
- rb_raise(rb_eNoMemError, "for attribute name.");
214
+ rb_gc_register_mark_object(odd->clas);
215
+ if (NULL == (odd->classname = OJ_STRDUP(rb_class2name(clas)))) {
216
+ rb_raise(rb_eNoMemError, "for class name.");
204
217
  }
205
- odd->clen = strlen(odd->classname);
218
+ odd->clen = strlen(odd->classname);
206
219
  odd->create_obj = create_object;
220
+ rb_gc_register_mark_object(odd->create_obj);
207
221
  odd->create_op = SYM2ID(create_method);
208
- odd->attr_cnt = mcnt;
222
+ odd->attr_cnt = mcnt;
209
223
  odd->is_module = (T_MODULE == rb_type(clas));
210
- odd->raw = raw;
224
+ odd->raw = raw;
211
225
  for (ap = odd->attrs, np = odd->attr_names, fp = odd->attrFuncs; 0 < mcnt; mcnt--, ap++, np++, members++, fp++) {
212
- *fp = 0;
213
- switch (rb_type(*members)) {
214
- case T_STRING:
215
- if (NULL == (*np = strdup(rb_string_value_ptr(members)))) {
216
- rb_raise(rb_eNoMemError, "for attribute name.");
217
- }
218
- break;
219
- case T_SYMBOL:
220
- *np = rb_id2name(SYM2ID(*members));
221
- break;
222
- default:
223
- rb_raise(rb_eArgError, "registered member identifiers must be Strings or Symbols.");
224
- break;
225
- }
226
- *ap = rb_intern(*np);
226
+ *fp = 0;
227
+ switch (rb_type(*members)) {
228
+ case T_STRING:
229
+ if (NULL == (*np = OJ_STRDUP(RSTRING_PTR(*members)))) {
230
+ rb_raise(rb_eNoMemError, "for attribute name.");
231
+ }
232
+ break;
233
+ case T_SYMBOL:
234
+ // The symbol can move and invalidate the name so make a copy.
235
+ if (NULL == (*np = OJ_STRDUP(rb_id2name(SYM2ID(*members))))) {
236
+ rb_raise(rb_eNoMemError, "for attribute name.");
237
+ }
238
+ break;
239
+ default: rb_raise(rb_eArgError, "registered member identifiers must be Strings or Symbols."); break;
240
+ }
241
+ *ap = rb_intern(*np);
227
242
  }
228
243
  *np = 0;
229
244
  *ap = 0;
230
- odd_cnt++;
231
245
  }
data/ext/oj/odd.h CHANGED
@@ -1,7 +1,5 @@
1
- /* odd.h
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- */
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.
5
3
 
6
4
  #ifndef OJ_ODD_H
7
5
  #define OJ_ODD_H
@@ -10,35 +8,36 @@
10
8
 
11
9
  #include "ruby.h"
12
10
 
13
- #define MAX_ODD_ARGS 10
11
+ #define MAX_ODD_ARGS 10
14
12
 
15
- typedef VALUE (*AttrGetFunc)(VALUE obj);
13
+ typedef VALUE (*AttrGetFunc)(VALUE obj);
16
14
 
17
15
  typedef struct _odd {
18
- const char *classname;
19
- size_t clen;
20
- VALUE clas; // Ruby class or module
21
- VALUE create_obj;
22
- ID create_op;
23
- int attr_cnt;
24
- bool is_module;
25
- bool raw;
26
- const char *attr_names[MAX_ODD_ARGS]; // NULL terminated attr names
27
- ID attrs[MAX_ODD_ARGS]; // 0 terminated attr IDs
28
- AttrGetFunc attrFuncs[MAX_ODD_ARGS];
16
+ struct _odd *next;
17
+ const char *classname;
18
+ size_t clen;
19
+ VALUE clas; // Ruby class or module
20
+ VALUE create_obj;
21
+ ID create_op;
22
+ int attr_cnt;
23
+ bool is_module;
24
+ bool raw;
25
+ const char *attr_names[MAX_ODD_ARGS]; // NULL terminated attr names
26
+ ID attrs[MAX_ODD_ARGS]; // 0 terminated attr IDs
27
+ AttrGetFunc attrFuncs[MAX_ODD_ARGS];
29
28
  } *Odd;
30
29
 
31
30
  typedef struct _oddArgs {
32
- Odd odd;
33
- VALUE args[MAX_ODD_ARGS];
31
+ Odd odd;
32
+ VALUE args[MAX_ODD_ARGS];
34
33
  } *OddArgs;
35
34
 
36
- extern void oj_odd_init(void);
37
- extern Odd oj_get_odd(VALUE clas);
38
- extern Odd oj_get_oddc(const char *classname, size_t len);
39
- extern OddArgs oj_odd_alloc_args(Odd odd);
40
- extern void oj_odd_free(OddArgs args);
41
- extern int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value);
42
- extern void oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw);
35
+ extern void oj_odd_init(void);
36
+ extern Odd oj_get_odd(VALUE clas);
37
+ extern Odd oj_get_oddc(const char *classname, size_t len);
38
+ extern OddArgs oj_odd_alloc_args(Odd odd);
39
+ extern void oj_odd_free(OddArgs args);
40
+ extern int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value);
41
+ extern void oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw);
43
42
 
44
43
  #endif /* OJ_ODD_H */