Changed endsubmsg handler to return the closure of the submessage.

This is a behavior change to help out PHP for the lazy wrappers
optimization.
pull/13171/head
Joshua Haberman 5 years ago
parent 56589c7276
commit 715718d5a5
  1. 4
      generated_for_cmake/upb/json/parser.c
  2. 24
      tests/pb/test_decoder.cc
  3. 4
      upb/json/parser.rl
  4. 3
      upb/pb/decoder.c
  5. 11
      upb/sink.h

@ -2036,7 +2036,7 @@ static void end_member(upb_json_parser *p) {
p->top--; p->top--;
ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel);
UPB_ASSERT(ok); 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; p->top->f = NULL;
@ -2150,7 +2150,7 @@ static void end_subobject(upb_json_parser *p) {
p->top--; p->top--;
if (!is_unknown) { if (!is_unknown) {
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); 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);
} }
} }
} }

@ -569,7 +569,7 @@ string wrap_text(int32_t fn, const string& text) {
LINE("<"), LINE("<"),
num2string(fn), LINE(":{") num2string(fn), LINE(":{")
" ", wrapped_text, " ", wrapped_text,
LINE("}") LINE(" }")
LINE(">")); LINE(">"));
return wrapped_text; return wrapped_text;
} }
@ -922,7 +922,7 @@ void test_valid() {
LINE("%u:{") LINE("%u:{")
LINE(" <") LINE(" <")
LINE(" >") LINE(" >")
LINE("}") LINE(" }")
LINE(">"), UPB_DESCRIPTOR_TYPE_MESSAGE); LINE(">"), UPB_DESCRIPTOR_TYPE_MESSAGE);
assert_successful_parse( assert_successful_parse(
@ -933,7 +933,7 @@ void test_valid() {
LINE("%u:{") LINE("%u:{")
LINE(" <") LINE(" <")
LINE(" >") LINE(" >")
LINE("}") LINE(" }")
LINE("%u:5") LINE("%u:5")
LINE(">"), UPB_DESCRIPTOR_TYPE_MESSAGE, UPB_DESCRIPTOR_TYPE_INT32); LINE(">"), UPB_DESCRIPTOR_TYPE_MESSAGE, UPB_DESCRIPTOR_TYPE_INT32);
@ -957,9 +957,9 @@ void test_valid() {
LINE(" <") LINE(" <")
LINE(" %u:2345678") LINE(" %u:2345678")
LINE(" >") LINE(" >")
LINE(" }") LINE(" }")
LINE(" >") LINE(" >")
LINE("}") LINE(" }")
LINE("%u:22222") LINE("%u:22222")
LINE(">"), msg_type, msg_type, int32_type, int32_type); LINE(">"), msg_type, msg_type, int32_type, int32_type);
@ -984,7 +984,7 @@ void test_valid() {
LINE(" %u:(5)\"abcde") LINE(" %u:(5)\"abcde")
LINE(" %u:\"") LINE(" %u:\"")
LINE(" >") LINE(" >")
LINE("}") LINE(" }")
LINE(">"), msg_fn, UPB_DESCRIPTOR_TYPE_STRING, LINE(">"), msg_fn, UPB_DESCRIPTOR_TYPE_STRING,
UPB_DESCRIPTOR_TYPE_STRING); UPB_DESCRIPTOR_TYPE_STRING);
@ -1014,11 +1014,11 @@ void test_valid() {
LINE(" %u:{") LINE(" %u:{")
LINE(" <") LINE(" <")
LINE(" >") LINE(" >")
LINE(" }") LINE(" }")
LINE(" >") LINE(" >")
LINE(" }") LINE(" }")
LINE(" >") LINE(" >")
LINE("}") LINE(" }")
LINE(">"), msg_fn, msg_fn, msg_fn); LINE(">"), msg_fn, msg_fn, msg_fn);
uint32_t repm_fn = rep_fn(UPB_DESCRIPTOR_TYPE_MESSAGE); uint32_t repm_fn = rep_fn(UPB_DESCRIPTOR_TYPE_MESSAGE);
@ -1032,10 +1032,10 @@ void test_valid() {
LINE(" %u:{") LINE(" %u:{")
LINE(" <") LINE(" <")
LINE(" >") LINE(" >")
LINE(" }") LINE(" }")
LINE(" ]") LINE(" ]")
LINE(" >") LINE(" >")
LINE(" }") LINE(" }")
LINE("]") LINE("]")
LINE(">"), repm_fn, repm_fn, repm_fn, repm_fn); LINE(">"), repm_fn, repm_fn, repm_fn, repm_fn);
@ -1099,7 +1099,7 @@ void test_valid() {
textbuf.append(">\n"); textbuf.append(">\n");
for (int i = 0; i < total; i++) { for (int i = 0; i < total; i++) {
indentbuf(&textbuf, total - i - 1); indentbuf(&textbuf, total - i - 1);
textbuf.append("}\n"); textbuf.append(" }\n");
indentbuf(&textbuf, total - i - 1); indentbuf(&textbuf, total - i - 1);
textbuf.append(">\n"); textbuf.append(">\n");
} }

@ -2034,7 +2034,7 @@ static void end_member(upb_json_parser *p) {
p->top--; p->top--;
ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel);
UPB_ASSERT(ok); 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; p->top->f = NULL;
@ -2148,7 +2148,7 @@ static void end_subobject(upb_json_parser *p) {
p->top--; p->top--;
if (!is_unknown) { if (!is_unknown) {
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); 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);
} }
} }
} }

@ -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)); CHECK_SUSPEND(upb_sink_startsubmsg(outer->sink, arg, &d->top->sink));
) )
VMCASE(OP_ENDSUBMSG, 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, VMCASE(OP_STARTSTR,
uint32_t len = delim_remaining(d); uint32_t len = delim_remaining(d);

@ -185,15 +185,16 @@ UPB_INLINE bool upb_sink_startsubmsg(upb_sink s, upb_selector_t sel,
return sub->closure ? true : false; 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; typedef upb_endfield_handlerfunc func;
func *endsubmsg; func *endsubmsg;
const void *hd; const void *hd;
if (!s.handlers) return true; if (!s.handlers) return true;
endsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd); endsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
if (!endsubmsg) return s.closure; if (!endsubmsg) return true;
return endsubmsg(s.closure, hd); return endsubmsg(sub.closure, hd);
} }
#ifdef __cplusplus #ifdef __cplusplus
@ -359,8 +360,8 @@ class upb::Sink {
return ret; return ret;
} }
bool EndSubMessage(HandlersPtr::Selector s) { bool EndSubMessage(HandlersPtr::Selector s, Sink sub) {
return upb_sink_endsubmsg(sink_, s); return upb_sink_endsubmsg(sink_, sub.sink_, s);
} }
/* For repeated fields of any type, the sequence of values must be wrapped in /* For repeated fields of any type, the sequence of values must be wrapped in

Loading…
Cancel
Save