From caa926feeb168f9cb04f4a774b7097d445d8f4e4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 May 2019 23:11:21 -0400 Subject: [PATCH] Started implementing and deduplicating the error handling in events.c. --- common/events.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/common/events.c b/common/events.c index 1dbdf135..6ba5548f 100644 --- a/common/events.c +++ b/common/events.c @@ -50,18 +50,27 @@ uiEvent *uiNewEvent(uiEventOptions *options) { } +#define checkEventNonnull(e, ...) if ((e) == NULL) { \ + uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEvent", __func__); \ + return __VA_ARGS__; \ +} +#define checkEventNotFiring(e, ...) if ((e)->firing) { \ + uiprivProgrammerError(uiprivProgrammerErrorChangingEventDuringFire, __func__); \ + return __VA_ARGS__; \ +} + int uiEventAddHandler(uiEvent *e, uiEventHandler handler, void *sender, void *data) { + checkEventNonnull(e, 0); + checkEventNotFiring(e, 0); } void uiEventDeleteHandler(uiEvent *e, int id) { struct handler *h; - if (e == NULL) - TODO - if (e->firing) - TODO + checkEventNonnull(e); + checkEventNotFiring(e); if (e->len == 0) TODO h = handlerFind(e->handlers, e->len, id); @@ -76,10 +85,11 @@ void uiEventFire(uiEvent *e, void *sender, void *args) struct handler *h; size_t i; - if (e == NULL) - TODO - if (e->firing) - TODO + checkEventNonnull(e); + if (e->firing) { + uiprivProgrammerError(uiprivProgrammerErrorRecursiveEventFire); + return; + } if (e->opts.Global && sender != NULL) TODO e->firing = true; @@ -94,8 +104,11 @@ void uiEventFire(uiEvent *e, void *sender, void *args) bool uiEventHandlerBlocked(const uiEvent *e, int id) { + checkEventNonnull(e, false); } void uiEventSetHandlerBlocked(uiEvent *e, int id, bool blocked) { + checkEventNonnull(e); + checkEventNotFiring(e); }