[polari/wip/fmuellner/lib-cleanup: 4/4] main: Use autoptr as well



commit a0a1fb3188883027e18f61ecac90bc4f9945220c
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Dec 8 22:59:36 2017 +0100

    main: Use autoptr as well
    
    Simplify our error paths by allowing the compiler to clean up any
    local variables.

 src/polari.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
---
diff --git a/src/polari.c b/src/polari.c
index 2bc6e82..0155cdb 100644
--- a/src/polari.c
+++ b/src/polari.c
@@ -1,6 +1,8 @@
 #include <girepository.h>
 #include <gjs/gjs.h>
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GjsContext, g_object_unref)
+
 const char *src =
   "imports.package.start({ name: '" PACKAGE_NAME "',"
   "                        version: '" PACKAGE_VERSION "',"
@@ -11,8 +13,8 @@ int
 main (int argc, char *argv[])
 {
   const char *search_path[] = { "resource:///org/gnome/Polari/js", NULL };
-  GError *error = NULL;
-  GjsContext *context;
+  g_autoptr (GError) error = NULL;
+  g_autoptr (GjsContext) context = NULL;
   int status;
 
   g_irepository_prepend_search_path (PKGLIBDIR);
@@ -26,9 +28,6 @@ main (int argc, char *argv[])
                                         &error))
     {
       g_message ("Failed to define ARGV: %s", error->message);
-      g_error_free (error);
-
-      g_object_unref (context);
 
       return 1;
     }
@@ -36,14 +35,9 @@ main (int argc, char *argv[])
   if (!gjs_context_eval (context, src, -1, "<main>", &status, &error))
     {
       g_message ("Execution of start() threw exception: %s", error->message);
-      g_error_free (error);
-
-      g_object_unref (context);
 
       return status;
     }
 
-  g_object_unref (context);
-
   return 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]