Added uiEventFree(). Now to add it to the tests and see what AddressSanitizer says afterward.
This commit is contained in:
parent
ece22bdddc
commit
9f2796ebac
|
@ -24,6 +24,7 @@ static int handlerCmp(const void *a, const void *b)
|
||||||
|
|
||||||
struct uiEvent {
|
struct uiEvent {
|
||||||
uiEventOptions opts;
|
uiEventOptions opts;
|
||||||
|
bool internal;
|
||||||
uiprivArray handlers;
|
uiprivArray handlers;
|
||||||
uiprivArray unusedIDs;
|
uiprivArray unusedIDs;
|
||||||
bool firing;
|
bool firing;
|
||||||
|
@ -59,6 +60,26 @@ uiEvent *uiNewEvent(const uiEventOptions *options)
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiFreeEvent(uiEvent *e)
|
||||||
|
{
|
||||||
|
if (!uiprivCheckInitializedAndThread())
|
||||||
|
return;
|
||||||
|
checkEventNonnull(e, /* nothing */);
|
||||||
|
if (e->internal) {
|
||||||
|
uiprivProgrammerErrorFreeingInternalEvent();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkEventNotFiring(e, /* nothing */);
|
||||||
|
if (e->handlers.len != 0) {
|
||||||
|
uiprivProgrammerErrorFreeingEventInUse();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uiprivArrayFree(e->unusedIDs);
|
||||||
|
uiprivArrayFree(e->handlers);
|
||||||
|
uiprivFree(e);
|
||||||
|
}
|
||||||
|
|
||||||
static bool checkEventSender(const uiEvent *e, void *sender, const char *func)
|
static bool checkEventSender(const uiEvent *e, void *sender, const char *func)
|
||||||
{
|
{
|
||||||
if (e->opts.Global && sender != NULL) {
|
if (e->opts.Global && sender != NULL) {
|
||||||
|
|
|
@ -36,3 +36,9 @@
|
||||||
|
|
||||||
#define uiprivProgrammerErrorRecursiveEventFire() \
|
#define uiprivProgrammerErrorRecursiveEventFire() \
|
||||||
uiprivProgrammerError("attempt to fire a uiEvent while it is already being fired")
|
uiprivProgrammerError("attempt to fire a uiEvent while it is already being fired")
|
||||||
|
|
||||||
|
#define uiprivProgrammerErrorFreeingInternalEvent() \
|
||||||
|
uiprivProgrammerError("attempt to free a libui-provided uiEvent")
|
||||||
|
|
||||||
|
#define uiprivProgrammerErrorFreeingEventInUse() \
|
||||||
|
uiprivProgrammerError("attempt to free a uiEvent that still has handlers registered")
|
||||||
|
|
|
@ -50,6 +50,16 @@ uiEvent *uiNewEvent(const uiEventOptions *options);
|
||||||
|
|
||||||
It is a programmer error to specify `NULL` for `options`.
|
It is a programmer error to specify `NULL` for `options`.
|
||||||
|
|
||||||
|
### `uiFreeEvent()`
|
||||||
|
|
||||||
|
```c
|
||||||
|
uiprivExtern void uiFreeEvent(uiEvent *e);
|
||||||
|
```
|
||||||
|
|
||||||
|
Frees the given event. The event must not be a libui-provided event, and must not have any handlers registered to it.
|
||||||
|
|
||||||
|
It is a programmer error to pass `NULL` for the given event, or to pass in an event that is currently firing.
|
||||||
|
|
||||||
### `uiEventAddHandler()`
|
### `uiEventAddHandler()`
|
||||||
|
|
||||||
```c
|
```c
|
||||||
|
|
2
ui.h
2
ui.h
|
@ -54,7 +54,7 @@ struct uiEventOptions {
|
||||||
};
|
};
|
||||||
|
|
||||||
uiprivExtern uiEvent *uiNewEvent(const uiEventOptions *options);
|
uiprivExtern uiEvent *uiNewEvent(const uiEventOptions *options);
|
||||||
// TODO uiFreeEvent()
|
uiprivExtern void uiFreeEvent(uiEvent *e);
|
||||||
uiprivExtern int uiEventAddHandler(uiEvent *e, uiEventHandler handler, void *sender, void *data);
|
uiprivExtern int uiEventAddHandler(uiEvent *e, uiEventHandler handler, void *sender, void *data);
|
||||||
uiprivExtern void uiEventDeleteHandler(uiEvent *e, int id);
|
uiprivExtern void uiEventDeleteHandler(uiEvent *e, int id);
|
||||||
uiprivExtern void uiEventFire(uiEvent *e, void *sender, void *args);
|
uiprivExtern void uiEventFire(uiEvent *e, void *sender, void *args);
|
||||||
|
|
Loading…
Reference in New Issue