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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a087288e893750057d1e1e492e693dc4fd1d8e9d
4
- data.tar.gz: b477f818062421da4df0a059b355d48522c1e94b
3
+ metadata.gz: f81763696eea5a3b5cb4c13f03bcfafa1ba75883
4
+ data.tar.gz: 6c7f329234428cd07ec9fbf73b1040c27d82fab3
5
5
  SHA512:
6
- metadata.gz: b614c4a9214e03d8744c446fcbec59b57e7e3a08f88724918d0e9bd35eba1542ae76444d93d6189f67ad9ff718a3ad2c35746d70cb41ae3bfa00ecd5a000031c
7
- data.tar.gz: 250b143ad9111b33b792fae5ac909c3d0c771026615af1024a61f3476ad155150160027983cfc02e133fba2c31bcfa29fe90918a59e7c964e6b3e754b50e4197
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 finished;
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
- long len = RARRAY_LEN(ctx->stack);
20
- VALUE last = rb_ary_entry(ctx->stack, len-1);
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, ctx->key, val);
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 = 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
- rb_ary_push(ctx->key_stack, ctx->key);
39
- rb_ary_push(ctx->stack, obj);
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
- ctx->key = rb_ary_pop(ctx->key_stack);
44
- if ( RARRAY_LEN(ctx->stack) > 1 ) {
45
- set_value(ctx, rb_ary_pop(ctx->stack));
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 = rb_ary_pop(ctx->stack);
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
- ctx.stack = rb_ary_new();
168
- ctx.key_stack = rb_ary_new();
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
- /* hack to avoid garbage collection */
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 ctx.finished;
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
@@ -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
@@ -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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module FFI_Yajl
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.6
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-05 00:00:00.000000000 Z
11
+ date: 2014-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake