pspp-dev
[Top][All Lists]
Advanced

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

[PATCH 1/2] psppire-acr: Clarify acr ownership of its list store.


From: Ben Pfaff
Subject: [PATCH 1/2] psppire-acr: Clarify acr ownership of its list store.
Date: Mon, 23 Apr 2012 22:19:05 -0700

PsppireAcr retains a pointer to the GtkListStore inside it but it
didn't, until now, keep a reference to it.  This commit makes
PsppireAcr retain a reference, documents the interface, and updates
callers to properly maintain reference counts.
---
 src/ui/gui/aggregate-dialog.c  |    2 +
 src/ui/gui/chi-square-dialog.c |    1 +
 src/ui/gui/psppire-acr.c       |   45 ++++++++++++++++-----------------------
 3 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/src/ui/gui/aggregate-dialog.c b/src/ui/gui/aggregate-dialog.c
index 7fce9f5..b3f3564 100644
--- a/src/ui/gui/aggregate-dialog.c
+++ b/src/ui/gui/aggregate-dialog.c
@@ -527,6 +527,8 @@ aggregate_dialog (PsppireDataWindow *dw)
                                             G_TYPE_DOUBLE);
 
     psppire_acr_set_model (PSPPIRE_ACR (fd.summary_acr), list);
+    g_object_unref (list);
+    
 
     psppire_acr_set_get_value_func (PSPPIRE_ACR (fd.summary_acr),
                                                 get_summary_spec, &fd);
diff --git a/src/ui/gui/chi-square-dialog.c b/src/ui/gui/chi-square-dialog.c
index 7666cb5..dfa39f0 100644
--- a/src/ui/gui/chi-square-dialog.c
+++ b/src/ui/gui/chi-square-dialog.c
@@ -237,5 +237,6 @@ chisquare_dialog (PsppireDataWindow *dw)
       break;
     }
 
+  g_object_unref (csd.expected_list);
   g_object_unref (xml);
 }
diff --git a/src/ui/gui/psppire-acr.c b/src/ui/gui/psppire-acr.c
index f11283b..c23bdcf 100644
--- a/src/ui/gui/psppire-acr.c
+++ b/src/ui/gui/psppire-acr.c
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -40,35 +40,22 @@
 #include "psppire-acr.h"
 #include "helper.h"
 
-static void psppire_acr_init (PsppireAcr *);
+G_DEFINE_TYPE (PsppireAcr, psppire_acr, GTK_TYPE_HBOX);
 
-GType
-psppire_acr_get_type (void)
+static void
+psppire_acr_dispose (GObject *obj)
 {
-  static GType acr_type = 0;
-
-  if (!acr_type)
-    {
-      static const GTypeInfo acr_info =
-      {
-       sizeof (PsppireAcrClass),
-       NULL, /* base_init */
-        NULL, /* base_finalize */
-       NULL, /* class_init */
-        NULL, /* class_finalize */
-       NULL, /* class_data */
-        sizeof (PsppireAcr),
-       0,
-       (GInstanceInitFunc) psppire_acr_init,
-      };
-
-      acr_type = g_type_register_static (GTK_TYPE_HBOX, "PsppireAcr",
-                                       &acr_info, 0);
-    }
+  PsppireAcr *acr = PSPPIRE_ACR (obj);
+  psppire_acr_set_model (acr, NULL);
 
-  return acr_type;
+  G_OBJECT_CLASS (psppire_acr_parent_class)->dispose (obj);
 }
 
+static void
+psppire_acr_class_init (PsppireAcrClass *class)
+{
+  G_OBJECT_CLASS (class)->dispose = psppire_acr_dispose;
+}
 
 static gboolean row_is_selected (const PsppireAcr *acr);
 
@@ -347,10 +334,16 @@ psppire_acr_new (void)
 
 
 
-/* Set the widget's treemodel */
+/* Set the widget's treemodel to LISTSTORE.  LISTSTORE ownership is not
+   transferred. */
 void
 psppire_acr_set_model (PsppireAcr *acr, GtkListStore *liststore)
 {
+  if (acr->list_store)
+    g_object_unref (liststore);
+  if (liststore)
+    g_object_ref (liststore);
+
   acr->list_store = liststore;
 
   gtk_tree_view_set_model (GTK_TREE_VIEW (acr->tv),
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]