oj 2.18.5 → 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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1452 -0
- data/README.md +53 -221
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +54 -72
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +61 -63
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +38 -67
- data/ext/oj/circarray.h +16 -42
- data/ext/oj/code.c +214 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +194 -110
- data/ext/oj/custom.c +1074 -0
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +1276 -2494
- data/ext/oj/dump.h +110 -0
- data/ext/oj/dump_compat.c +897 -0
- data/ext/oj/dump_leaf.c +162 -0
- data/ext/oj/dump_object.c +710 -0
- data/ext/oj/dump_strict.c +399 -0
- data/ext/oj/encode.h +7 -42
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +28 -53
- data/ext/oj/err.h +49 -46
- data/ext/oj/extconf.rb +33 -32
- data/ext/oj/fast.c +1082 -1098
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +919 -0
- data/ext/oj/object.c +545 -625
- data/ext/oj/odd.c +158 -168
- data/ext/oj/odd.h +32 -58
- data/ext/oj/oj.c +1727 -2080
- data/ext/oj/oj.h +334 -259
- data/ext/oj/parse.c +974 -753
- data/ext/oj/parse.h +97 -90
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +103 -0
- data/ext/oj/rails.c +1478 -0
- data/ext/oj/rails.h +18 -0
- data/ext/oj/reader.c +136 -163
- data/ext/oj/reader.h +76 -112
- data/ext/oj/resolve.c +45 -94
- data/ext/oj/resolve.h +7 -34
- data/ext/oj/rxclass.c +144 -0
- data/ext/oj/rxclass.h +26 -0
- data/ext/oj/saj.c +445 -511
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +82 -143
- data/ext/oj/simd.h +10 -0
- data/ext/oj/sparse.c +749 -644
- data/ext/oj/stream_writer.c +329 -0
- data/ext/oj/strict.c +114 -112
- data/ext/oj/string_writer.c +517 -0
- data/ext/oj/trace.c +72 -0
- data/ext/oj/trace.h +55 -0
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +75 -72
- data/ext/oj/val_stack.h +94 -127
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +586 -0
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +8 -1
- data/lib/oj/easy_hash.rb +21 -13
- data/lib/oj/error.rb +10 -12
- data/lib/oj/json.rb +188 -0
- data/lib/oj/mimic.rb +165 -26
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +135 -0
- data/lib/oj/version.rb +2 -3
- data/lib/oj.rb +3 -31
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +94 -0
- data/pages/Modes.md +161 -0
- data/pages/Options.md +337 -0
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +167 -0
- data/pages/Security.md +20 -0
- data/pages/WAB.md +13 -0
- metadata +126 -163
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activesupport_datetime_test.rb +0 -23
- data/test/bug.rb +0 -51
- data/test/bug2.rb +0 -10
- data/test/bug3.rb +0 -46
- data/test/bug_fast.rb +0 -32
- data/test/bug_load.rb +0 -24
- data/test/crash.rb +0 -111
- data/test/curl/curl_oj.rb +0 -46
- data/test/curl/get_oj.rb +0 -24
- data/test/curl/just_curl.rb +0 -31
- data/test/curl/just_oj.rb +0 -51
- data/test/example.rb +0 -11
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -24
- data/test/helper.rb +0 -27
- data/test/io.rb +0 -48
- data/test/isolated/shared.rb +0 -310
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/mod.rb +0 -16
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -128
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -151
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -128
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -55
- data/test/sample_json.rb +0 -37
- data/test/struct.rb +0 -29
- data/test/test_compat.rb +0 -398
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -458
- data/test/test_file.rb +0 -245
- data/test/test_gc.rb +0 -49
- data/test/test_hash.rb +0 -29
- data/test/test_object.rb +0 -745
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -396
- data/test/test_serializer.rb +0 -59
- data/test/test_strict.rb +0 -254
- data/test/test_various.rb +0 -1383
- data/test/test_writer.rb +0 -308
- data/test/write_timebars.rb +0 -31
data/ext/oj/odd.c
CHANGED
@@ -1,109 +1,109 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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 "odd.h"
|
30
5
|
|
31
6
|
#include <string.h>
|
32
7
|
|
33
|
-
#include "
|
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;
|
34
17
|
|
35
|
-
static
|
36
|
-
|
37
|
-
|
38
|
-
static ID sec_id;
|
39
|
-
static ID sec_fraction_id;
|
40
|
-
static ID to_f_id;
|
41
|
-
static ID numerator_id;
|
42
|
-
static ID denominator_id;
|
43
|
-
static ID rational_id;
|
44
|
-
static VALUE rational_class;
|
45
|
-
|
46
|
-
static void
|
47
|
-
set_class(Odd odd, const char *classname) {
|
48
|
-
const char **np;
|
49
|
-
ID *idp;
|
18
|
+
static void set_class(Odd odd, const char *classname) {
|
19
|
+
const char **np;
|
20
|
+
ID *idp;
|
50
21
|
|
51
22
|
odd->classname = classname;
|
52
|
-
odd->clen
|
53
|
-
odd->clas
|
23
|
+
odd->clen = strlen(classname);
|
24
|
+
odd->clas = rb_const_get(rb_cObject, rb_intern(classname));
|
25
|
+
rb_gc_register_mark_object(odd->clas);
|
54
26
|
odd->create_obj = odd->clas;
|
27
|
+
rb_gc_register_mark_object(odd->create_obj);
|
55
28
|
odd->create_op = rb_intern("new");
|
56
29
|
odd->is_module = (T_MODULE == rb_type(odd->clas));
|
57
|
-
odd->raw
|
30
|
+
odd->raw = 0;
|
58
31
|
for (np = odd->attr_names, idp = odd->attrs; 0 != *np; np++, idp++) {
|
59
|
-
|
32
|
+
*idp = rb_intern(*np);
|
60
33
|
}
|
61
34
|
*idp = 0;
|
62
35
|
}
|
63
36
|
|
64
|
-
static VALUE
|
65
|
-
|
66
|
-
VALUE
|
67
|
-
|
68
|
-
long
|
69
|
-
long long
|
70
|
-
|
71
|
-
|
72
|
-
#if DATETIME_1_8
|
73
|
-
num *= 86400;
|
74
|
-
#endif
|
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));
|
43
|
+
|
75
44
|
num += sec * den;
|
76
45
|
|
77
46
|
return rb_funcall(rb_cObject, rational_id, 2, rb_ll2inum(num), rb_ll2inum(den));
|
78
47
|
}
|
79
48
|
|
80
|
-
void
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
+
}
|
62
|
+
|
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
|
+
}
|
84
71
|
|
85
|
-
|
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");
|
86
87
|
sec_fraction_id = rb_intern("sec_fraction");
|
87
|
-
to_f_id
|
88
|
-
numerator_id
|
89
|
-
denominator_id
|
90
|
-
rational_id
|
91
|
-
|
92
|
-
|
93
|
-
memset(_odds, 0, sizeof(_odds));
|
94
|
-
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
|
+
|
95
93
|
// Rational
|
96
|
-
|
94
|
+
odd = odd_create();
|
95
|
+
np = odd->attr_names;
|
97
96
|
*np++ = "numerator";
|
98
97
|
*np++ = "denominator";
|
99
|
-
*np
|
98
|
+
*np = 0;
|
100
99
|
set_class(odd, "Rational");
|
101
100
|
odd->create_obj = rb_cObject;
|
102
|
-
odd->create_op
|
103
|
-
odd->attr_cnt
|
101
|
+
odd->create_op = rational_id;
|
102
|
+
odd->attr_cnt = 2;
|
103
|
+
|
104
104
|
// Date
|
105
|
-
odd
|
106
|
-
np
|
105
|
+
odd = odd_create();
|
106
|
+
np = odd->attr_names;
|
107
107
|
*np++ = "year";
|
108
108
|
*np++ = "month";
|
109
109
|
*np++ = "day";
|
@@ -111,9 +111,10 @@ oj_odd_init() {
|
|
111
111
|
*np++ = 0;
|
112
112
|
set_class(odd, "Date");
|
113
113
|
odd->attr_cnt = 4;
|
114
|
+
|
114
115
|
// DateTime
|
115
|
-
odd
|
116
|
-
np
|
116
|
+
odd = odd_create();
|
117
|
+
np = odd->attr_names;
|
117
118
|
*np++ = "year";
|
118
119
|
*np++ = "month";
|
119
120
|
*np++ = "day";
|
@@ -124,132 +125,121 @@ oj_odd_init() {
|
|
124
125
|
*np++ = "start";
|
125
126
|
*np++ = 0;
|
126
127
|
set_class(odd, "DateTime");
|
127
|
-
odd->attr_cnt
|
128
|
+
odd->attr_cnt = 8;
|
128
129
|
odd->attrFuncs[5] = get_datetime_secs;
|
130
|
+
|
129
131
|
// Range
|
130
|
-
odd
|
131
|
-
np
|
132
|
+
odd = odd_create();
|
133
|
+
np = odd->attr_names;
|
132
134
|
*np++ = "begin";
|
133
135
|
*np++ = "end";
|
134
136
|
*np++ = "exclude_end?";
|
135
137
|
*np++ = 0;
|
136
138
|
set_class(odd, "Range");
|
137
139
|
odd->attr_cnt = 3;
|
138
|
-
|
139
|
-
odd_cnt = odd - odds + 1;
|
140
140
|
}
|
141
141
|
|
142
|
-
Odd
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
}
|
159
|
-
}
|
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
|
+
}
|
160
158
|
}
|
161
159
|
return NULL;
|
162
160
|
}
|
163
161
|
|
164
|
-
Odd
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
':' == classname[odd->clen]) {
|
175
|
-
return odd;
|
176
|
-
}
|
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
|
+
}
|
177
172
|
}
|
178
|
-
return
|
173
|
+
return NULL;
|
179
174
|
}
|
180
175
|
|
181
|
-
OddArgs
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
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;
|
186
180
|
|
187
181
|
oa->odd = odd;
|
188
182
|
for (i = odd->attr_cnt, a = oa->args; 0 < i; i--, a++) {
|
189
|
-
|
183
|
+
*a = Qnil;
|
190
184
|
}
|
191
185
|
return oa;
|
192
186
|
}
|
193
187
|
|
194
|
-
void
|
195
|
-
|
196
|
-
xfree(args);
|
188
|
+
void oj_odd_free(OddArgs args) {
|
189
|
+
OJ_R_FREE(args);
|
197
190
|
}
|
198
191
|
|
199
|
-
int
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
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;
|
204
196
|
|
205
197
|
for (i = args->odd->attr_cnt, np = args->odd->attr_names, vp = args->args; 0 < i; i--, np++, vp++) {
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
198
|
+
if (0 == strncmp(key, *np, klen) && '\0' == *((*np) + klen)) {
|
199
|
+
*vp = value;
|
200
|
+
return 0;
|
201
|
+
}
|
210
202
|
}
|
211
203
|
return -1;
|
212
204
|
}
|
213
205
|
|
214
|
-
void
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
AttrGetFunc *fp;
|
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;
|
220
211
|
|
221
|
-
|
222
|
-
odds = ALLOC_N(struct _Odd, odd_cnt + 1);
|
223
|
-
|
224
|
-
memcpy(odds, _odds, sizeof(struct _Odd) * odd_cnt);
|
225
|
-
} else {
|
226
|
-
REALLOC_N(odds, struct _Odd, odd_cnt + 1);
|
227
|
-
}
|
228
|
-
odd = odds + odd_cnt;
|
212
|
+
odd = odd_create();
|
229
213
|
odd->clas = clas;
|
230
|
-
odd->
|
231
|
-
odd->
|
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.");
|
217
|
+
}
|
218
|
+
odd->clen = strlen(odd->classname);
|
232
219
|
odd->create_obj = create_object;
|
220
|
+
rb_gc_register_mark_object(odd->create_obj);
|
233
221
|
odd->create_op = SYM2ID(create_method);
|
234
|
-
odd->attr_cnt
|
222
|
+
odd->attr_cnt = mcnt;
|
235
223
|
odd->is_module = (T_MODULE == rb_type(clas));
|
236
|
-
odd->raw
|
224
|
+
odd->raw = raw;
|
237
225
|
for (ap = odd->attrs, np = odd->attr_names, fp = odd->attrFuncs; 0 < mcnt; mcnt--, ap++, np++, members++, fp++) {
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
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);
|
251
242
|
}
|
252
243
|
*np = 0;
|
253
244
|
*ap = 0;
|
254
|
-
odd_cnt++;
|
255
245
|
}
|
data/ext/oj/odd.h
CHANGED
@@ -1,69 +1,43 @@
|
|
1
|
-
|
2
|
-
|
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.
|
30
3
|
|
31
|
-
#ifndef
|
32
|
-
#define
|
4
|
+
#ifndef OJ_ODD_H
|
5
|
+
#define OJ_ODD_H
|
33
6
|
|
34
7
|
#include <stdbool.h>
|
35
8
|
|
36
9
|
#include "ruby.h"
|
37
10
|
|
38
|
-
#define MAX_ODD_ARGS
|
39
|
-
|
40
|
-
typedef VALUE
|
41
|
-
|
42
|
-
typedef struct
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
VALUE
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
bool
|
51
|
-
|
52
|
-
|
53
|
-
|
11
|
+
#define MAX_ODD_ARGS 10
|
12
|
+
|
13
|
+
typedef VALUE (*AttrGetFunc)(VALUE obj);
|
14
|
+
|
15
|
+
typedef struct _odd {
|
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];
|
54
28
|
} *Odd;
|
55
29
|
|
56
|
-
typedef struct
|
57
|
-
Odd
|
58
|
-
VALUE
|
30
|
+
typedef struct _oddArgs {
|
31
|
+
Odd odd;
|
32
|
+
VALUE args[MAX_ODD_ARGS];
|
59
33
|
} *OddArgs;
|
60
34
|
|
61
|
-
extern void
|
62
|
-
extern Odd
|
63
|
-
extern Odd
|
64
|
-
extern OddArgs
|
65
|
-
extern void
|
66
|
-
extern int
|
67
|
-
extern void
|
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);
|
68
42
|
|
69
|
-
#endif /*
|
43
|
+
#endif /* OJ_ODD_H */
|