diff --git a/generated_for_cmake/upb/json/parser.c b/generated_for_cmake/upb/json/parser.c index f72e945881..311eaee213 100644 --- a/generated_for_cmake/upb/json/parser.c +++ b/generated_for_cmake/upb/json/parser.c @@ -2036,7 +2036,7 @@ static void end_member(upb_json_parser *p) { p->top--; ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); UPB_ASSERT(ok); - upb_sink_endsubmsg(p->top->sink, sel); + upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel); } p->top->f = NULL; @@ -2150,7 +2150,7 @@ static void end_subobject(upb_json_parser *p) { p->top--; if (!is_unknown) { sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); - upb_sink_endsubmsg(p->top->sink, sel); + upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel); } } } diff --git a/tests/pb/test_decoder.cc b/tests/pb/test_decoder.cc index 5cc59e40c9..ef40f8f3e2 100644 --- a/tests/pb/test_decoder.cc +++ b/tests/pb/test_decoder.cc @@ -569,7 +569,7 @@ string wrap_text(int32_t fn, const string& text) { LINE("<"), num2string(fn), LINE(":{") " ", wrapped_text, - LINE("}") + LINE(" }") LINE(">")); return wrapped_text; } @@ -922,7 +922,7 @@ void test_valid() { LINE("%u:{") LINE(" <") LINE(" >") - LINE("}") + LINE(" }") LINE(">"), UPB_DESCRIPTOR_TYPE_MESSAGE); assert_successful_parse( @@ -933,7 +933,7 @@ void test_valid() { LINE("%u:{") LINE(" <") LINE(" >") - LINE("}") + LINE(" }") LINE("%u:5") LINE(">"), UPB_DESCRIPTOR_TYPE_MESSAGE, UPB_DESCRIPTOR_TYPE_INT32); @@ -957,9 +957,9 @@ void test_valid() { LINE(" <") LINE(" %u:2345678") LINE(" >") - LINE(" }") + LINE(" }") LINE(" >") - LINE("}") + LINE(" }") LINE("%u:22222") LINE(">"), msg_type, msg_type, int32_type, int32_type); @@ -984,7 +984,7 @@ void test_valid() { LINE(" %u:(5)\"abcde") LINE(" %u:\"") LINE(" >") - LINE("}") + LINE(" }") LINE(">"), msg_fn, UPB_DESCRIPTOR_TYPE_STRING, UPB_DESCRIPTOR_TYPE_STRING); @@ -1014,11 +1014,11 @@ void test_valid() { LINE(" %u:{") LINE(" <") LINE(" >") - LINE(" }") + LINE(" }") LINE(" >") - LINE(" }") + LINE(" }") LINE(" >") - LINE("}") + LINE(" }") LINE(">"), msg_fn, msg_fn, msg_fn); uint32_t repm_fn = rep_fn(UPB_DESCRIPTOR_TYPE_MESSAGE); @@ -1032,10 +1032,10 @@ void test_valid() { LINE(" %u:{") LINE(" <") LINE(" >") - LINE(" }") + LINE(" }") LINE(" ]") LINE(" >") - LINE(" }") + LINE(" }") LINE("]") LINE(">"), repm_fn, repm_fn, repm_fn, repm_fn); @@ -1099,7 +1099,7 @@ void test_valid() { textbuf.append(">\n"); for (int i = 0; i < total; i++) { indentbuf(&textbuf, total - i - 1); - textbuf.append("}\n"); + textbuf.append(" }\n"); indentbuf(&textbuf, total - i - 1); textbuf.append(">\n"); } diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 2641dda31c..18a76f580e 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -2034,7 +2034,7 @@ static void end_member(upb_json_parser *p) { p->top--; ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); UPB_ASSERT(ok); - upb_sink_endsubmsg(p->top->sink, sel); + upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel); } p->top->f = NULL; @@ -2148,7 +2148,7 @@ static void end_subobject(upb_json_parser *p) { p->top--; if (!is_unknown) { sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); - upb_sink_endsubmsg(p->top->sink, sel); + upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel); } } } diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 735bef18f8..ba2b770098 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -749,7 +749,8 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, CHECK_SUSPEND(upb_sink_startsubmsg(outer->sink, arg, &d->top->sink)); ) VMCASE(OP_ENDSUBMSG, - CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, arg)); + upb_sink subsink = (d->top + 1)->sink; + CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, subsink, arg)); ) VMCASE(OP_STARTSTR, uint32_t len = delim_remaining(d); diff --git a/upb/sink.h b/upb/sink.h index 47d218a9c1..871a8f57a7 100644 --- a/upb/sink.h +++ b/upb/sink.h @@ -185,15 +185,16 @@ UPB_INLINE bool upb_sink_startsubmsg(upb_sink s, upb_selector_t sel, return sub->closure ? true : false; } -UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_selector_t sel) { +UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_sink sub, + upb_selector_t sel) { typedef upb_endfield_handlerfunc func; func *endsubmsg; const void *hd; if (!s.handlers) return true; endsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd); - if (!endsubmsg) return s.closure; - return endsubmsg(s.closure, hd); + if (!endsubmsg) return true; + return endsubmsg(sub.closure, hd); } #ifdef __cplusplus @@ -359,8 +360,8 @@ class upb::Sink { return ret; } - bool EndSubMessage(HandlersPtr::Selector s) { - return upb_sink_endsubmsg(sink_, s); + bool EndSubMessage(HandlersPtr::Selector s, Sink sub) { + return upb_sink_endsubmsg(sink_, sub.sink_, s); } /* For repeated fields of any type, the sequence of values must be wrapped in