ffi-yajl 1.2.0-universal-java → 1.3.0-universal-java
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/ext/ffi_yajl/ext/encoder/encoder.c +100 -28
- data/ext/ffi_yajl/ext/encoder/extconf.rb +1 -1
- data/ext/ffi_yajl/ext/parser/extconf.rb +1 -1
- data/ext/ffi_yajl/ext/parser/parser.c +2 -4
- data/lib/ffi_yajl.rb +22 -3
- data/lib/ffi_yajl/ext.rb +1 -1
- data/lib/ffi_yajl/ffi/encoder.rb +61 -26
- data/lib/ffi_yajl/ffi/parser.rb +2 -5
- data/lib/ffi_yajl/json_gem.rb +2 -0
- data/lib/ffi_yajl/parser.rb +2 -0
- data/lib/ffi_yajl/version.rb +1 -1
- data/spec/ffi_yajl/encoder_spec.rb +25 -0
- data/spec/ffi_yajl/parser_spec.rb +49 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78b174d432e532e7ce493e825ab04fb81732d0e8
|
4
|
+
data.tar.gz: 97199ad459ab9d164231563dc91fe26d4923c22f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417f7f79a50826cd7315ba893bfe01c3e16fc615a368af5c37b471de854ba036013deea0eb382fd3dcd50c81b2d32e322bcc9549c479c5b9c93daabd3cfb2802
|
7
|
+
data.tar.gz: c4e9a16d122714c1446e82993ac4b979aaf4ad0373b1110581ac5fb683c767908ae90dace4aafb1d89456c858945e62004bae3975c92d8de5e6695c169b6b077
|
@@ -78,19 +78,30 @@ static VALUE rb_cHash_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
78
78
|
struct yajl_gen_t *yajl_gen;
|
79
79
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
80
80
|
|
81
|
-
|
81
|
+
if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
|
82
|
+
ID sym_to_s = rb_intern("to_s");
|
83
|
+
VALUE str = rb_funcall(self, sym_to_s, 0);
|
84
|
+
char *cptr = RSTRING_PTR(str);
|
85
|
+
int len = RSTRING_LEN(str);
|
86
|
+
|
87
|
+
CHECK_STATUS(
|
88
|
+
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
89
|
+
);
|
90
|
+
} else {
|
91
|
+
extra = rb_hash_new(); /* FIXME: reduce garbage */
|
82
92
|
|
83
|
-
|
93
|
+
rb_hash_aset(extra, rb_str_new2("yajl_gen"), rb_yajl_gen);
|
84
94
|
|
85
|
-
|
95
|
+
rb_hash_aset(extra, rb_str_new2("state"), state);
|
86
96
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
97
|
+
CHECK_STATUS(
|
98
|
+
yajl_gen_map_open(yajl_gen)
|
99
|
+
);
|
100
|
+
rb_hash_foreach(self, rb_cHash_ffi_yajl_callback, extra);
|
101
|
+
CHECK_STATUS(
|
102
|
+
yajl_gen_map_close(yajl_gen)
|
103
|
+
);
|
104
|
+
}
|
94
105
|
|
95
106
|
return Qnil;
|
96
107
|
}
|
@@ -103,16 +114,27 @@ static VALUE rb_cArray_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
103
114
|
struct yajl_gen_t *yajl_gen;
|
104
115
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
105
116
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
117
|
+
if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
|
118
|
+
ID sym_to_s = rb_intern("to_s");
|
119
|
+
VALUE str = rb_funcall(self, sym_to_s, 0);
|
120
|
+
char *cptr = RSTRING_PTR(str);
|
121
|
+
int len = RSTRING_LEN(str);
|
122
|
+
|
123
|
+
CHECK_STATUS(
|
124
|
+
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
125
|
+
);
|
126
|
+
} else {
|
127
|
+
CHECK_STATUS(
|
128
|
+
yajl_gen_array_open(yajl_gen)
|
129
|
+
);
|
130
|
+
for(i=0; i<RARRAY_LEN(self); i++) {
|
131
|
+
val = rb_ary_entry(self, i);
|
132
|
+
rb_funcall(val, sym_ffi_yajl, 2, rb_yajl_gen, state);
|
133
|
+
}
|
134
|
+
CHECK_STATUS(
|
135
|
+
yajl_gen_array_close(yajl_gen)
|
136
|
+
);
|
112
137
|
}
|
113
|
-
CHECK_STATUS(
|
114
|
-
yajl_gen_array_close(yajl_gen)
|
115
|
-
);
|
116
138
|
|
117
139
|
return Qnil;
|
118
140
|
}
|
@@ -121,9 +143,22 @@ static VALUE rb_cNilClass_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
121
143
|
yajl_gen_status status;
|
122
144
|
struct yajl_gen_t *yajl_gen;
|
123
145
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
124
|
-
|
125
|
-
|
126
|
-
|
146
|
+
|
147
|
+
if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
|
148
|
+
ID sym_to_s = rb_intern("to_s");
|
149
|
+
VALUE str = rb_funcall(self, sym_to_s, 0);
|
150
|
+
char *cptr = RSTRING_PTR(str);
|
151
|
+
int len = RSTRING_LEN(str);
|
152
|
+
|
153
|
+
CHECK_STATUS(
|
154
|
+
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
155
|
+
);
|
156
|
+
} else {
|
157
|
+
CHECK_STATUS(
|
158
|
+
yajl_gen_null(yajl_gen)
|
159
|
+
);
|
160
|
+
}
|
161
|
+
|
127
162
|
return Qnil;
|
128
163
|
}
|
129
164
|
|
@@ -131,9 +166,22 @@ static VALUE rb_cTrueClass_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state)
|
|
131
166
|
yajl_gen_status status;
|
132
167
|
struct yajl_gen_t *yajl_gen;
|
133
168
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
134
|
-
|
135
|
-
|
136
|
-
|
169
|
+
|
170
|
+
if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
|
171
|
+
ID sym_to_s = rb_intern("to_s");
|
172
|
+
VALUE str = rb_funcall(self, sym_to_s, 0);
|
173
|
+
char *cptr = RSTRING_PTR(str);
|
174
|
+
int len = RSTRING_LEN(str);
|
175
|
+
|
176
|
+
CHECK_STATUS(
|
177
|
+
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
178
|
+
);
|
179
|
+
} else {
|
180
|
+
CHECK_STATUS(
|
181
|
+
yajl_gen_bool(yajl_gen, 1)
|
182
|
+
);
|
183
|
+
}
|
184
|
+
|
137
185
|
return Qnil;
|
138
186
|
}
|
139
187
|
|
@@ -141,9 +189,22 @@ static VALUE rb_cFalseClass_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state)
|
|
141
189
|
yajl_gen_status status;
|
142
190
|
struct yajl_gen_t *yajl_gen;
|
143
191
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
144
|
-
|
145
|
-
|
146
|
-
|
192
|
+
|
193
|
+
if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
|
194
|
+
ID sym_to_s = rb_intern("to_s");
|
195
|
+
VALUE str = rb_funcall(self, sym_to_s, 0);
|
196
|
+
char *cptr = RSTRING_PTR(str);
|
197
|
+
int len = RSTRING_LEN(str);
|
198
|
+
|
199
|
+
CHECK_STATUS(
|
200
|
+
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
201
|
+
);
|
202
|
+
} else {
|
203
|
+
CHECK_STATUS(
|
204
|
+
yajl_gen_bool(yajl_gen, 0)
|
205
|
+
);
|
206
|
+
}
|
207
|
+
|
147
208
|
return Qnil;
|
148
209
|
}
|
149
210
|
|
@@ -168,6 +229,7 @@ static VALUE rb_cFixnum_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
168
229
|
yajl_gen_number(yajl_gen, cptr, len)
|
169
230
|
);
|
170
231
|
}
|
232
|
+
|
171
233
|
return Qnil;
|
172
234
|
}
|
173
235
|
|
@@ -179,6 +241,7 @@ static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
179
241
|
int len = RSTRING_LEN(str);
|
180
242
|
struct yajl_gen_t *yajl_gen;
|
181
243
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
244
|
+
|
182
245
|
if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
|
183
246
|
rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
|
184
247
|
}
|
@@ -191,6 +254,7 @@ static VALUE rb_cBignum_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
191
254
|
yajl_gen_number(yajl_gen, cptr, len)
|
192
255
|
);
|
193
256
|
}
|
257
|
+
|
194
258
|
return Qnil;
|
195
259
|
}
|
196
260
|
|
@@ -202,6 +266,7 @@ static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
202
266
|
int len = RSTRING_LEN(str);
|
203
267
|
struct yajl_gen_t *yajl_gen;
|
204
268
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
269
|
+
|
205
270
|
if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
|
206
271
|
rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
|
207
272
|
}
|
@@ -214,6 +279,7 @@ static VALUE rb_cFloat_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
214
279
|
yajl_gen_number(yajl_gen, cptr, len)
|
215
280
|
);
|
216
281
|
}
|
282
|
+
|
217
283
|
return Qnil;
|
218
284
|
}
|
219
285
|
|
@@ -221,9 +287,11 @@ static VALUE rb_cString_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
221
287
|
yajl_gen_status status;
|
222
288
|
struct yajl_gen_t *yajl_gen;
|
223
289
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
290
|
+
|
224
291
|
CHECK_STATUS(
|
225
292
|
yajl_gen_string(yajl_gen, (unsigned char *)RSTRING_PTR(self), RSTRING_LEN(self))
|
226
293
|
);
|
294
|
+
|
227
295
|
return Qnil;
|
228
296
|
}
|
229
297
|
|
@@ -236,9 +304,11 @@ static VALUE object_to_s_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
236
304
|
int len = RSTRING_LEN(str);
|
237
305
|
struct yajl_gen_t *yajl_gen;
|
238
306
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
307
|
+
|
239
308
|
CHECK_STATUS(
|
240
309
|
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
241
310
|
);
|
311
|
+
|
242
312
|
return Qnil;
|
243
313
|
}
|
244
314
|
|
@@ -258,9 +328,11 @@ static VALUE rb_cTime_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
|
|
258
328
|
int len = RSTRING_LEN(str);
|
259
329
|
struct yajl_gen_t *yajl_gen;
|
260
330
|
Data_Get_Struct(rb_yajl_gen, struct yajl_gen_t, yajl_gen);
|
331
|
+
|
261
332
|
CHECK_STATUS(
|
262
333
|
yajl_gen_string(yajl_gen, (unsigned char *)cptr, len)
|
263
334
|
);
|
335
|
+
|
264
336
|
return Qnil;
|
265
337
|
}
|
266
338
|
|
@@ -26,6 +26,7 @@ void set_value(CTX *ctx, VALUE val) {
|
|
26
26
|
rb_hash_aset(last, key, val);
|
27
27
|
break;
|
28
28
|
default:
|
29
|
+
rb_ary_push(stack, val);
|
29
30
|
break;
|
30
31
|
}
|
31
32
|
}
|
@@ -49,8 +50,6 @@ void end_object(CTX *ctx) {
|
|
49
50
|
rb_ivar_set(ctx->self, rb_intern("key"), rb_ary_pop(key_stack));
|
50
51
|
if ( RARRAY_LEN(stack) > 1 ) {
|
51
52
|
set_value(ctx, rb_ary_pop(stack));
|
52
|
-
} else {
|
53
|
-
rb_ivar_set(ctx->self, rb_intern("finished"), rb_ary_pop(stack));
|
54
53
|
}
|
55
54
|
}
|
56
55
|
|
@@ -211,7 +210,7 @@ static VALUE mParser_do_yajl_parse(VALUE self, VALUE str, VALUE yajl_opts) {
|
|
211
210
|
goto raise;
|
212
211
|
}
|
213
212
|
yajl_free(hand);
|
214
|
-
return rb_ivar_get(self, rb_intern("
|
213
|
+
return rb_ary_pop(rb_ivar_get(self, rb_intern("stack")));
|
215
214
|
|
216
215
|
raise:
|
217
216
|
if (hand) {
|
@@ -230,4 +229,3 @@ void Init_parser() {
|
|
230
229
|
utf8Encoding = rb_utf8_encoding();
|
231
230
|
#endif
|
232
231
|
}
|
233
|
-
|
data/lib/ffi_yajl.rb
CHANGED
@@ -1,14 +1,33 @@
|
|
1
1
|
|
2
|
+
#
|
3
|
+
# Precedence:
|
4
|
+
#
|
5
|
+
# - The FORCE_FFI_YAJL env var takes precedence over everything else, the user
|
6
|
+
# theoretically knows best
|
7
|
+
# - Java always gets ffi because jruby only supports ffi
|
8
|
+
# - There is a conflict between loading libyajl 1.x and 2.x in the same VM
|
9
|
+
# process (on a fundamental basis, simply guru medidate about how the
|
10
|
+
# c-symbols work if you load both libs). For some reason the ffi interface
|
11
|
+
# seems to work fine sometimes (i'm not sure how) so we fall back to that--
|
12
|
+
# this is much more likely to be converted into a raise than to have the warn
|
13
|
+
# dropped, so don't bother asking for that.
|
14
|
+
# - Then we try the c-ext and rescue into ffi that fails
|
15
|
+
#
|
2
16
|
if ENV['FORCE_FFI_YAJL'] == "ext"
|
3
17
|
require 'ffi_yajl/ext'
|
4
|
-
elsif ENV['FORCE_FFI_YAJL'] == "ffi"
|
5
|
-
|
6
|
-
|
18
|
+
elsif ENV['FORCE_FFI_YAJL'] == "ffi"
|
19
|
+
require 'ffi_yajl/ffi'
|
20
|
+
elsif RUBY_PLATFORM == "java"
|
21
|
+
require 'ffi_yajl/ffi'
|
22
|
+
elsif defined?(Yajl)
|
23
|
+
warn "the ffi-yajl and yajl-ruby gems have incompatible C libyajl libs and should not be loaded in the same Ruby VM"
|
24
|
+
warn "falling back to ffi which might work (or might not, no promises)"
|
7
25
|
require 'ffi_yajl/ffi'
|
8
26
|
else
|
9
27
|
begin
|
10
28
|
require 'ffi_yajl/ext'
|
11
29
|
rescue LoadError
|
30
|
+
warn "failed to load the ffi-yajl c-extension, falling back to ffi interface"
|
12
31
|
require 'ffi_yajl/ffi'
|
13
32
|
end
|
14
33
|
end
|
data/lib/ffi_yajl/ext.rb
CHANGED
@@ -61,7 +61,7 @@ module FFI_Yajl
|
|
61
61
|
end
|
62
62
|
|
63
63
|
unless try_fiddle_dlopen(libpath) || try_dl_dlopen(libpath) || try_ffi_dlopen(libpath)
|
64
|
-
raise "cannot find dlopen
|
64
|
+
raise "cannot find dlopen via Fiddle, DL or FFI, what am I supposed to do?"
|
65
65
|
end
|
66
66
|
|
67
67
|
class Parser
|
data/lib/ffi_yajl/ffi/encoder.rb
CHANGED
@@ -46,56 +46,91 @@ end
|
|
46
46
|
|
47
47
|
class Hash
|
48
48
|
def ffi_yajl(yajl_gen, state)
|
49
|
-
if
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
if state[:processing_key]
|
50
|
+
str = self.to_s
|
51
|
+
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
|
52
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
|
56
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
57
|
+
end
|
58
|
+
self.each do |key, value|
|
59
|
+
# Perf Fix: mutate state hash rather than creating new copy
|
60
|
+
state[:processing_key] = true
|
61
|
+
key.ffi_yajl(yajl_gen, state)
|
62
|
+
state[:processing_key] = false
|
63
|
+
value.ffi_yajl(yajl_gen, state)
|
64
|
+
end
|
65
|
+
if ( status = FFI_Yajl.yajl_gen_map_close(yajl_gen) ) != 0
|
66
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
65
72
|
class Array
|
66
73
|
def ffi_yajl(yajl_gen, state)
|
67
|
-
if
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
if state[:processing_key]
|
75
|
+
str = self.to_s
|
76
|
+
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
|
77
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0
|
81
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
82
|
+
end
|
83
|
+
self.each do |value|
|
84
|
+
value.ffi_yajl(yajl_gen, state)
|
85
|
+
end
|
86
|
+
if ( status = FFI_Yajl.yajl_gen_array_close(yajl_gen) ) != 0
|
87
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
88
|
+
end
|
75
89
|
end
|
76
90
|
end
|
77
91
|
end
|
78
92
|
|
79
93
|
class NilClass
|
80
94
|
def ffi_yajl(yajl_gen, state)
|
81
|
-
if
|
82
|
-
|
95
|
+
if state[:processing_key]
|
96
|
+
str = self.to_s
|
97
|
+
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
|
98
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
99
|
+
end
|
100
|
+
else
|
101
|
+
if ( status = FFI_Yajl.yajl_gen_null(yajl_gen) ) != 0
|
102
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
103
|
+
end
|
83
104
|
end
|
84
105
|
end
|
85
106
|
end
|
86
107
|
|
87
108
|
class TrueClass
|
88
109
|
def ffi_yajl(yajl_gen, state)
|
89
|
-
if
|
90
|
-
|
110
|
+
if state[:processing_key]
|
111
|
+
str = self.to_s
|
112
|
+
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
|
113
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
114
|
+
end
|
115
|
+
else
|
116
|
+
if ( status = FFI_Yajl.yajl_gen_bool(yajl_gen, 1) ) != 0
|
117
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
118
|
+
end
|
91
119
|
end
|
92
120
|
end
|
93
121
|
end
|
94
122
|
|
95
123
|
class FalseClass
|
96
124
|
def ffi_yajl(yajl_gen, state)
|
97
|
-
if
|
98
|
-
|
125
|
+
if state[:processing_key]
|
126
|
+
str = self.to_s
|
127
|
+
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
|
128
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
129
|
+
end
|
130
|
+
else
|
131
|
+
if ( status = FFI_Yajl.yajl_gen_bool(yajl_gen, 0) ) != 0
|
132
|
+
FFI_Yajl::Encoder.raise_error_for_status(status)
|
133
|
+
end
|
99
134
|
end
|
100
135
|
end
|
101
136
|
end
|
data/lib/ffi_yajl/ffi/parser.rb
CHANGED
@@ -13,15 +13,13 @@ module FFI_Yajl
|
|
13
13
|
when Array
|
14
14
|
stack.last.push(val)
|
15
15
|
else
|
16
|
-
|
16
|
+
stack.push(val)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def stack_pop
|
21
21
|
if stack.length > 1
|
22
22
|
set_value( stack.pop )
|
23
|
-
else
|
24
|
-
@finished = stack.pop
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -138,11 +136,10 @@ module FFI_Yajl
|
|
138
136
|
error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize)
|
139
137
|
raise ::FFI_Yajl::ParseError.new(error)
|
140
138
|
end
|
141
|
-
|
139
|
+
stack.pop
|
142
140
|
ensure
|
143
141
|
::FFI_Yajl.yajl_free(yajl_handle) if yajl_handle
|
144
142
|
end
|
145
143
|
end
|
146
144
|
end
|
147
145
|
end
|
148
|
-
|
data/lib/ffi_yajl/json_gem.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'ffi_yajl' unless defined?(FFI_Yajl::Parser)
|
5
5
|
|
6
|
+
warn "ffi-yajl/json_gem is deprecated, these monkeypatches will be dropped shortly"
|
7
|
+
|
6
8
|
module JSON
|
7
9
|
class JSONError < StandardError; end unless defined?(JSON::JSONError)
|
8
10
|
class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError)
|
data/lib/ffi_yajl/parser.rb
CHANGED
data/lib/ffi_yajl/version.rb
CHANGED
@@ -7,6 +7,31 @@ describe "FFI_Yajl::Encoder" do
|
|
7
7
|
|
8
8
|
let(:encoder) { FFI_Yajl::Encoder.new }
|
9
9
|
|
10
|
+
it "encodes hashes in keys as strings", :ruby_gte_193 => true do
|
11
|
+
ruby = { {'a' => 'b'} => 2 }
|
12
|
+
expect(encoder.encode(ruby)).to eq('{"{\"a\"=>\"b\"}":2}')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "encodes arrays in keys as strings", :ruby_gte_193 => true do
|
16
|
+
ruby = { [0,1] => 2 }
|
17
|
+
expect(encoder.encode(ruby)).to eq('{"[0, 1]":2}')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "encodes nil in keys as strings" do
|
21
|
+
ruby = { nil => 2 }
|
22
|
+
expect(encoder.encode(ruby)).to eq('{"":2}')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "encodes true in keys as strings" do
|
26
|
+
ruby = { true => 2 }
|
27
|
+
expect(encoder.encode(ruby)).to eq('{"true":2}')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "encodes false in keys as strings" do
|
31
|
+
ruby = { false => 2 }
|
32
|
+
expect(encoder.encode(ruby)).to eq('{"false":2}')
|
33
|
+
end
|
34
|
+
|
10
35
|
it "encodes fixnums in keys as strings" do
|
11
36
|
ruby = { 1 => 2 }
|
12
37
|
expect(encoder.encode(ruby)).to eq('{"1":2}')
|
@@ -14,6 +14,55 @@ describe "FFI_Yajl::Parser" do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
context "when parsing nil" do
|
18
|
+
let(:json) { nil }
|
19
|
+
it "should not coredump ruby" do
|
20
|
+
expect{ parser }.to raise_error(FFI_Yajl::ParseError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when parsing bare int" do
|
25
|
+
let(:json) { "1" }
|
26
|
+
it "should parse to the int value" do
|
27
|
+
expect( parser ).to eq(1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when parsing bare string" do
|
32
|
+
let(:json) { '"a"' }
|
33
|
+
it "should parse to the string value" do
|
34
|
+
expect( parser ).to eq("a")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when parsing bare true" do
|
39
|
+
let(:json) { "true" }
|
40
|
+
it "should parse to the true value" do
|
41
|
+
expect( parser ).to eq(true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when parsing bare false" do
|
46
|
+
let(:json) { "false" }
|
47
|
+
it "should parse to the false value" do
|
48
|
+
expect( parser ).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when parsing bare null" do
|
53
|
+
let(:json) { "null" }
|
54
|
+
it "should parse to the nil value" do
|
55
|
+
expect( parser ).to eq(nil)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when parsing bare float" do
|
60
|
+
let(:json) { "1.1" }
|
61
|
+
it "should parse to the a float" do
|
62
|
+
expect( parser ).to eq(1.1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
17
66
|
context "when json has comments" do
|
18
67
|
let(:json) { '{"key": /* this is a comment */ "value"}' }
|
19
68
|
|
@@ -482,4 +531,3 @@ describe "FFI_Yajl::Parser" do
|
|
482
531
|
end
|
483
532
|
end
|
484
533
|
end
|
485
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-yajl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: universal-java
|
6
6
|
authors:
|
7
7
|
- Lamont Granquist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1.
|
103
|
+
version: '1.2'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '1.
|
110
|
+
version: '1.2'
|
111
111
|
description: Ruby FFI wrapper around YAJL 2.x
|
112
112
|
email: lamont@getchef.com
|
113
113
|
executables:
|