[maemo-commits] [maemo-commits] r8912 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Jan 2 18:08:07 EET 2007
Author: lucasr
Date: 2007-01-02 18:08:06 +0200 (Tue, 02 Jan 2007)
New Revision: 8912

Modified:
   projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog
   projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-python.c
Log:
2007-01-02  Lucas Rocha  <lucas.rocha at nokia.com>

	* src/hd-plugin-loader-python.c: improve memory management by
	decreasing reference count of the python object and module related to
	the plugin. Also, python garbage collection is used now.


Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog	2007-01-02 15:22:16 UTC (rev 8911)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog	2007-01-02 16:08:06 UTC (rev 8912)
@@ -1,5 +1,11 @@
 2007-01-02  Lucas Rocha  <lucas.rocha at nokia.com>
 
+	* src/hd-plugin-loader-python.c: improve memory management by
+	decreasing reference count of the python object and module related to
+	the plugin. Also, python garbage collection is used now.
+
+2007-01-02  Lucas Rocha  <lucas.rocha at nokia.com>
+
 	* src/hd-plugin-loader-python.c: fix crash when loading and then
 	unloading a python plugin.
 

Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-python.c
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-python.c	2007-01-02 15:22:16 UTC (rev 8911)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-python.c	2007-01-02 16:08:06 UTC (rev 8912)
@@ -41,6 +41,20 @@
   gboolean initialised;
 };
 
+static void 
+hd_plugin_loader_python_destroy_plugin (GtkObject *object, gpointer user_data)
+{
+  PyObject *pModule, *pObject;
+
+  pObject = (PyObject *) g_object_get_data (G_OBJECT (object), "object");
+  pModule = (PyObject *) g_object_get_data (G_OBJECT (object), "module");
+
+  Py_DECREF (pObject);
+  Py_DECREF (pModule);
+
+  PyGC_Collect();
+}
+
 static GList * 
 hd_plugin_loader_python_open_module (HDPluginLoaderPython *loader,
                                       GError **error)
@@ -142,6 +156,19 @@
           {
             GObject *object = g_object_ref(((PyGObject *) pObject)->obj);
 
+            g_signal_connect (G_OBJECT (object), 
+                              "destroy", 
+                              G_CALLBACK (hd_plugin_loader_python_destroy_plugin), 
+                              NULL);
+
+            /* Increase reference count of the module for each "extra"
+               plugin instance so that when no more plugin instances exist
+               the module is unloaded correctly. */
+            Py_INCREF (pModule);
+
+            g_object_set_data (object, "object", pObject);
+            g_object_set_data (object, "module", pModule);
+
             objects = g_list_append (objects, object);
           }
         }
@@ -150,8 +177,8 @@
       }
       else 
       {
-        Py_XDECREF(pList);
-        Py_DECREF(pModule);
+        Py_XDECREF (pList);
+        Py_DECREF (pModule);
 
         PyErr_Print ();
         PyErr_Clear ();


More information about the maemo-commits mailing list