summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-11-22 14:34:12 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-11-22 14:34:12 -0800
commit702720c2cc1a11314a4046819ab763f759c37a6b (patch)
treef3bf751b368180004322b3a4377132eb951333ef
parent981b65b2244b82439c1f923a021badccebac77d1 (diff)
downloadffi-yajl-702720c2cc1a11314a4046819ab763f759c37a6b.tar.gz
fix bare object parsing
closes #2 and #16
-rw-r--r--ext/ffi_yajl/ext/parser/parser.c6
-rw-r--r--lib/ffi_yajl/ffi/parser.rb7
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
-