RC::ConstHandle<Value> parse( char const *data, unsigned len ) { yajl_status yajlStatus; RC::ConstHandle<Value> result; m_contextStack.push_back( new DirectContext( result ) ); yajlStatus = yajl_parse( m_yajlHandle, (const unsigned char *)data, len ); if ( yajlStatus != yajl_status_ok ) throw Exception( "JSON parser error: " + std::string( yajl_status_to_string( yajlStatus ) ) ); yajlStatus = yajl_parse_complete( m_yajlHandle ); if ( yajlStatus != yajl_status_ok ) throw Exception( "JSON parser error: " + std::string( yajl_status_to_string( yajlStatus ) ) ); Context *lastContext = m_contextStack.back(); m_contextStack.pop_back(); delete lastContext; return result; }
PyObject *_internal_decode(_YajlDecoder *self, char *buffer, unsigned int buflen) { yajl_handle parser = NULL; yajl_status yrc; yajl_parser_config config = { 1, 1 }; PyObject *root; if (self->elements.used > 0) { py_yajl_ps_free(self->elements); py_yajl_ps_init(self->elements); } if (self->keys.used > 0) { py_yajl_ps_free(self->keys); py_yajl_ps_init(self->keys); } /* callbacks, config, allocfuncs */ parser = yajl_alloc(&decode_callbacks, &config, NULL, (void *)(self)); yrc = yajl_parse(parser, (const unsigned char *)(buffer), buflen); yajl_parse_complete(parser); yajl_free(parser); if (yrc != yajl_status_ok) { PyErr_SetObject(PyExc_ValueError, PyUnicode_FromString(yajl_status_to_string(yrc))); return NULL; } if (self->root == NULL) { PyErr_SetObject(PyExc_ValueError, PyUnicode_FromString("The root object is NULL")); return NULL; } // Callee now owns memory, we'll leave refcnt at one and // null out our pointer. root = self->root; self->root = NULL; return root; }