oj-introspect 0.5.0 → 0.7.0
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +5 -5
- data/ext/oj-introspect/introspect.c +46 -32
- data/lib/oj/introspect/version.rb +1 -1
- data/oj-introspect.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8344e4ea03bb224e5911727d82641178d51384929ec66d40518b44b9d06cf1a
|
4
|
+
data.tar.gz: 6cd47873367c3d0305b40022ca35e46f22060df2fa3d5997927161150cf6996c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6c63c1724ed3b9295eef1b7858f78ff926042a3bef6d558648822a7a144dd2426ad2e884f8173f576a23c484c2e50c2170c90d905aefe4efa0a4c56b6eccc58
|
7
|
+
data.tar.gz: 50992a4c4cc58fe8589afc32669ea6bbb34a699078112e853299b707389f4883ee9e82f1fc0370ee87f61fb9847edb111e2d0540205378b88f9fc05ec008672f
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
oj-introspect (0.
|
5
|
-
oj (>= 3.13.
|
4
|
+
oj-introspect (0.7.0)
|
5
|
+
oj (>= 3.13.23)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -11,11 +11,11 @@ GEM
|
|
11
11
|
coderay (1.1.3)
|
12
12
|
diff-lcs (1.5.0)
|
13
13
|
method_source (1.0.0)
|
14
|
-
oj (3.13.
|
14
|
+
oj (3.13.23)
|
15
15
|
pry (0.14.1)
|
16
16
|
coderay (~> 1.1)
|
17
17
|
method_source (~> 1.0)
|
18
|
-
rake (
|
18
|
+
rake (13.0.6)
|
19
19
|
rake-compiler (1.2.0)
|
20
20
|
rake
|
21
21
|
rspec (3.12.0)
|
@@ -39,7 +39,7 @@ DEPENDENCIES
|
|
39
39
|
benchmark-ips
|
40
40
|
oj-introspect!
|
41
41
|
pry
|
42
|
-
rake (~>
|
42
|
+
rake (~> 13.0)
|
43
43
|
rake-compiler
|
44
44
|
rspec (~> 3.0)
|
45
45
|
|
@@ -26,8 +26,14 @@ typedef struct _introspect_S {
|
|
26
26
|
void (*delegated_open_object_key_func)(struct _ojParser *p);
|
27
27
|
void (*delegated_open_array_key_func)(struct _ojParser *p);
|
28
28
|
void (*delegated_close_object_func)(struct _ojParser *p);
|
29
|
+
void (*delegated_close_object_key_func)(struct _ojParser *p);
|
30
|
+
void (*delegated_close_array_key_func)(struct _ojParser *p);
|
29
31
|
} * IntrospectDelegate;
|
30
32
|
|
33
|
+
static VALUE introspection_key;
|
34
|
+
static VALUE start_byte_key;
|
35
|
+
static VALUE end_byte_key;
|
36
|
+
|
31
37
|
static void dfree(ojParser p) {
|
32
38
|
IntrospectDelegate d = (IntrospectDelegate)p->ctx;
|
33
39
|
|
@@ -51,16 +57,18 @@ static void start(ojParser p) {
|
|
51
57
|
}
|
52
58
|
|
53
59
|
static void copy_ruby_str(char **target, VALUE source) {
|
54
|
-
|
60
|
+
const char *ruby_str = StringValueCStr(source);
|
61
|
+
size_t len = strlen(ruby_str);
|
62
|
+
|
55
63
|
*target = ALLOC_N(char, len + 1);
|
56
|
-
|
57
|
-
(*target)[len] = '\0'; // Parantheses are important as it means => (*target + sizeof(char) * len)
|
64
|
+
strncpy(*target, ruby_str, len + 1);
|
58
65
|
}
|
59
66
|
|
60
67
|
static VALUE option(ojParser p, const char *key, VALUE value) {
|
61
68
|
IntrospectDelegate d = (IntrospectDelegate)p->ctx;
|
62
69
|
|
63
70
|
if(strcmp(key, "filter=") == 0) {
|
71
|
+
Check_Type(value, T_STRING);
|
64
72
|
copy_ruby_str(&d->filter, value); // We need to copy the value as GC can free it later.
|
65
73
|
|
66
74
|
return Qtrue;
|
@@ -144,12 +152,10 @@ static void set_introspection_values(ojParser p) {
|
|
144
152
|
|
145
153
|
if(!d->introspect) return;
|
146
154
|
|
147
|
-
switch_introspection(d);
|
148
|
-
|
149
155
|
volatile VALUE obj = rb_hash_new();
|
150
|
-
rb_hash_aset(obj,
|
151
|
-
rb_hash_aset(obj,
|
152
|
-
rb_hash_aset(*(d->usual.vtail - 1),
|
156
|
+
rb_hash_aset(obj, start_byte_key, INT2FIX(pop(p)));
|
157
|
+
rb_hash_aset(obj, end_byte_key, INT2FIX(p->cur));
|
158
|
+
rb_hash_aset(*(d->usual.vtail - 1), introspection_key, obj);
|
153
159
|
}
|
154
160
|
|
155
161
|
static void close_object_introspected(ojParser p) {
|
@@ -159,10 +165,28 @@ static void close_object_introspected(ojParser p) {
|
|
159
165
|
set_introspection_values(p);
|
160
166
|
}
|
161
167
|
|
168
|
+
// We switch introspection off only for object and array keys.
|
169
|
+
static void close_object_key_introspected(ojParser p) {
|
170
|
+
IntrospectDelegate d = (IntrospectDelegate)p->ctx;
|
171
|
+
d->delegated_close_object_func(p);
|
172
|
+
|
173
|
+
if(d->introspect) {
|
174
|
+
set_introspection_values(p);
|
175
|
+
switch_introspection(d);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
static void close_array_key_introspected(ojParser p) {
|
180
|
+
IntrospectDelegate d = (IntrospectDelegate)p->ctx;
|
181
|
+
d->delegated_close_array_key_func(p);
|
182
|
+
|
183
|
+
if(d->introspect) switch_introspection(d);
|
184
|
+
}
|
185
|
+
|
162
186
|
static void init_introspect_parser(ojParser p, VALUE ropts) {
|
163
187
|
IntrospectDelegate d = ALLOC(struct _introspect_S);
|
164
188
|
|
165
|
-
oj_init_usual(p,
|
189
|
+
oj_init_usual(p, &d->usual);
|
166
190
|
|
167
191
|
// now function mangling...
|
168
192
|
d->delegated_free_func = p->free;
|
@@ -174,12 +198,7 @@ static void init_introspect_parser(ojParser p, VALUE ropts) {
|
|
174
198
|
d->delegated_option_func = p->option;
|
175
199
|
p->option = option;
|
176
200
|
|
177
|
-
//
|
178
|
-
// _usual is the first member of struct _introspect the cast to Usual in the
|
179
|
-
// usual.c mark() function should still work just fine.
|
180
|
-
|
181
|
-
// PCO - do you need the location of sub-objects and arrays or just top
|
182
|
-
// level objects?
|
201
|
+
// Wrap original functions to collect byte offsets
|
183
202
|
Funcs f = &p->funcs[TOP_FUN];
|
184
203
|
d->delegated_open_object_func = f->open_object;
|
185
204
|
d->delegated_close_object_func = f->close_object;
|
@@ -193,9 +212,12 @@ static void init_introspect_parser(ojParser p, VALUE ropts) {
|
|
193
212
|
f = &p->funcs[OBJECT_FUN];
|
194
213
|
d->delegated_open_array_key_func = f->open_array;
|
195
214
|
d->delegated_open_object_key_func = f->open_object;
|
215
|
+
d->delegated_close_array_key_func = f->close_array;
|
216
|
+
d->delegated_close_object_key_func = f->close_object;
|
196
217
|
f->open_array = open_array_key_introspected;
|
197
218
|
f->open_object = open_object_key_introspected;
|
198
|
-
f->
|
219
|
+
f->close_array = close_array_key_introspected;
|
220
|
+
f->close_object = close_object_key_introspected;
|
199
221
|
|
200
222
|
// Init stack
|
201
223
|
d->byte_offsets.current = 0;
|
@@ -208,18 +230,6 @@ static void init_introspect_parser(ojParser p, VALUE ropts) {
|
|
208
230
|
oj_parser_set_option(p, ropts);
|
209
231
|
}
|
210
232
|
|
211
|
-
VALUE oj_get_parser_introspect() {
|
212
|
-
VALUE oj_parser = oj_parser_new();
|
213
|
-
struct _ojParser *p;
|
214
|
-
Data_Get_Struct(oj_parser, struct _ojParser, p);
|
215
|
-
|
216
|
-
init_introspect_parser(p, Qnil);
|
217
|
-
|
218
|
-
rb_gc_register_address(&oj_parser);
|
219
|
-
|
220
|
-
return oj_parser;
|
221
|
-
}
|
222
|
-
|
223
233
|
static VALUE rb_new_introspect_parser(int argc, VALUE *argv, VALUE self) {
|
224
234
|
rb_check_arity(argc, 0, 1);
|
225
235
|
|
@@ -240,10 +250,6 @@ static VALUE rb_new_introspect_parser(int argc, VALUE *argv, VALUE self) {
|
|
240
250
|
|
241
251
|
init_introspect_parser(p, options);
|
242
252
|
|
243
|
-
// This locks the object in memory and is never recovered. Best to let the
|
244
|
-
// mark function handle it.
|
245
|
-
// rb_gc_register_address(&oj_parser);
|
246
|
-
|
247
253
|
return oj_parser;
|
248
254
|
}
|
249
255
|
|
@@ -267,6 +273,14 @@ void Init_introspect_ext() {
|
|
267
273
|
VALUE parser_module = rb_const_get(oj_module, rb_intern("Parser"));
|
268
274
|
VALUE introspection_class = rb_define_class_under(oj_module, "Introspect", rb_cObject);
|
269
275
|
|
276
|
+
introspection_key = ID2SYM(rb_intern("__oj_introspection"));
|
277
|
+
rb_gc_register_address(&introspection_key);
|
278
|
+
start_byte_key = ID2SYM(rb_intern("start_byte"));
|
279
|
+
rb_gc_register_address(&start_byte_key);
|
280
|
+
end_byte_key = ID2SYM(rb_intern("end_byte"));
|
281
|
+
rb_gc_register_address(&end_byte_key);
|
282
|
+
|
283
|
+
rb_const_set(introspection_class, rb_intern("KEY"), introspection_key);
|
270
284
|
rb_define_singleton_method(parser_module, "introspect", rb_get_default_introspect_parser, 0);
|
271
285
|
rb_define_singleton_method(introspection_class, "new", rb_new_introspect_parser, -1);
|
272
286
|
}
|
data/oj-introspect.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj-introspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Emin INAC
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.13.
|
19
|
+
version: 3.13.23
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.13.
|
26
|
+
version: 3.13.23
|
27
27
|
description: Embeds start and end byte offsets of JSON objects into generated Ruby
|
28
28
|
hashes.
|
29
29
|
email:
|