From f97383f66cbf7586637b8bbe65bf50c3af59d1ef Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 9 May 2019 12:07:28 -0400 Subject: [PATCH] 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. --- common/init.c | 14 ++++++-------- common/uipriv.h | 4 ++-- darwin/main.m | 9 +++++---- unix/main.c | 13 +++++++------ windows/main.cpp | 11 ++++++----- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/common/init.c b/common/init.c index c22a1342..83015402 100644 --- a/common/init.c +++ b/common/init.c @@ -20,7 +20,7 @@ static const char *commonInitErrors[] = { NULL, }; -static int checkInitErrorLengths(uiInitError *err, const char *initErrors[]) +static int checkInitErrorLengths(uiInitError *err, const char **initErrors) { const char **p; @@ -36,7 +36,7 @@ static int checkInitErrorLengths(uiInitError *err, const char *initErrors[]) return 1; } -int uiprivInitCheckParams(void *options, uiInitError *err, const char *initErrors[]) +int uiInit(void *options, uiInitError *err) { if (err == NULL) return 0; @@ -45,7 +45,7 @@ int uiprivInitCheckParams(void *options, uiInitError *err, const char *initError if (!checkInitErrorLengths(err, commonInitErrors)) return 0; - if (!checkInitErrorLengths(err, initErrors)) + if (!checkInitErrorLengths(err, uiprivSysInitErrors())) return 0; if (initialized) @@ -54,6 +54,9 @@ int uiprivInitCheckParams(void *options, uiInitError *err, const char *initError if (options != NULL) return uiprivInitReturnError(err, errOptionsMustBeNULL); + if (!uiprivSysInit(options, err)) + return 0; + initialized = 1; return 1; } @@ -74,8 +77,3 @@ int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...) va_end(ap); return 0; } - -void uiprivMarkInitialized(void) -{ - initialized = 1; -} diff --git a/common/uipriv.h b/common/uipriv.h index 3db2660b..613e0d0b 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -5,10 +5,10 @@ extern "C" { #endif // 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 uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...); -extern void uiprivMarkInitialized(void); #ifdef __cplusplus } diff --git a/darwin/main.m b/darwin/main.m index 0532bf5e..9e95e3b3 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -43,11 +43,13 @@ static const char *initErrors[] = { NULL, }; -int uiInit(void *options, uiInitError *err) +const char **uiprivSysInitErrors(void) { - if (!uiprivInitCheckParams(options, err, initErrors)) - return 0; + return initErrors; +} +int uiprivSysInit(void *options, uiInitError *err) +{ uiprivApp = [uiprivApplication sharedApplication]; if (![NSApp isKindOfClass:[uiprivApplication class]]) return uiprivInitReturnError(err, errNSAppAlreadyInitialized); @@ -59,7 +61,6 @@ int uiInit(void *options, uiInitError *err) uiprivAppDelegate = [uiprivApplicationDelegate new]; [uiprivApp setDelegate:uiprivAppDelegate]; - uiprivMarkInitialized(); return 1; } diff --git a/unix/main.c b/unix/main.c index 87624119..1ab14138 100644 --- a/unix/main.c +++ b/unix/main.c @@ -1,20 +1,21 @@ // 6 april 2015 #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; - if (!uiprivInitCheckParams(options, err, NULL)) - return 0; - if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &gerr) == FALSE) { + // TODO make sure this is safe strncpy(err->Message, gerr->message, 255); g_error_free(gerr); return 0; } - - uiprivMarkInitialized(); return 1; } diff --git a/windows/main.cpp b/windows/main.cpp index 4bcef139..dbb69264 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -61,7 +61,12 @@ static const char *initErrors[] = { }; #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; HICON hDefaultIcon; @@ -69,9 +74,6 @@ int uiInit(void *options, uiInitError *err) INITCOMMONCONTROLSEX icc; HRESULT hr; - if (!uiprivInitCheckParams(options, err, initErrors)) - return 0; - setHInstance(); uipriv_nCmdShow = SW_SHOWDEFAULT; GetStartupInfoW(&si); @@ -108,7 +110,6 @@ int uiInit(void *options, uiInitError *err) // LONGTERM initialize COM security // LONGTERM turn off COM exception handling */ - uiprivMarkInitialized(); return 1; }