Module: FFI_Yajl::Ext::Parser

Included in:
Parser
Defined in:
ext/ffi_yajl/ext/parser/parser.c

Instance Method Summary collapse

Instance Method Details

#do_yajl_parse(str, opts) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'ext/ffi_yajl/ext/parser/parser.c', line 161

static VALUE mParser_do_yajl_parse(VALUE self, VALUE str, VALUE opts) {
  yajl_handle hand;
  yajl_status stat;
  unsigned char *err;
  CTX ctx;

  ctx.stack = rb_ary_new();
  ctx.key_stack = rb_ary_new();

  hand = yajl_alloc(&callbacks, NULL, &ctx);
  if ((stat = yajl_parse(hand, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str))) != yajl_status_ok) {
    err = yajl_get_error(hand, 1, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
    goto raise;
  }
  if ((stat = yajl_complete_parse(hand)) != yajl_status_ok) {
    err = yajl_get_error(hand, 1, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
    goto raise;
  }
  yajl_free(hand);
  return ctx.finished;

raise:
  if (hand) {
    yajl_free(hand);
  }
  rb_raise(cParseError, "%s", err);
}