All tests pass again!

pull/13171/head
Joshua Haberman 6 years ago
parent cb26d883d1
commit 754b9f1cfd
  1. 2
      tests/json/test_json.cc
  2. 12
      tests/pb/test_decoder.cc
  3. 2
      tests/pb/test_encoder.cc
  4. 27
      tests/test_util.h
  5. 114
      upb/json/parser.c
  6. 9
      upb/json/parser.h
  7. 8
      upb/json/parser.rl
  8. 4
      upb/pb/decoder.c
  9. 8
      upb/pb/decoder.h

@ -176,7 +176,7 @@ void test_json_roundtrip_message(const char* json_src,
upb::json::PrinterPtr printer = upb::json::PrinterPtr::Create( upb::json::PrinterPtr printer = upb::json::PrinterPtr::Create(
env.arena(), serialize_handlers, data_sink.Sink()); env.arena(), serialize_handlers, data_sink.Sink());
upb::json::ParserPtr parser = upb::json::ParserPtr::Create( upb::json::ParserPtr parser = upb::json::ParserPtr::Create(
env.arena(), parser_method, NULL, printer.input(), false); env.arena(), parser_method, NULL, printer.input(), env.status(), false);
env.ResetBytesSink(parser.input()); env.ResetBytesSink(parser.input());
env.Reset(json_src, strlen(json_src), false, false); env.Reset(json_src, strlen(json_src), false, false);

@ -454,8 +454,9 @@ upb::pb::DecoderMethodPtr global_method;
upb::pb::DecoderPtr CreateDecoder(upb::Arena* arena, upb::pb::DecoderPtr CreateDecoder(upb::Arena* arena,
upb::pb::DecoderMethodPtr method, upb::pb::DecoderMethodPtr method,
upb::Sink sink) { upb::Sink sink, upb::Status* status) {
upb::pb::DecoderPtr ret = upb::pb::DecoderPtr::Create(arena, method, sink); upb::pb::DecoderPtr ret =
upb::pb::DecoderPtr::Create(arena, method, sink, status);
ret.set_max_nesting(MAX_NESTING); ret.set_max_nesting(MAX_NESTING);
return ret; return ret;
} }
@ -556,7 +557,7 @@ void do_run_decoder(VerboseParserEnvironment* env, upb::pb::DecoderPtr decoder,
void run_decoder(const string& proto, const string* expected_output) { void run_decoder(const string& proto, const string* expected_output) {
VerboseParserEnvironment env(filter_hash != 0); VerboseParserEnvironment env(filter_hash != 0);
upb::Sink sink(global_handlers, &closures[0]); upb::Sink sink(global_handlers, &closures[0]);
upb::pb::DecoderPtr decoder = CreateDecoder(env.arena(), global_method, sink); upb::pb::DecoderPtr decoder = CreateDecoder(env.arena(), global_method, sink, env.status());
env.ResetBytesSink(decoder.input()); env.ResetBytesSink(decoder.input());
for (size_t i = 0; i < proto.size(); i++) { for (size_t i = 0; i < proto.size(); i++) {
for (size_t j = i; j < UPB_MIN(proto.size(), i + 5); j++) { for (size_t j = i; j < UPB_MIN(proto.size(), i + 5); j++) {
@ -874,7 +875,8 @@ void test_valid() {
upb::Status status; upb::Status status;
upb::Arena arena; upb::Arena arena;
upb::Sink sink(global_handlers, &closures[0]); upb::Sink sink(global_handlers, &closures[0]);
upb::pb::DecoderPtr decoder = CreateDecoder(&arena, global_method, sink); upb::pb::DecoderPtr decoder =
CreateDecoder(&arena, global_method, sink, &status);
output.clear(); output.clear();
bool ok = upb::PutBuffer(std::string(), decoder.input()); bool ok = upb::PutBuffer(std::string(), decoder.input());
ASSERT(ok); ASSERT(ok);
@ -1161,7 +1163,7 @@ void test_emptyhandlers(upb::SymbolTable* symtab, bool allowjit) {
VerboseParserEnvironment env(filter_hash != 0); VerboseParserEnvironment env(filter_hash != 0);
upb::Sink sink(global_method.dest_handlers(), &closures[0]); upb::Sink sink(global_method.dest_handlers(), &closures[0]);
upb::pb::DecoderPtr decoder = upb::pb::DecoderPtr decoder =
CreateDecoder(env.arena(), global_method, sink); CreateDecoder(env.arena(), global_method, sink, env.status());
env.ResetBytesSink(decoder.input()); env.ResetBytesSink(decoder.input());
env.Reset(testdata[i].data, testdata[i].length, true, false); env.Reset(testdata[i].data, testdata[i].length, true, false);
ASSERT(env.Start()); ASSERT(env.Start());

@ -48,7 +48,7 @@ void test_pb_roundtrip() {
upb::pb::EncoderPtr encoder = upb::pb::EncoderPtr encoder =
upb::pb::EncoderPtr::Create(&arena, encoder_handlers, string_sink.input()); upb::pb::EncoderPtr::Create(&arena, encoder_handlers, string_sink.input());
upb::pb::DecoderPtr decoder = upb::pb::DecoderPtr decoder =
upb::pb::DecoderPtr::Create(&arena, method, encoder.input()); upb::pb::DecoderPtr::Create(&arena, method, encoder.input(), &status);
ok = upb::PutBuffer(input, decoder.input()); ok = upb::PutBuffer(input, decoder.input());
ASSERT(ok); ASSERT(ok);
ASSERT(input == output); ASSERT(input == output);

@ -32,21 +32,6 @@ class VerboseParserEnvironment {
/* Pass verbose=true to print detailed diagnostics to stderr. */ /* Pass verbose=true to print detailed diagnostics to stderr. */
VerboseParserEnvironment(bool verbose) : verbose_(verbose) {} VerboseParserEnvironment(bool verbose) : verbose_(verbose) {}
static bool OnError(void *ud, const upb::Status* status) {
VerboseParserEnvironment* env = static_cast<VerboseParserEnvironment*>(ud);
if (env->expect_error_ && env->verbose_) {
fprintf(stderr, "Encountered error, as expected: ");
} else if (!env->expect_error_) {
fprintf(stderr, "Encountered unexpected error: ");
} else {
return false;
}
fprintf(stderr, "%s\n", status->error_message());
return false;
}
void Reset(const char *buf, size_t len, bool may_skip, bool expect_error) { void Reset(const char *buf, size_t len, bool may_skip, bool expect_error) {
buf_ = buf; buf_ = buf;
len_ = len; len_ = len;
@ -99,6 +84,17 @@ class VerboseParserEnvironment {
return false; return false;
} }
if (!status_.ok()) {
if (expect_error_ && verbose_) {
fprintf(stderr, "Encountered error, as expected: %s",
status_.error_message());
} else if (!expect_error_) {
fprintf(stderr, "Encountered unexpected error: %s",
status_.error_message());
return false;
}
}
return true; return true;
} }
@ -175,6 +171,7 @@ class VerboseParserEnvironment {
bool SkippedWithNull() { return skipped_with_null_; } bool SkippedWithNull() { return skipped_with_null_; }
upb::Arena* arena() { return &arena_; } upb::Arena* arena() { return &arena_; }
upb::Status* status() { return &status_; }
private: private:
upb::Arena arena_; upb::Arena arena_;

@ -306,8 +306,9 @@ static void json_parser_any_frame_set_payload_type(
/* Initialize parser. */ /* Initialize parser. */
parser_method = upb_json_codecache_get(frame->parser_codecache, payload_type); parser_method = upb_json_codecache_get(frame->parser_codecache, payload_type);
upb_sink_reset(&frame->sink, h, encoder); upb_sink_reset(&frame->sink, h, encoder);
frame->parser = upb_json_parser_create(p->arena, parser_method, p->symtab, frame->parser =
frame->sink, p->ignore_json_unknown); upb_json_parser_create(p->arena, parser_method, p->symtab, frame->sink,
p->status, p->ignore_json_unknown);
} }
static void json_parser_any_frame_free(upb_jsonparser_any_frame *frame) { static void json_parser_any_frame_free(upb_jsonparser_any_frame *frame) {
@ -2379,11 +2380,11 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */ * final state once, when the closing '"' is seen. */
#line 2541 "upb/json/parser.rl" #line 2542 "upb/json/parser.rl"
#line 2387 "upb/json/parser.c" #line 2388 "upb/json/parser.c"
static const char _json_actions[] = { static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1, 0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1, 4, 1, 6, 1, 7, 1, 8, 1,
@ -2630,7 +2631,7 @@ static const int json_en_value_machine = 75;
static const int json_en_main = 1; static const int json_en_main = 1;
#line 2544 "upb/json/parser.rl" #line 2545 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size, size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) { const upb_bufhandle *handle) {
@ -2653,7 +2654,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume(parser, buf); capture_resume(parser, buf);
#line 2657 "upb/json/parser.c" #line 2658 "upb/json/parser.c"
{ {
int _klen; int _klen;
unsigned int _trans; unsigned int _trans;
@ -2728,83 +2729,83 @@ _match:
switch ( *_acts++ ) switch ( *_acts++ )
{ {
case 1: case 1:
#line 2392 "upb/json/parser.rl" #line 2393 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 2: case 2:
#line 2394 "upb/json/parser.rl" #line 2395 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 23;goto _again;} } { p--; {stack[top++] = cs; cs = 23;goto _again;} }
break; break;
case 3: case 3:
#line 2398 "upb/json/parser.rl" #line 2399 "upb/json/parser.rl"
{ start_text(parser, p); } { start_text(parser, p); }
break; break;
case 4: case 4:
#line 2399 "upb/json/parser.rl" #line 2400 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); } { CHECK_RETURN_TOP(end_text(parser, p)); }
break; break;
case 5: case 5:
#line 2405 "upb/json/parser.rl" #line 2406 "upb/json/parser.rl"
{ start_hex(parser); } { start_hex(parser); }
break; break;
case 6: case 6:
#line 2406 "upb/json/parser.rl" #line 2407 "upb/json/parser.rl"
{ hexdigit(parser, p); } { hexdigit(parser, p); }
break; break;
case 7: case 7:
#line 2407 "upb/json/parser.rl" #line 2408 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); } { CHECK_RETURN_TOP(end_hex(parser)); }
break; break;
case 8: case 8:
#line 2413 "upb/json/parser.rl" #line 2414 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); } { CHECK_RETURN_TOP(escape(parser, p)); }
break; break;
case 9: case 9:
#line 2419 "upb/json/parser.rl" #line 2420 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 10: case 10:
#line 2431 "upb/json/parser.rl" #line 2432 "upb/json/parser.rl"
{ start_duration_base(parser, p); } { start_duration_base(parser, p); }
break; break;
case 11: case 11:
#line 2432 "upb/json/parser.rl" #line 2433 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_duration_base(parser, p)); } { CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break; break;
case 12: case 12:
#line 2434 "upb/json/parser.rl" #line 2435 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 13: case 13:
#line 2439 "upb/json/parser.rl" #line 2440 "upb/json/parser.rl"
{ start_timestamp_base(parser, p); } { start_timestamp_base(parser, p); }
break; break;
case 14: case 14:
#line 2440 "upb/json/parser.rl" #line 2441 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); }
break; break;
case 15: case 15:
#line 2442 "upb/json/parser.rl" #line 2443 "upb/json/parser.rl"
{ start_timestamp_fraction(parser, p); } { start_timestamp_fraction(parser, p); }
break; break;
case 16: case 16:
#line 2443 "upb/json/parser.rl" #line 2444 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break; break;
case 17: case 17:
#line 2445 "upb/json/parser.rl" #line 2446 "upb/json/parser.rl"
{ start_timestamp_zone(parser, p); } { start_timestamp_zone(parser, p); }
break; break;
case 18: case 18:
#line 2446 "upb/json/parser.rl" #line 2447 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break; break;
case 19: case 19:
#line 2448 "upb/json/parser.rl" #line 2449 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
case 20: case 20:
#line 2453 "upb/json/parser.rl" #line 2454 "upb/json/parser.rl"
{ {
if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
{stack[top++] = cs; cs = 47;goto _again;} {stack[top++] = cs; cs = 47;goto _again;}
@ -2816,11 +2817,11 @@ _match:
} }
break; break;
case 21: case 21:
#line 2464 "upb/json/parser.rl" #line 2465 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 75;goto _again;} } { p--; {stack[top++] = cs; cs = 75;goto _again;} }
break; break;
case 22: case 22:
#line 2469 "upb/json/parser.rl" #line 2470 "upb/json/parser.rl"
{ {
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_member(parser, p); start_any_member(parser, p);
@ -2830,11 +2831,11 @@ _match:
} }
break; break;
case 23: case 23:
#line 2476 "upb/json/parser.rl" #line 2477 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_membername(parser)); } { CHECK_RETURN_TOP(end_membername(parser)); }
break; break;
case 24: case 24:
#line 2479 "upb/json/parser.rl" #line 2480 "upb/json/parser.rl"
{ {
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
end_any_member(parser, p); end_any_member(parser, p);
@ -2844,7 +2845,7 @@ _match:
} }
break; break;
case 25: case 25:
#line 2490 "upb/json/parser.rl" #line 2491 "upb/json/parser.rl"
{ {
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_object(parser, p); start_any_object(parser, p);
@ -2854,7 +2855,7 @@ _match:
} }
break; break;
case 26: case 26:
#line 2499 "upb/json/parser.rl" #line 2500 "upb/json/parser.rl"
{ {
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) { if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
CHECK_RETURN_TOP(end_any_object(parser, p)); CHECK_RETURN_TOP(end_any_object(parser, p));
@ -2864,54 +2865,54 @@ _match:
} }
break; break;
case 27: case 27:
#line 2511 "upb/json/parser.rl" #line 2512 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); } { CHECK_RETURN_TOP(start_array(parser)); }
break; break;
case 28: case 28:
#line 2515 "upb/json/parser.rl" #line 2516 "upb/json/parser.rl"
{ end_array(parser); } { end_array(parser); }
break; break;
case 29: case 29:
#line 2520 "upb/json/parser.rl" #line 2521 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_number(parser, p)); } { CHECK_RETURN_TOP(start_number(parser, p)); }
break; break;
case 30: case 30:
#line 2521 "upb/json/parser.rl" #line 2522 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); } { CHECK_RETURN_TOP(end_number(parser, p)); }
break; break;
case 31: case 31:
#line 2523 "upb/json/parser.rl" #line 2524 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); } { CHECK_RETURN_TOP(start_stringval(parser)); }
break; break;
case 32: case 32:
#line 2524 "upb/json/parser.rl" #line 2525 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_stringval(parser)); } { CHECK_RETURN_TOP(end_stringval(parser)); }
break; break;
case 33: case 33:
#line 2526 "upb/json/parser.rl" #line 2527 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); } { CHECK_RETURN_TOP(end_bool(parser, true)); }
break; break;
case 34: case 34:
#line 2528 "upb/json/parser.rl" #line 2529 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); } { CHECK_RETURN_TOP(end_bool(parser, false)); }
break; break;
case 35: case 35:
#line 2530 "upb/json/parser.rl" #line 2531 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); } { CHECK_RETURN_TOP(end_null(parser)); }
break; break;
case 36: case 36:
#line 2532 "upb/json/parser.rl" #line 2533 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject_full(parser)); } { CHECK_RETURN_TOP(start_subobject_full(parser)); }
break; break;
case 37: case 37:
#line 2533 "upb/json/parser.rl" #line 2534 "upb/json/parser.rl"
{ end_subobject_full(parser); } { end_subobject_full(parser); }
break; break;
case 38: case 38:
#line 2538 "upb/json/parser.rl" #line 2539 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} } { p--; {cs = stack[--top]; goto _again;} }
break; break;
#line 2915 "upb/json/parser.c" #line 2916 "upb/json/parser.c"
} }
} }
@ -2928,32 +2929,32 @@ _again:
while ( __nacts-- > 0 ) { while ( __nacts-- > 0 ) {
switch ( *__acts++ ) { switch ( *__acts++ ) {
case 0: case 0:
#line 2390 "upb/json/parser.rl" #line 2391 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; if ( p == pe ) { p--; {cs = stack[--top]; if ( p == pe )
goto _test_eof; goto _test_eof;
goto _again;} } goto _again;} }
break; break;
case 30: case 30:
#line 2521 "upb/json/parser.rl" #line 2522 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); } { CHECK_RETURN_TOP(end_number(parser, p)); }
break; break;
case 33: case 33:
#line 2526 "upb/json/parser.rl" #line 2527 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); } { CHECK_RETURN_TOP(end_bool(parser, true)); }
break; break;
case 34: case 34:
#line 2528 "upb/json/parser.rl" #line 2529 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); } { CHECK_RETURN_TOP(end_bool(parser, false)); }
break; break;
case 35: case 35:
#line 2530 "upb/json/parser.rl" #line 2531 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); } { CHECK_RETURN_TOP(end_null(parser)); }
break; break;
case 37: case 37:
#line 2533 "upb/json/parser.rl" #line 2534 "upb/json/parser.rl"
{ end_subobject_full(parser); } { end_subobject_full(parser); }
break; break;
#line 2957 "upb/json/parser.c" #line 2958 "upb/json/parser.c"
} }
} }
} }
@ -2961,7 +2962,7 @@ goto _again;} }
_out: {} _out: {}
} }
#line 2566 "upb/json/parser.rl" #line 2567 "upb/json/parser.rl"
if (p != pe) { if (p != pe) {
upb_status_seterrf(parser->status, "Parse error at '%.*s'\n", pe - p, p); upb_status_seterrf(parser->status, "Parse error at '%.*s'\n", pe - p, p);
@ -3008,13 +3009,13 @@ static void json_parser_reset(upb_json_parser *p) {
/* Emit Ragel initialization of the parser. */ /* Emit Ragel initialization of the parser. */
#line 3012 "upb/json/parser.c" #line 3013 "upb/json/parser.c"
{ {
cs = json_start; cs = json_start;
top = 0; top = 0;
} }
#line 2612 "upb/json/parser.rl" #line 2613 "upb/json/parser.rl"
p->current_state = cs; p->current_state = cs;
p->parser_top = top; p->parser_top = top;
accumulate_clear(p); accumulate_clear(p);
@ -3071,6 +3072,7 @@ upb_json_parser *upb_json_parser_create(upb_arena *arena,
const upb_json_parsermethod *method, const upb_json_parsermethod *method,
const upb_symtab* symtab, const upb_symtab* symtab,
upb_sink output, upb_sink output,
upb_status *status,
bool ignore_json_unknown) { bool ignore_json_unknown) {
#ifndef NDEBUG #ifndef NDEBUG
const size_t size_before = upb_arena_bytesallocated(arena); const size_t size_before = upb_arena_bytesallocated(arena);
@ -3080,7 +3082,7 @@ upb_json_parser *upb_json_parser_create(upb_arena *arena,
p->arena = arena; p->arena = arena;
p->method = method; p->method = method;
p->status = NULL; p->status = status;
p->limit = p->stack + UPB_JSON_MAX_DEPTH; p->limit = p->stack + UPB_JSON_MAX_DEPTH;
p->accumulate_buf = NULL; p->accumulate_buf = NULL;
p->accumulate_buf_size = 0; p->accumulate_buf_size = 0;

@ -71,6 +71,7 @@ upb_json_parser* upb_json_parser_create(upb_arena* a,
const upb_json_parsermethod* m, const upb_json_parsermethod* m,
const upb_symtab* symtab, const upb_symtab* symtab,
upb_sink output, upb_sink output,
upb_status *status,
bool ignore_json_unknown); bool ignore_json_unknown);
upb_bytessink upb_json_parser_input(upb_json_parser* p); upb_bytessink upb_json_parser_input(upb_json_parser* p);
@ -84,12 +85,12 @@ class upb::json::ParserPtr {
ParserPtr(upb_json_parser* ptr) : ptr_(ptr) {} ParserPtr(upb_json_parser* ptr) : ptr_(ptr) {}
static ParserPtr Create(Arena* arena, ParserMethodPtr method, static ParserPtr Create(Arena* arena, ParserMethodPtr method,
SymbolTable* symtab, Sink output, SymbolTable* symtab, Sink output, Status* status,
bool ignore_json_unknown) { bool ignore_json_unknown) {
upb_symtab* symtab_ptr = symtab ? symtab->ptr() : nullptr; upb_symtab* symtab_ptr = symtab ? symtab->ptr() : nullptr;
return ParserPtr(upb_json_parser_create(arena->ptr(), method.ptr(), return ParserPtr(upb_json_parser_create(
symtab_ptr, output.sink(), arena->ptr(), method.ptr(), symtab_ptr, output.sink(), status->ptr(),
ignore_json_unknown)); ignore_json_unknown));
} }
BytesSink input() { return upb_json_parser_input(ptr_); } BytesSink input() { return upb_json_parser_input(ptr_); }

@ -304,8 +304,9 @@ static void json_parser_any_frame_set_payload_type(
/* Initialize parser. */ /* Initialize parser. */
parser_method = upb_json_codecache_get(frame->parser_codecache, payload_type); parser_method = upb_json_codecache_get(frame->parser_codecache, payload_type);
upb_sink_reset(&frame->sink, h, encoder); upb_sink_reset(&frame->sink, h, encoder);
frame->parser = upb_json_parser_create(p->arena, parser_method, p->symtab, frame->parser =
frame->sink, p->ignore_json_unknown); upb_json_parser_create(p->arena, parser_method, p->symtab, frame->sink,
p->status, p->ignore_json_unknown);
} }
static void json_parser_any_frame_free(upb_jsonparser_any_frame *frame) { static void json_parser_any_frame_free(upb_jsonparser_any_frame *frame) {
@ -2665,6 +2666,7 @@ upb_json_parser *upb_json_parser_create(upb_arena *arena,
const upb_json_parsermethod *method, const upb_json_parsermethod *method,
const upb_symtab* symtab, const upb_symtab* symtab,
upb_sink output, upb_sink output,
upb_status *status,
bool ignore_json_unknown) { bool ignore_json_unknown) {
#ifndef NDEBUG #ifndef NDEBUG
const size_t size_before = upb_arena_bytesallocated(arena); const size_t size_before = upb_arena_bytesallocated(arena);
@ -2674,7 +2676,7 @@ upb_json_parser *upb_json_parser_create(upb_arena *arena,
p->arena = arena; p->arena = arena;
p->method = method; p->method = method;
p->status = NULL; p->status = status;
p->limit = p->stack + UPB_JSON_MAX_DEPTH; p->limit = p->stack + UPB_JSON_MAX_DEPTH;
p->accumulate_buf = NULL; p->accumulate_buf = NULL;
p->accumulate_buf_size = 0; p->accumulate_buf_size = 0;

@ -991,7 +991,7 @@ void upb_pbdecoder_reset(upb_pbdecoder *d) {
} }
upb_pbdecoder *upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m, upb_pbdecoder *upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m,
upb_sink sink) { upb_sink sink, upb_status *status) {
const size_t default_max_nesting = 64; const size_t default_max_nesting = 64;
#ifndef NDEBUG #ifndef NDEBUG
size_t size_before = upb_arena_bytesallocated(a); size_t size_before = upb_arena_bytesallocated(a);
@ -1010,7 +1010,7 @@ upb_pbdecoder *upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m,
d->arena = a; d->arena = a;
d->limit = d->stack + default_max_nesting - 1; d->limit = d->stack + default_max_nesting - 1;
d->stack_size = default_max_nesting; d->stack_size = default_max_nesting;
d->status = NULL; d->status = status;
upb_pbdecoder_reset(d); upb_pbdecoder_reset(d);
upb_bytessink_reset(&d->input_, &m->input_handler_, d); upb_bytessink_reset(&d->input_, &m->input_handler_, d);

@ -102,7 +102,7 @@ extern "C" {
upb_pbdecoder *upb_pbdecoder_create(upb_arena *arena, upb_pbdecoder *upb_pbdecoder_create(upb_arena *arena,
const upb_pbdecodermethod *method, const upb_pbdecodermethod *method,
upb_sink output); upb_sink output, upb_status *status);
const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d); const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d);
upb_bytessink upb_pbdecoder_input(upb_pbdecoder *d); upb_bytessink upb_pbdecoder_input(upb_pbdecoder *d);
uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d); uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d);
@ -127,9 +127,9 @@ class upb::pb::DecoderPtr {
* *
* The sink must match the given method. */ * The sink must match the given method. */
static DecoderPtr Create(Arena *arena, DecoderMethodPtr method, static DecoderPtr Create(Arena *arena, DecoderMethodPtr method,
upb::Sink output) { upb::Sink output, Status *status) {
return DecoderPtr( return DecoderPtr(upb_pbdecoder_create(arena->ptr(), method.ptr(),
upb_pbdecoder_create(arena->ptr(), method.ptr(), output.sink())); output.sink(), status->ptr()));
} }
/* Returns the DecoderMethod this decoder is parsing from. */ /* Returns the DecoderMethod this decoder is parsing from. */

Loading…
Cancel
Save