#c #json #boost #jsonreader
#c #json #boost #jsonreader
Вопрос:
Я использую boost для обработки Json, он работает хорошо, но сегодня я получаю ядро. вот стек.
#0 0x0000000000517a19 in std::for_each<std::reverse_iterator<__gnu_cxx::__normal_iterator<boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >**, std::vector<boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*, std::allocator<boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*> > > >, std::binder2nd<std::mem_fun1_t<int, boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >, boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> >*> > > (__first=
{<std::iterator<std::random_access_iterator_tag,boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*,ptrdiff_t,boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >**,boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*amp;>> = {<No data fields>}, current = {_M_current = 0x7fcb5d7a1268}}, __last=
{<std::iterator<std::random_access_iterator_tag,boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*,ptrdiff_t,boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >**,boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*amp;>> = {<No data fields>}, current = {_M_current = 0x7fcb5d7a1260}}, __f=
{<std::unary_function<boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*,int>> = {<No data fields>}, op = {<std::binary_function<boost::spirit::classic::impl::grammar_helper_base<boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> > >*,boost::spirit::classic::grammar<boost::property_tree::json_parser::json_grammar<boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::classic::parser_context<boost::spirit::classic::nil_t> >*,int>> = {<No data fields>}, _M_f = {__pfn = 0x1, __delta = 0}}, value = 0x4121a440}) at /usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../include/c /3.4.5/bits/stl_function.h:664
#1 0x000000000051b819 in ~grammar (this=0x4121a440) at bc_out/third-64/boost/output/include/boost/spirit/home/classic/core/non_terminal/impl/grammar.ipp:103
#2 0x000000000051ef46 in boost::property_tree::json_parser::read_json_internal<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > > (stream=Variable "stream" is not available.
)
at bc_out/third-64/boost/output/include/boost/property_tree/detail/json_parser_read.hpp:310
#3 0x000000000051f2ed in boost::property_tree::json_parser::read_json<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > > (stream=Variable "stream" is not available.
)
at /usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../include/c /3.4.5/ext/new_allocator.h:69
и это мой код.
std::stringstream stream;
boost::property_tree::ptree pt;
char *strs = (char *)(row->get_value(json_it->src_index));
if (strs == NULL) {
continue;
}
std::string strJson = strs;
stream << strJson;
try {
//crash on this row
boost::property_tree::json_parser::read_json<boost::property_tree::ptree>(stream, pt);
} catch (boost::property_tree::ptree_error amp;e) {
REPORT_WARNING("read json fail: %s, error:%s", strJson.c_str(), e.what());
continue;
} catch (std::exceptionamp; e) {
REPORT_WARNING("read json fail: %s, error:%s", strJson.c_str(), e.what());
continue;
} catch (...) {
REPORT_WARNING("read json fail: %s", strJson.c_str());
continue;
}
Я не знаю, что с этим не так, кто-нибудь может мне помочь?
Комментарии:
1. часть «недоступно», скорее всего, является исходным кодом для показа вам, что происходит в этой позиции трассировки стека. Что касается причины сбоя, я не вижу никакого кода, который вы перечислили, который, очевидно, соответствует чему-либо в этой трассировке стека, поэтому я не знаю.
2. Вы правы, «недоступно» не важно. Я предоставил больше информации по этому вопросу. Есть ли какие-либо ошибки в этих кодах? Я думаю, что это недопустимая строка Json, которая приводит к сбою программы. Но по некоторым причинам я не могу воспроизвести это. Спасибо!