ffi-yajl 0.1.6-universal-java → 0.1.7-universal-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/ffi_yajl/ext/parser/parser.c +25 -24
- data/lib/ffi_yajl/ext.rb +16 -18
- data/lib/ffi_yajl/ffi/parser.rb +0 -15
- data/lib/ffi_yajl/json_gem.rb +2 -1
- data/lib/ffi_yajl/parser.rb +16 -0
- data/lib/ffi_yajl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f81763696eea5a3b5cb4c13f03bcfafa1ba75883
|
4
|
+
data.tar.gz: 6c7f329234428cd07ec9fbf73b1040c27d82fab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4b4112c08b390a78848ffcdac91e56e9e1009425cdcfb196cb69e3e983c9abd356217ad1e3fd4c73d398570c0b46fa61dc46347d582a93847fdfd080dbefac
|
7
|
+
data.tar.gz: a40243af1ddc3095562a3af781bcf73c2cb04691ce4cb2a090ca85e4987508b0673e8e89f0176364dbed765e0369ba3d4185b3eafcba52f8e4056d41e37da487
|
@@ -9,21 +9,20 @@ static rb_encoding *utf8Encoding;
|
|
9
9
|
static VALUE mFFI_Yajl, mExt, mParser, cParseError;
|
10
10
|
|
11
11
|
typedef struct {
|
12
|
-
VALUE
|
13
|
-
VALUE stack;
|
14
|
-
VALUE key_stack;
|
15
|
-
VALUE key;
|
12
|
+
VALUE self;
|
16
13
|
} CTX;
|
17
14
|
|
18
15
|
void set_value(CTX *ctx, VALUE val) {
|
19
|
-
|
20
|
-
VALUE
|
16
|
+
VALUE stack = rb_ivar_get(ctx->self, rb_intern("stack"));
|
17
|
+
VALUE key = rb_ivar_get(ctx->self, rb_intern("key"));
|
18
|
+
long len = RARRAY_LEN(stack);
|
19
|
+
VALUE last = rb_ary_entry(stack, len-1);
|
21
20
|
switch (TYPE(last)) {
|
22
21
|
case T_ARRAY:
|
23
22
|
rb_ary_push(last, val);
|
24
23
|
break;
|
25
24
|
case T_HASH:
|
26
|
-
rb_hash_aset(last,
|
25
|
+
rb_hash_aset(last, key, val);
|
27
26
|
break;
|
28
27
|
default:
|
29
28
|
break;
|
@@ -31,20 +30,26 @@ void set_value(CTX *ctx, VALUE val) {
|
|
31
30
|
}
|
32
31
|
|
33
32
|
void set_key(CTX *ctx, VALUE key) {
|
34
|
-
ctx->key
|
33
|
+
rb_ivar_set(ctx->self, rb_intern("key"), key);
|
35
34
|
}
|
36
35
|
|
37
36
|
void start_object(CTX *ctx, VALUE obj) {
|
38
|
-
|
39
|
-
|
37
|
+
VALUE key_stack = rb_ivar_get(ctx->self, rb_intern("key_stack"));
|
38
|
+
VALUE key = rb_ivar_get(ctx->self, rb_intern("key"));
|
39
|
+
VALUE stack = rb_ivar_get(ctx->self, rb_intern("stack"));
|
40
|
+
|
41
|
+
rb_ary_push(key_stack, key);
|
42
|
+
rb_ary_push(stack, obj);
|
40
43
|
}
|
41
44
|
|
42
45
|
void end_object(CTX *ctx) {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
VALUE key_stack = rb_ivar_get(ctx->self, rb_intern("key_stack"));
|
47
|
+
VALUE stack = rb_ivar_get(ctx->self, rb_intern("stack"));
|
48
|
+
rb_ivar_set(ctx->self, rb_intern("key"), rb_ary_pop(key_stack));
|
49
|
+
if ( RARRAY_LEN(stack) > 1 ) {
|
50
|
+
set_value(ctx, rb_ary_pop(stack));
|
46
51
|
} else {
|
47
|
-
ctx->finished
|
52
|
+
rb_ivar_set(ctx->self, rb_intern("finished"), rb_ary_pop(stack));
|
48
53
|
}
|
49
54
|
}
|
50
55
|
|
@@ -162,18 +167,14 @@ static VALUE mParser_do_yajl_parse(VALUE self, VALUE str, VALUE opts) {
|
|
162
167
|
yajl_handle hand;
|
163
168
|
yajl_status stat;
|
164
169
|
unsigned char *err;
|
165
|
-
CTX ctx;
|
170
|
+
volatile CTX ctx;
|
166
171
|
|
167
|
-
|
168
|
-
|
172
|
+
rb_ivar_set(self, rb_intern("stack"), rb_ary_new());
|
173
|
+
rb_ivar_set(self, rb_intern("key_stack"), rb_ary_new());
|
169
174
|
|
170
|
-
|
171
|
-
rb_ivar_set(self, rb_intern("stack"), ctx.stack);
|
172
|
-
rb_ivar_set(self, rb_intern("key_stack"), ctx.key_stack);
|
173
|
-
rb_ivar_set(self, rb_intern("finished"), ctx.stack);
|
174
|
-
rb_ivar_set(self, rb_intern("key"), ctx.stack);
|
175
|
+
ctx.self = self;
|
175
176
|
|
176
|
-
hand = yajl_alloc(&callbacks, NULL, &ctx);
|
177
|
+
hand = yajl_alloc(&callbacks, NULL, (void *)&ctx);
|
177
178
|
if ((stat = yajl_parse(hand, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str))) != yajl_status_ok) {
|
178
179
|
err = yajl_get_error(hand, 1, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
|
179
180
|
goto raise;
|
@@ -183,7 +184,7 @@ static VALUE mParser_do_yajl_parse(VALUE self, VALUE str, VALUE opts) {
|
|
183
184
|
goto raise;
|
184
185
|
}
|
185
186
|
yajl_free(hand);
|
186
|
-
return
|
187
|
+
return rb_ivar_get(self, rb_intern("finished"));
|
187
188
|
|
188
189
|
raise:
|
189
190
|
if (hand) {
|
data/lib/ffi_yajl/ext.rb
CHANGED
@@ -7,34 +7,32 @@ require 'libyajl2'
|
|
7
7
|
begin
|
8
8
|
require 'fiddle'
|
9
9
|
rescue LoadError
|
10
|
+
end
|
11
|
+
begin
|
10
12
|
require 'dl'
|
13
|
+
rescue LoadError
|
11
14
|
end
|
12
15
|
|
13
16
|
module FFI_Yajl
|
17
|
+
# FIXME: DRY with ffi_yajl/ffi.rb
|
18
|
+
libname = ::FFI.map_library_name("yajl")
|
19
|
+
libpath = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
20
|
+
libpath.gsub!(/dylib/, 'bundle')
|
21
|
+
libpath = ::FFI.map_library_name("yajl") unless File.exist?(libpath)
|
22
|
+
if defined?(Fiddle) && Fiddle.respond_to?(:dlopen)
|
23
|
+
::Fiddle.dlopen(libpath)
|
24
|
+
elsif defined?(DL) && DL.respond_to?(:dlopen)
|
25
|
+
::DL.dlopen(libpath)
|
26
|
+
else
|
27
|
+
ffi_lib libpath
|
28
|
+
end
|
29
|
+
|
14
30
|
class Parser
|
15
|
-
# FIXME: DRY with ffi_yajl/ffi.rb
|
16
|
-
libname = ::FFI.map_library_name("yajl")
|
17
|
-
libpath = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
18
|
-
libpath.gsub!(/dylib/, 'bundle')
|
19
|
-
if defined?(Fiddle)
|
20
|
-
::Fiddle.dlopen(libpath)
|
21
|
-
else
|
22
|
-
::DL.dlopen(libpath)
|
23
|
-
end
|
24
31
|
require 'ffi_yajl/ext/parser'
|
25
32
|
include FFI_Yajl::Ext::Parser
|
26
33
|
end
|
27
34
|
|
28
35
|
class Encoder
|
29
|
-
# FIXME: DRY with ffi_yajl/ffi.rb
|
30
|
-
libname = ::FFI.map_library_name("yajl")
|
31
|
-
libpath = File.expand_path(File.join(Libyajl2.opt_path, libname))
|
32
|
-
libpath.gsub!(/dylib/, 'bundle')
|
33
|
-
if defined?(Fiddle)
|
34
|
-
::Fiddle.dlopen(libpath)
|
35
|
-
else
|
36
|
-
::DL.dlopen(libpath)
|
37
|
-
end
|
38
36
|
require 'ffi_yajl/ext/encoder'
|
39
37
|
include FFI_Yajl::Ext::Encoder
|
40
38
|
end
|
data/lib/ffi_yajl/ffi/parser.rb
CHANGED
@@ -4,14 +4,6 @@ require 'ffi_yajl/ffi'
|
|
4
4
|
module FFI_Yajl
|
5
5
|
module FFI
|
6
6
|
module Parser
|
7
|
-
attr_accessor :stack, :key_stack, :key, :finished
|
8
|
-
|
9
|
-
#
|
10
|
-
# stack used to build up our complex object
|
11
|
-
#
|
12
|
-
def stack
|
13
|
-
@stack ||= Array.new
|
14
|
-
end
|
15
7
|
|
16
8
|
def set_value(val)
|
17
9
|
case stack.last
|
@@ -33,13 +25,6 @@ module FFI_Yajl
|
|
33
25
|
end
|
34
26
|
end
|
35
27
|
|
36
|
-
#
|
37
|
-
# stack to keep track of keys as we create nested hashes
|
38
|
-
#
|
39
|
-
def key_stack
|
40
|
-
@key_stack ||= Array.new
|
41
|
-
end
|
42
|
-
|
43
28
|
def key_push
|
44
29
|
key_stack.push(key)
|
45
30
|
end
|
data/lib/ffi_yajl/json_gem.rb
CHANGED
@@ -20,7 +20,8 @@ module JSON
|
|
20
20
|
raise JSON::GeneratorError, e.message
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.pretty_generate(obj, opts=
|
23
|
+
def self.pretty_generate(obj, opts=nil)
|
24
|
+
opts ||= {}
|
24
25
|
options_map = {}
|
25
26
|
options_map[:pretty] = true
|
26
27
|
options_map[:indent] = opts[:indent] if opts.has_key?(:indent)
|
data/lib/ffi_yajl/parser.rb
CHANGED
@@ -2,8 +2,24 @@
|
|
2
2
|
module FFI_Yajl
|
3
3
|
class ParseError < StandardError; end
|
4
4
|
class Parser
|
5
|
+
attr_accessor :stack, :key_stack, :key, :finished
|
6
|
+
|
5
7
|
attr_accessor :opts
|
6
8
|
|
9
|
+
#
|
10
|
+
# stack used to build up our complex object
|
11
|
+
#
|
12
|
+
def stack
|
13
|
+
@stack ||= Array.new
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# stack to keep track of keys as we create nested hashes
|
18
|
+
#
|
19
|
+
def key_stack
|
20
|
+
@key_stack ||= Array.new
|
21
|
+
end
|
22
|
+
|
7
23
|
def self.parse(obj, *args)
|
8
24
|
new(*args).parse(obj)
|
9
25
|
end
|
data/lib/ffi_yajl/version.rb
CHANGED
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: 0.1.
|
4
|
+
version: 0.1.7
|
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-06-
|
11
|
+
date: 2014-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|