Changed uiInit() to return bool instead of int, now that we've settled on using bool.
This commit is contained in:
parent
edfd5e9157
commit
19ad0d33a3
|
@ -9,7 +9,7 @@
|
|||
#include "ui.h"
|
||||
#include "uipriv.h"
|
||||
|
||||
static int initialized = 0;
|
||||
static bool initialized = false;
|
||||
|
||||
#define errAlreadyInitialized "libui already initialized"
|
||||
#define errOptionsMustBeNULL "options parameter to uiInit() must be NULL"
|
||||
|
@ -20,33 +20,33 @@ static const char *commonInitErrors[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
static int checkInitErrorLengths(uiInitError *err, const char **initErrors)
|
||||
static bool checkInitErrorLengths(uiInitError *err, const char **initErrors)
|
||||
{
|
||||
const char **p;
|
||||
|
||||
if (initErrors == NULL)
|
||||
return 1;
|
||||
return true;
|
||||
for (p = initErrors; *p != NULL; p++)
|
||||
if (strlen(*p) > 255) {
|
||||
strcpy(err->Message, "[INTERNAL] uiInit() error too long: ");
|
||||
strncat(err->Message, *p, 32);
|
||||
strcat(err->Message, "...");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int uiInit(void *options, uiInitError *err)
|
||||
bool uiInit(void *options, uiInitError *err)
|
||||
{
|
||||
if (err == NULL)
|
||||
return 0;
|
||||
return false;
|
||||
if (err->Size != sizeof (uiInitError))
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
if (!checkInitErrorLengths(err, commonInitErrors))
|
||||
return 0;
|
||||
return false;
|
||||
if (!checkInitErrorLengths(err, uiprivSysInitErrors()))
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
if (initialized)
|
||||
return uiprivInitReturnError(err, errAlreadyInitialized);
|
||||
|
@ -55,19 +55,19 @@ int uiInit(void *options, uiInitError *err)
|
|||
return uiprivInitReturnError(err, errOptionsMustBeNULL);
|
||||
|
||||
if (!uiprivSysInit(options, err))
|
||||
return 0;
|
||||
initialized = 1;
|
||||
return 1;
|
||||
return false;
|
||||
initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int uiprivInitReturnError(uiInitError *err, const char *msg)
|
||||
bool uiprivInitReturnError(uiInitError *err, const char *msg)
|
||||
{
|
||||
// checkInitErrorLengths() above ensures that err->Message[255] will always be '\0'
|
||||
strncpy(err->Message, msg, 256);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...)
|
||||
bool uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
@ -75,7 +75,7 @@ int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...)
|
|||
va_start(ap, msg);
|
||||
vsnprintf(err->Message, 256, msg, ap);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool uiprivCheckInitializedAndThreadImpl(const char *func)
|
||||
|
|
|
@ -21,9 +21,9 @@ extern "C" {
|
|||
|
||||
// init.c
|
||||
extern const char **uiprivSysInitErrors(void);
|
||||
extern int uiprivSysInit(void *options, uiInitError *err);
|
||||
extern int uiprivInitReturnError(uiInitError *err, const char *msg);
|
||||
extern int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
|
||||
extern bool uiprivSysInit(void *options, uiInitError *err);
|
||||
extern bool uiprivInitReturnError(uiInitError *err, const char *msg);
|
||||
extern bool uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
|
||||
extern bool uiprivCheckInitializedAndThreadImpl(const char *func);
|
||||
#define uiprivCheckInitializedAndThread() uiprivCheckInitializedAndThreadImpl(uiprivFunc)
|
||||
extern bool uiprivSysCheckThread(void);
|
||||
|
|
|
@ -51,7 +51,7 @@ const char **uiprivSysInitErrors(void)
|
|||
static pthread_t mainThread;
|
||||
static BOOL initialized = NO; // TODO deduplicate this from common/init.c
|
||||
|
||||
int uiprivSysInit(void *options, uiInitError *err)
|
||||
bool uiprivSysInit(void *options, uiInitError *err)
|
||||
{
|
||||
uiprivApp = [uiprivApplication sharedApplication];
|
||||
if (![NSApp isKindOfClass:[uiprivApplication class]])
|
||||
|
@ -66,7 +66,7 @@ int uiprivSysInit(void *options, uiInitError *err)
|
|||
|
||||
mainThread = pthread_self();
|
||||
initialized = YES;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void uiMain(void)
|
||||
|
|
|
@ -78,10 +78,10 @@ TODO timers
|
|||
### `uiInit()`
|
||||
|
||||
```c
|
||||
int uiInit(void *options, uiInitError *err);
|
||||
bool uiInit(void *options, uiInitError *err);
|
||||
```
|
||||
|
||||
`uiInit()` initializes libui. It returns nonzero on success and zero on failure; in the event of a failure, `err` is filled with relevant information explaining the failure.
|
||||
`uiInit()` initializes libui. It returns `true` on success and `false` on failure; in the event of a failure, `err` is filled with relevant information explaining the failure.
|
||||
|
||||
`err` is required and must be properly initialized. If `err` is `NULL` or `err->Size` does not match `sizeof (uiError)`, `uiInit()` immediately returns zero without doing anything. If any of the other fields of `err` are not zero-initialized as with `memset(0)`, the behavior is undefined.
|
||||
|
||||
|
|
2
ui.h
2
ui.h
|
@ -38,7 +38,7 @@ struct uiInitError {
|
|||
char Message[256];
|
||||
};
|
||||
|
||||
uiprivExtern int uiInit(void *options, uiInitError *err);
|
||||
uiprivExtern bool uiInit(void *options, uiInitError *err);
|
||||
uiprivExtern void uiMain(void);
|
||||
uiprivExtern void uiQuit(void);
|
||||
uiprivExtern void uiQueueMain(void (*f)(void *data), void *data);
|
||||
|
|
|
@ -9,7 +9,7 @@ const char **uiprivSysInitErrors(void)
|
|||
static pthread_t mainThread;
|
||||
static gboolean initialized = FALSE; // TODO deduplicate this from common/init.c
|
||||
|
||||
int uiprivSysInit(void *options, uiInitError *err)
|
||||
bool uiprivSysInit(void *options, uiInitError *err)
|
||||
{
|
||||
GError *gerr = NULL;
|
||||
|
||||
|
@ -17,11 +17,11 @@ int uiprivSysInit(void *options, uiInitError *err)
|
|||
// TODO make sure this is safe
|
||||
strncpy(err->Message, gerr->message, 255);
|
||||
g_error_free(gerr);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
mainThread = pthread_self();
|
||||
initialized = TRUE;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void uiMain(void)
|
||||
|
|
|
@ -69,7 +69,7 @@ const char **uiprivSysInitErrors(void)
|
|||
static DWORD mainThread;
|
||||
static BOOL initialized = FALSE; // TODO deduplicate this from common/init.c
|
||||
|
||||
int uiprivSysInit(void *options, uiInitError *err)
|
||||
bool uiprivSysInit(void *options, uiInitError *err)
|
||||
{
|
||||
STARTUPINFOW si;
|
||||
HICON hDefaultIcon;
|
||||
|
@ -115,7 +115,7 @@ int uiprivSysInit(void *options, uiInitError *err)
|
|||
*/
|
||||
mainThread = GetCurrentThreadId();
|
||||
initialized = TRUE;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void uiMain(void)
|
||||
|
|
Loading…
Reference in New Issue