Merge pull request #221 from haberman/endsubmsg

Changed endsubmsg handler to return the closure of the submessage.
pull/13171/head
Joshua Haberman 5 years ago committed by GitHub
commit f32f2fdb25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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

@ -2022,7 +2022,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;
@ -2136,7 +2136,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);
}
}
}

@ -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");
}

@ -2020,7 +2020,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;
@ -2134,7 +2134,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);
}
}
}

@ -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);

@ -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

Loading…
Cancel
Save