@@ -247,16 +247,12 @@ PyObject *_internal_decode(_YajlDecoder *self, char *buffer, unsigned int buflen
247
247
yajl_status yrc ;
248
248
yrc = yajl_parse (parser , (const unsigned char * )(buffer ), buflen );
249
249
if (yrc != yajl_status_ok ) {
250
- //fprintf(stderr, "YAJL ERROR %s\n", yajl_status_to_string(yrc));
251
- PyErr_SetString (PyExc_ValueError , yajl_status_to_string (yrc ));
252
- return NULL ;
250
+ goto error ;
253
251
}
254
252
255
253
yrc = yajl_complete_parse (parser );
256
254
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 ));
259
- return NULL ;
255
+ goto error ;
260
256
}
261
257
262
258
yajl_free (parser );
@@ -268,4 +264,17 @@ PyObject *_internal_decode(_YajlDecoder *self, char *buffer, unsigned int buflen
268
264
PyObject * root = self -> root ;
269
265
self -> root = NULL ;
270
266
return root ;
267
+
268
+ unsigned char * str ;
269
+ error :
270
+ // TODO: It would be nice to make these parse errors more consistent with
271
+ // Oil. And maybe return them rather than printing on stderr.
272
+ str = yajl_get_error (parser , 1 , buffer , buflen );
273
+ fprintf (stderr , "%s" , (const char * ) str );
274
+ yajl_free_error (parser , str );
275
+ yajl_free (parser );
276
+
277
+ //fprintf(stderr, "YAJL ERROR %s\n", yajl_status_to_string(yrc));
278
+ PyErr_SetString (PyExc_ValueError , yajl_status_to_string (yrc ));
279
+ return NULL ;
271
280
}
0 commit comments