From d619852e06983dc30d2070f6c4af32d563b101f2 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 19 May 2011 10:56:34 -0700 Subject: Change dispatcher error handling model. Now the dispatcher will call error handlers instaed of returning statuses that the caller has to constantly check. --- src/upb_msg.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/upb_msg.c') diff --git a/src/upb_msg.c b/src/upb_msg.c index 1115673..dd00610 100644 --- a/src/upb_msg.c +++ b/src/upb_msg.c @@ -208,25 +208,13 @@ static upb_flow_t upb_msg_dispatch(upb_msg *msg, upb_msgdef *md, static upb_flow_t upb_msg_pushval(upb_value val, upb_fielddef *f, upb_dispatcher *d, upb_fhandlers *hf) { -#define CHECK_FLOW(x) do { \ - upb_flow_t flow = x; if (flow != UPB_CONTINUE) return flow; \ - } while(0) - -// For when a SKIP can be implemented just through an early return. -#define CHECK_FLOW_LOCAL(x) do { \ - upb_flow_t flow = x; \ - if (flow != UPB_CONTINUE) { \ - if (flow == UPB_SKIPSUBMSG) flow = UPB_CONTINUE; \ - return flow; \ - } \ -} while (0) if (upb_issubmsg(f)) { upb_msg *msg = upb_value_getmsg(val); - CHECK_FLOW_LOCAL(upb_dispatch_startsubmsg(d, hf, 0)); - CHECK_FLOW_LOCAL(upb_msg_dispatch(msg, upb_downcast_msgdef(f->def), d)); - CHECK_FLOW(upb_dispatch_endsubmsg(d)); + upb_dispatch_startsubmsg(d, hf); + upb_msg_dispatch(msg, upb_downcast_msgdef(f->def), d); + upb_dispatch_endsubmsg(d); } else { - CHECK_FLOW(upb_dispatch_value(d, hf, val)); + upb_dispatch_value(d, hf, val); } return UPB_CONTINUE; } @@ -243,22 +231,20 @@ static upb_flow_t upb_msg_dispatch(upb_msg *msg, upb_msgdef *md, if (upb_isarray(f)) { upb_array *arr = upb_value_getarr(val); for (uint32_t j = 0; j < upb_array_len(arr); ++j) { - CHECK_FLOW_LOCAL(upb_msg_pushval(upb_array_get(arr, f, j), f, d, hf)); + upb_msg_pushval(upb_array_get(arr, f, j), f, d, hf); } } else { - CHECK_FLOW_LOCAL(upb_msg_pushval(val, f, d, hf)); + upb_msg_pushval(val, f, d, hf); } } return UPB_CONTINUE; -#undef CHECK_FLOW -#undef CHECK_FLOW_LOCAL } void upb_msg_runhandlers(upb_msg *msg, upb_msgdef *md, upb_handlers *h, void *closure, upb_status *status) { upb_dispatcher d; - upb_dispatcher_init(&d, h); - upb_dispatcher_reset(&d, closure, 0); + upb_dispatcher_init(&d, h, NULL, NULL, NULL); + upb_dispatcher_reset(&d, closure); upb_dispatch_startmsg(&d); upb_msg_dispatch(msg, md, &d); -- cgit v1.2.3