Rearranged things so that uiInit() itself is in common/init.c and the OS-specific initialization code is its own standalone internal function. This'll make testing a bit easier, especially after the next few commits, and will allow me to test pre-initialization and cross-thread stuff a bit more easily.

This commit is contained in:
Pietro Gagliardi 2019-05-09 12:07:28 -04:00
parent e1c970bdbd
commit f97383f66c
5 changed files with 26 additions and 25 deletions

View File

@ -20,7 +20,7 @@ static const char *commonInitErrors[] = {
NULL, NULL,
}; };
static int checkInitErrorLengths(uiInitError *err, const char *initErrors[]) static int checkInitErrorLengths(uiInitError *err, const char **initErrors)
{ {
const char **p; const char **p;
@ -36,7 +36,7 @@ static int checkInitErrorLengths(uiInitError *err, const char *initErrors[])
return 1; return 1;
} }
int uiprivInitCheckParams(void *options, uiInitError *err, const char *initErrors[]) int uiInit(void *options, uiInitError *err)
{ {
if (err == NULL) if (err == NULL)
return 0; return 0;
@ -45,7 +45,7 @@ int uiprivInitCheckParams(void *options, uiInitError *err, const char *initError
if (!checkInitErrorLengths(err, commonInitErrors)) if (!checkInitErrorLengths(err, commonInitErrors))
return 0; return 0;
if (!checkInitErrorLengths(err, initErrors)) if (!checkInitErrorLengths(err, uiprivSysInitErrors()))
return 0; return 0;
if (initialized) if (initialized)
@ -54,6 +54,9 @@ int uiprivInitCheckParams(void *options, uiInitError *err, const char *initError
if (options != NULL) if (options != NULL)
return uiprivInitReturnError(err, errOptionsMustBeNULL); return uiprivInitReturnError(err, errOptionsMustBeNULL);
if (!uiprivSysInit(options, err))
return 0;
initialized = 1;
return 1; return 1;
} }
@ -74,8 +77,3 @@ int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...)
va_end(ap); va_end(ap);
return 0; return 0;
} }
void uiprivMarkInitialized(void)
{
initialized = 1;
}

View File

@ -5,10 +5,10 @@ extern "C" {
#endif #endif
// init.c // init.c
extern int uiprivInitCheckParams(void *options, uiInitError *err, const char *initErrors[]); extern const char **uiprivSysInitErrors(void);
extern int uiprivSysInit(void *options, uiInitError *err);
extern int uiprivInitReturnError(uiInitError *err, const char *msg); extern int uiprivInitReturnError(uiInitError *err, const char *msg);
extern int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...); extern int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
extern void uiprivMarkInitialized(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -43,11 +43,13 @@ static const char *initErrors[] = {
NULL, NULL,
}; };
int uiInit(void *options, uiInitError *err) const char **uiprivSysInitErrors(void)
{ {
if (!uiprivInitCheckParams(options, err, initErrors)) return initErrors;
return 0; }
int uiprivSysInit(void *options, uiInitError *err)
{
uiprivApp = [uiprivApplication sharedApplication]; uiprivApp = [uiprivApplication sharedApplication];
if (![NSApp isKindOfClass:[uiprivApplication class]]) if (![NSApp isKindOfClass:[uiprivApplication class]])
return uiprivInitReturnError(err, errNSAppAlreadyInitialized); return uiprivInitReturnError(err, errNSAppAlreadyInitialized);
@ -59,7 +61,6 @@ int uiInit(void *options, uiInitError *err)
uiprivAppDelegate = [uiprivApplicationDelegate new]; uiprivAppDelegate = [uiprivApplicationDelegate new];
[uiprivApp setDelegate:uiprivAppDelegate]; [uiprivApp setDelegate:uiprivAppDelegate];
uiprivMarkInitialized();
return 1; return 1;
} }

View File

@ -1,20 +1,21 @@
// 6 april 2015 // 6 april 2015
#include "uipriv_unix.h" #include "uipriv_unix.h"
int uiInit(void *options, uiInitError *err) const char **uiprivSysInitErrors(void)
{
return NULL;
}
int uiprivSysInit(void *options, uiInitError *err)
{ {
GError *gerr = NULL; GError *gerr = NULL;
if (!uiprivInitCheckParams(options, err, NULL))
return 0;
if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &gerr) == FALSE) { if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &gerr) == FALSE) {
// TODO make sure this is safe
strncpy(err->Message, gerr->message, 255); strncpy(err->Message, gerr->message, 255);
g_error_free(gerr); g_error_free(gerr);
return 0; return 0;
} }
uiprivMarkInitialized();
return 1; return 1;
} }

View File

@ -61,7 +61,12 @@ static const char *initErrors[] = {
}; };
#define uiprivInitReturnHRESULT(err, msg, hr) uiprivInitReturnErrorf(err, "%s: 0x%08I32X", msg, hr) #define uiprivInitReturnHRESULT(err, msg, hr) uiprivInitReturnErrorf(err, "%s: 0x%08I32X", msg, hr)
int uiInit(void *options, uiInitError *err) const char **uiprivSysInitErrors(void)
{
return initErrors;
}
int uiprivSysInit(void *options, uiInitError *err)
{ {
STARTUPINFOW si; STARTUPINFOW si;
HICON hDefaultIcon; HICON hDefaultIcon;
@ -69,9 +74,6 @@ int uiInit(void *options, uiInitError *err)
INITCOMMONCONTROLSEX icc; INITCOMMONCONTROLSEX icc;
HRESULT hr; HRESULT hr;
if (!uiprivInitCheckParams(options, err, initErrors))
return 0;
setHInstance(); setHInstance();
uipriv_nCmdShow = SW_SHOWDEFAULT; uipriv_nCmdShow = SW_SHOWDEFAULT;
GetStartupInfoW(&si); GetStartupInfoW(&si);
@ -108,7 +110,6 @@ int uiInit(void *options, uiInitError *err)
// LONGTERM initialize COM security // LONGTERM initialize COM security
// LONGTERM turn off COM exception handling // LONGTERM turn off COM exception handling
*/ */
uiprivMarkInitialized();
return 1; return 1;
} }