From 101df7a46952de92062a106879829bea56bf413c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 14 May 2019 11:02:23 -0400 Subject: [PATCH] Added uiEvent-specific programmer errors. Next up: actually implementing uiEvent. --- common/errors.c | 6 +++++- common/uipriv.h | 3 ++- doc/events.md | 12 +++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/errors.c b/common/errors.c index 88f54dfb..f3fe1da1 100644 --- a/common/errors.c +++ b/common/errors.c @@ -24,11 +24,13 @@ void uiprivInternalError(const char *fmt, ...) uiprivReportError(internalErrorPrefix, buf, internalErrorSuffix, true); } -static const char *messages[] = { +static const char *messages[uiprivNumProgrammerErrors] = { [uiprivProgrammerErrorWrongStructSize] = "wrong size %zu for %s", [uiprivProgrammerErrorIndexOutOfRange] = "index %d out of range in %s()", [uiprivProgrammerErrorNullPointer] = "invalid null pointer for %s passed into %s()", [uiprivProgrammerErrorIntIDNotFound] = "%s identifier %d not found in %s()", + [uiprivProgrammerErrorChangingEventDuringFire] = "attempt to change a uiEvent with %s() while it is firing", + [uiprivProgrammerErrorRecursiveEventFire] = "attempt to fire a uiEvent while it is already being fired", }; static void prepareProgrammerError(char *buf, int size, unsigned int which, va_list ap) @@ -37,6 +39,8 @@ static void prepareProgrammerError(char *buf, int size, unsigned int which, va_l if (which >= uiprivNumProgrammerErrors) uiprivInternalError("bad programmer error value %u", which); + if (messages[which] == NULL) + uiprivInternalError("programmer error %u has no message", which); n = vsnprintf(buf, size, messages[which], ap); if (n < 0) uiprivInternalError("programmer error string for %u has encoding error", which); diff --git a/common/uipriv.h b/common/uipriv.h index 4090117f..839a9b9e 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -18,7 +18,8 @@ enum { uiprivProgrammerErrorNullPointer, // arguments: const char *paramDesc, __func__ uiprivProgrammerErrorIntIDNotFound, // arguments: const char *idDesc, int badID, __func__ // TODO type mismatch - // TODO attempt to change event during uiEventFire() + uiprivProgrammerErrorChangingEventDuringFire, // arguments: __func__ + uiprivProgrammerErrorRecursiveEventFire, // no arguments uiprivNumProgrammerErrors, }; extern void uiprivProgrammerError(unsigned int which, ...); diff --git a/doc/events.md b/doc/events.md index bfbb4587..6035278c 100644 --- a/doc/events.md +++ b/doc/events.md @@ -64,7 +64,7 @@ The return value is an identifier that may be used to delete or block the event. Note that event handlers are NOT deduplicated; if you call `uiEventAddHandler()` twice with the same `handler`, then `handler` will be registered twice and will thus be called twice, even if `sender` and/or `data` are the same, and `uiEventAddHandler()` will return two distinct identifiers. -It is a programmer error to specify `NULL` for `e` or `handler`. +It is a programmer error to specify `NULL` for `e` or `handler`. It is also a programmer error to call `uiEventAddHandler()` on an event while that event is being fired. ### `uiEventDeleteHandler()` @@ -72,7 +72,7 @@ It is a programmer error to specify `NULL` for `e` or `handler`. void uiEventDeleteHandler(uiEvent *e, int id); ``` -It is a programmer error to specify `NULL` for `e` or a currently unregistered value for `id`. +It is a programmer error to specify `NULL` for `e` or a currently unregistered value for `id`. It is also a programmer error to call `uiEventDeleteHandler()` on an event while that event is being fired. ### `uiEventFire()` @@ -88,12 +88,12 @@ Each handler that is to be called will receive whatever you pass in as `args` to Note that the order that handler functions are called in is unspecified. -It is a programmer error to specify `NULL` for `e`. +It is a programmer error to specify `NULL` for `e`. It is also a programmer error to fire an event again while it is already being fired. ### `uiEventHandlerBlocked()` ```c -bool uiEventHandlerBlocked(uiEvent *e, int id); +bool uiEventHandlerBlocked(const uiEvent *e, int id); ``` `uiEventHandlerBlocked()` returns whether or not the given registered event handler is *blocked*. A blocked event handler will not be called by `uiEventFire()`, even if that handler matches the parameters passed to `uiEventFire()`. `id` should be the identifier of a previously registered event handler as returned by `uiEventAddHandler()`. @@ -108,6 +108,4 @@ void uiEventSetHandlerBlocked(uiEvent *e, int id, bool blocked); `uiEventSetHandlerBlocked()` changes whether or not the given registered event handler is bocked. `id` should be the identifier of a previously registered event handler as returned by `uiEventAddHandler()`. -The effect of calling this function on a handler that matches a currently active `uiEventFire()` is unspecified. - -It is a programmer error to specify `NULL` for `e` or a currently unregistered event identifier for `id`. +It is a programmer error to specify `NULL` for `e` or a currently unregistered event identifier for `id`. It is also a programmer error to call `uiEventSetHandlerBlocked()` on an event while that event is being fired.