From d326407f05cadec6422fe3ccbcfcaf41a869dfde Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 10 Apr 2015 16:54:06 -0400 Subject: [PATCH] Decided to kill uiInitError and return the message as a const char * instead. Will need to implement on Windows. --- new/init_darwin.m | 9 ++------- new/init_unix.c | 28 ++++++++++------------------ new/test.c | 6 +++--- new/ui.h | 6 ++---- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/new/init_darwin.m b/new/init_darwin.m index 8d1a117..c7be20d 100644 --- a/new/init_darwin.m +++ b/new/init_darwin.m @@ -42,7 +42,7 @@ uiInitOptions options; -uiInitError *uiInit(uiInitOptions *o) +const char *uiInit(uiInitOptions *o) { options = *o; [uiApplication sharedApplication]; @@ -53,11 +53,6 @@ uiInitError *uiInit(uiInitOptions *o) return NULL; } -const char *uiInitErrorMessage(uiInitError *err) -{ - return ""; -} - -void uiInitErrorFree(uiInitError *err) +void uiFreeInitError(const char *err) { } diff --git a/new/init_unix.c b/new/init_unix.c index 60abc91..b10c05b 100644 --- a/new/init_unix.c +++ b/new/init_unix.c @@ -1,31 +1,23 @@ // 6 april 2015 #include "uipriv_unix.h" -struct uiInitError { - GError *err; -}; - uiInitOptions options; -uiInitError *uiInit(uiInitOptions *o) +const char *uiInit(uiInitOptions *o) { - uiInitError *err; + GError *err = NULL; + const char *msg; options = *o; - err = uiNew(uiInitError); - if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &(err->err)) == FALSE) - return err; - uiFree(err); + if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) { + msg = g_strdup(err->message); + g_error_free(err); + return msg; + } return NULL; } -const char *uiInitErrorMessage(uiInitError *err) +void uiFreeInitError(const char *err) { - return err->err->message; -} - -void uiInitErrorFree(uiInitError *err) -{ - g_error_free(err->err); - uiFree(err); + g_free((gpointer) err); } diff --git a/new/test.c b/new/test.c index 991b62b..f61038e 100644 --- a/new/test.c +++ b/new/test.c @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) { uiInitOptions o; int i; - uiInitError *err; + const char *err; uiControl *getButton, *setButton; memset(&o, 0, sizeof (uiInitOptions)); @@ -128,8 +128,8 @@ int main(int argc, char *argv[]) err = uiInit(&o); if (err != NULL) { - fprintf(stderr, "error initializing ui: %s\n", uiInitErrorMessage(err)); - uiInitErrorFree(err); + fprintf(stderr, "error initializing ui: %s\n", err); + uiFreeInitError(err); return 1; } diff --git a/new/ui.h b/new/ui.h index a692585..0625bd0 100644 --- a/new/ui.h +++ b/new/ui.h @@ -5,7 +5,6 @@ #include -typedef struct uiInitError uiInitError; typedef struct uiInitOptions uiInitOptions; // TODO note that should be initialized to zero @@ -17,9 +16,8 @@ struct uiInitOptions { int debugLogAllocations; }; -uiInitError *uiInit(uiInitOptions *); -const char *uiInitErrorMessage(uiInitError *); -void uiInitErrorFree(uiInitError *); +const char *uiInit(uiInitOptions *); +void uiFreeInitError(const char *); void uiMain(void); void uiQuit(void);