@@ -232,9 +232,6 @@ static yajl_callbacks decode_callbacks = {
232
232
233
233
PyObject * _internal_decode (_YajlDecoder * self , char * buffer , unsigned int buflen )
234
234
{
235
- yajl_handle parser = NULL ;
236
- yajl_status yrc ;
237
-
238
235
if (self -> elements .used > 0 ) {
239
236
py_yajl_ps_free (self -> elements );
240
237
py_yajl_ps_init (self -> elements );
@@ -245,23 +242,27 @@ PyObject *_internal_decode(_YajlDecoder *self, char *buffer, unsigned int buflen
245
242
}
246
243
247
244
/* callbacks, config, allocfuncs */
248
- parser = yajl_alloc (& decode_callbacks , NULL , (void * )(self ));
249
- yrc = yajl_parse (parser , (const unsigned char * )(buffer ), buflen );
250
- yajl_complete_parse (parser );
251
- yajl_free (parser );
245
+ yajl_handle parser = yajl_alloc (& decode_callbacks , NULL , (void * )(self ));
252
246
247
+ yajl_status yrc ;
248
+ yrc = yajl_parse (parser , (const unsigned char * )(buffer ), buflen );
253
249
if (yrc != yajl_status_ok ) {
254
- //fprintf(stderr, "YAJL ERROR %d\n", yrc);
255
- //fprintf(stderr, "%s\n", yajl_status_to_string(yrc));
250
+ //fprintf(stderr, "YAJL ERROR %s\n", yajl_status_to_string(yrc));
256
251
PyErr_SetString (PyExc_ValueError , yajl_status_to_string (yrc ));
257
252
return NULL ;
258
253
}
259
254
260
- if (self -> root == NULL ) {
261
- PyErr_SetString (PyExc_ValueError , "The root object is NULL" );
255
+ yrc = yajl_complete_parse (parser );
256
+ if (yrc != yajl_status_ok ) {
257
+ //fprintf(stderr, "YAJL ERROR %s\n", yajl_status_to_string(yrc));
258
+ PyErr_SetString (PyExc_ValueError , yajl_status_to_string (yrc ));
262
259
return NULL ;
263
260
}
264
261
262
+ yajl_free (parser );
263
+
264
+ assert (self -> root != NULL );
265
+
265
266
// Callee now owns memory, we'll leave refcnt at one and
266
267
// null out our pointer.
267
268
PyObject * root = self -> root ;
0 commit comments