Added uiprivAlloc() and friends and implemented uiNewEvent().
This commit is contained in:
parent
bd84da7179
commit
96c346c2dd
|
@ -0,0 +1,31 @@
|
|||
// 16 may 2019
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ui.h"
|
||||
#include "uipriv.h"
|
||||
|
||||
void *uiprivAlloc(size_t n, const char *what)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc(n);
|
||||
if (p == NULL)
|
||||
uiprivInternalError("memory exhausted allocating %s", what);
|
||||
memset(p, 0, n);
|
||||
return p;
|
||||
}
|
||||
|
||||
void *uiprivRealloc(void *p, size_t old, size_t new, const char *what)
|
||||
{
|
||||
p = realloc(p, new);
|
||||
if (p == NULL)
|
||||
uiprivInternalError("memory exhausted reallocating %s", what);
|
||||
if (new > old)
|
||||
memset(((uint8_t *) p) + old, 0, new - old);
|
||||
return p;
|
||||
}
|
||||
|
||||
void uiprivFree(void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
// 15 may 2019
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ui.h"
|
||||
#include "uipriv.h"
|
||||
|
||||
struct handler {
|
||||
int id;
|
||||
uiHandlerFunc f;
|
||||
uiEventHandler f;
|
||||
void *sender;
|
||||
void *data;
|
||||
bool blocked;
|
||||
|
@ -39,10 +40,19 @@ struct uiEvent {
|
|||
|
||||
uiEvent *uiNewEvent(const uiEventOptions *options)
|
||||
{
|
||||
uiEvent *e;
|
||||
|
||||
if (options == NULL) {
|
||||
uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEventOptions", __func__);
|
||||
return NULL;
|
||||
}
|
||||
if (options->Size != sizeof (uiEventOptions)) {
|
||||
uiprivProgrammerError(uiprivProgrammerErrorWrongStructSize, options->Size, "uiEventOptions");
|
||||
return NULL;
|
||||
}
|
||||
e = (uiEvent *) uiprivAlloc(sizeof (uiEvent), "uiEvent");
|
||||
e->opts = *options;
|
||||
return e;
|
||||
}
|
||||
|
||||
#define checkEventNonnull(e, ...) if ((e) == NULL) { \
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# 23 march 2019
|
||||
|
||||
libui_sources += [
|
||||
'common/alloc.c',
|
||||
'common/errors.c',
|
||||
'common/events.c',
|
||||
'common/init.c',
|
||||
|
|
|
@ -10,6 +10,11 @@ extern int uiprivSysInit(void *options, uiInitError *err);
|
|||
extern int uiprivInitReturnError(uiInitError *err, const char *msg);
|
||||
extern int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
|
||||
|
||||
// alloc.c
|
||||
extern void *uiprivAlloc(size_t n, const char *what);
|
||||
extern void *uiprivRealloc(void *p, size_t old, size_t new, const char *what);
|
||||
extern void uiprivFree(void *p);
|
||||
|
||||
// errors.c
|
||||
extern void uiprivInternalError(const char *fmt, ...);
|
||||
enum {
|
||||
|
|
Loading…
Reference in New Issue