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; }