diff options
-rw-r--r-- | ext/ffi_yajl/ext/parser/parser.c | 6 | ||||
-rw-r--r-- | lib/ffi_yajl/ffi/parser.rb | 7 |
2 files changed, 4 insertions, 9 deletions
diff --git a/ext/ffi_yajl/ext/parser/parser.c b/ext/ffi_yajl/ext/parser/parser.c index e2481cd..a2813af 100644 --- a/ext/ffi_yajl/ext/parser/parser.c +++ b/ext/ffi_yajl/ext/parser/parser.c @@ -26,6 +26,7 @@ void set_value(CTX *ctx, VALUE val) { rb_hash_aset(last, key, val); break; default: + rb_ary_push(stack, val); break; } } @@ -49,8 +50,6 @@ void end_object(CTX *ctx) { rb_ivar_set(ctx->self, rb_intern("key"), rb_ary_pop(key_stack)); if ( RARRAY_LEN(stack) > 1 ) { set_value(ctx, rb_ary_pop(stack)); - } else { - rb_ivar_set(ctx->self, rb_intern("finished"), rb_ary_pop(stack)); } } @@ -211,7 +210,7 @@ static VALUE mParser_do_yajl_parse(VALUE self, VALUE str, VALUE yajl_opts) { goto raise; } yajl_free(hand); - return rb_ivar_get(self, rb_intern("finished")); + return rb_ary_pop(rb_ivar_get(self, rb_intern("stack"))); raise: if (hand) { @@ -230,4 +229,3 @@ void Init_parser() { utf8Encoding = rb_utf8_encoding(); #endif } - diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb index 11682dc..7dfc26c 100644 --- a/lib/ffi_yajl/ffi/parser.rb +++ b/lib/ffi_yajl/ffi/parser.rb @@ -13,15 +13,13 @@ module FFI_Yajl when Array stack.last.push(val) else - raise FFI_Yajl::ParseError.new("internal error: object not a hash or array") + stack.push(val) end end def stack_pop if stack.length > 1 set_value( stack.pop ) - else - @finished = stack.pop end end @@ -138,11 +136,10 @@ module FFI_Yajl error = ::FFI_Yajl.yajl_get_error(yajl_handle, 1, str, str.bytesize) raise ::FFI_Yajl::ParseError.new(error) end - finished + stack.pop ensure ::FFI_Yajl.yajl_free(yajl_handle) if yajl_handle end end end end - |