Re: GConf ...



Hi Havoc,

On Tue, 2002-01-22 at 18:26, Havoc Pennington wrote:
> Michael Meeks <michael ximian com> writes:
> > 	All of these are leaked inside GConf 
> 
> Well, they aren't leaked, technically speaking.

	True :-) but it'd be great to have this API to allow us to write more
automated tests for GUI apps (plug for the release team).

> > 	Ideally I need a gconf_debug_shutdown () method.
> 
> That's fine with me I guess.
> 
> I think you just need to make gconf_detach_config_server() in gconf.c
> also gconf_engine_detach() all engines, then call
> gconf_detach_config_server() in your debug shutdown thingy.

	Ok - so this patch essentially adds 1 new public API:

void gconf_detach_config_server (void);

	I'd like permission to add this, since we have a very nice CORBA /
bonobo automated reference counting scheme in place, and we need gconf
to play ball with it to make regression tests that use gconf useful.

	So may I have approval ?

> Send along a patch.

	Appended,

	Regards,

		Michael.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gconf/ChangeLog,v
retrieving revision 1.350
diff -u -p -u -r1.350 ChangeLog
--- ChangeLog	2002/01/23 19:56:24	1.350
+++ ChangeLog	2002/01/25 16:30:07
@@ -1,3 +1,30 @@
+2002-01-25  Michael Meeks  <michael ximian com>
+
+	* gconf/gconf.c (try_to_contact_server): release the
+	server reference, if it's to a duff object.
+	(gconf_get_config_listener): strip local 'listener',
+	since we have a static module global for that.
+	(gconf_detach_config_server): release the listener.
+	(gconf_get_config_listener): release the poa & manager
+	references.
+
+	* tests/testgconf.c (main): add
+	gconf_detach_config_server
+
+	* gconf/gconf-internals.c
+	(gconf_orb_get): remove bonobo activation
+	worries, kill bogus fiddling with the default
+	context.
+	(gconf_orb_release): impl.
+
+	* gconf/gconf.c (gconf_detach_config_server):
+	publicise & destroy engines_by_cb.
+	(database_rec_release): impl.
+	(gconf_engine_set_database): use g_hash_table_new_full
+	(gconf_engine_detach): just remove from the hash.
+	(try_to_contact_server): release the server reference,
+	if it's to a duff object.
+
 2002-01-20  Havoc Pennington  <hp pobox com>
 
 	* gconf/Makefile.am: add gconf-enum-types.h/gconf-enum-types.c 
Index: gconf/gconf-client.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf-client.c,v
retrieving revision 1.51
diff -u -p -u -r1.51 gconf-client.c
--- gconf/gconf-client.c	2002/01/16 23:27:27	1.51
+++ gconf/gconf-client.c	2002/01/25 16:30:11
@@ -1094,8 +1094,8 @@ gconf_client_suggest_sync   (GConfClient
 }
 
 gboolean
-gconf_client_dir_exists     (GConfClient* client,
-                             const gchar* dir, GError** err)
+gconf_client_dir_exists(GConfClient* client,
+                        const gchar* dir, GError** err)
 {
   GError* error = NULL;
   gboolean retval;
Index: gconf/gconf-internals.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf-internals.c,v
retrieving revision 1.104
diff -u -p -u -r1.104 gconf-internals.c
--- gconf/gconf-internals.c	2002/01/15 02:01:07	1.104
+++ gconf/gconf-internals.c	2002/01/25 16:30:16
@@ -2736,48 +2736,44 @@ get_hostname (void)
 	return hostname;
 }
 
+static CORBA_ORB gconf_orb = CORBA_OBJECT_NIL;      
+
 CORBA_ORB
 gconf_orb_get (void)
 {
-  if (TRUE || gconf_in_daemon_mode ())
+  if (gconf_orb == CORBA_OBJECT_NIL)
     {
-      static CORBA_ORB gconf_orb = CORBA_OBJECT_NIL;      
-
-      if (gconf_orb == CORBA_OBJECT_NIL)
-        {
-          CORBA_Environment ev;
-          int argc = 1;
-          char *argv[] = { "gconf", NULL };
-          CORBA_Context context;
-          const char *hostname;
+      CORBA_Environment ev;
+      int argc = 1;
+      char *argv[] = { "gconf", NULL };
       
-          CORBA_exception_init (&ev);
+      CORBA_exception_init (&ev);
       
-          gconf_orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
-          g_assert (ev._major == CORBA_NO_EXCEPTION);
+      gconf_orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
+      g_assert (ev._major == CORBA_NO_EXCEPTION);
 
-          /* Set values in default context */
-          CORBA_ORB_get_default_context (gconf_orb, &context, &ev);
-          g_assert (ev._major == CORBA_NO_EXCEPTION);
-          
-          hostname = get_hostname ();
-          CORBA_Context_set_one_value (context, "hostname",
-                                       (char *) hostname, &ev);
-          CORBA_Context_set_one_value (context, "domain", "user", &ev);
-          CORBA_Context_set_one_value (context, "username",
-                                       g_get_user_name (), &ev);
-          
-          CORBA_exception_free (&ev);
-        }
-      
-      return gconf_orb;
+      CORBA_exception_free (&ev);
     }
-  else
+
+  return gconf_orb;
+}
+
+void
+gconf_orb_release (void)
+{
+  if (gconf_orb != CORBA_OBJECT_NIL)
     {
-      /* FIXME do we have to do this if an app is using bonobo activation? */
-#if 0
-      return bonobo_activation_orb_get ();
-#endif
+      CORBA_ORB orb = gconf_orb;
+      CORBA_Environment ev;
+
+      gconf_orb = CORBA_OBJECT_NIL;
+
+      CORBA_exception_init (&ev);
+
+      CORBA_ORB_destroy (orb, &ev);
+      CORBA_Object_release ((CORBA_Object)orb, &ev);
+
+      CORBA_exception_free (&ev);
     }
 }
 
Index: gconf/gconf-internals.h
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf-internals.h,v
retrieving revision 1.66
diff -u -p -u -r1.66 gconf-internals.h
--- gconf/gconf-internals.h	2002/01/15 02:01:07	1.66
+++ gconf/gconf-internals.h	2002/01/25 16:30:17
@@ -79,7 +79,7 @@ GSList*       gconf_load_source_path (co
 void     gconf_shutdown_daemon (GError **err);
 gboolean gconf_ping_daemon     (void);
 gboolean gconf_spawn_daemon    (GError **err);
-
+void     gconf_orb_release     (void);
 
 /* Returns 0 on failure (or if the string is "0" of course) */
 gulong       gconf_string_to_gulong (const gchar *str);
Index: gconf/gconf.c
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf.c,v
retrieving revision 1.130
diff -u -p -u -r1.130 gconf.c
--- gconf/gconf.c	2002/01/15 02:01:07	1.130
+++ gconf/gconf.c	2002/01/25 16:30:22
@@ -126,7 +126,6 @@ static ConfigServer   gconf_get_config_s
 
 /* Forget our current server object reference, so the next call to
    gconf_get_config_server will have to try to respawn the server */
-static void           gconf_detach_config_server (void);
 static ConfigListener gconf_get_config_listener  (void);
 
 static void           gconf_engine_detach       (GConfEngine     *conf);
@@ -251,6 +250,20 @@ lookup_engine_by_database (ConfigDatabas
     return NULL;
 }
 
+static void
+database_rec_release (gpointer rec)
+{
+  GConfEngine *conf = rec;
+  CORBA_Environment ev;
+
+  CORBA_exception_init (&ev);
+
+  CORBA_Object_release (conf->database, &ev);
+  conf->database = CORBA_OBJECT_NIL;
+  
+  CORBA_exception_free (&ev);
+}
+
 /* This takes ownership of the ConfigDatabase */
 static void
 gconf_engine_set_database (GConfEngine *conf,
@@ -261,8 +274,11 @@ gconf_engine_set_database (GConfEngine *
   conf->database = db;
 
   if (engines_by_db == NULL)
-    engines_by_db = g_hash_table_new ((GHashFunc) gconf_CORBA_Object_hash,
-                                      (GCompareFunc) gconf_CORBA_Object_equal);
+    engines_by_db = g_hash_table_new_full (
+	    (GHashFunc) gconf_CORBA_Object_hash,
+	    (GCompareFunc) gconf_CORBA_Object_equal,
+	    NULL,
+	    database_rec_release);
   
   g_hash_table_insert (engines_by_db, conf->database, conf);  
 }
@@ -270,16 +286,9 @@ gconf_engine_set_database (GConfEngine *
 static void
 gconf_engine_detach (GConfEngine *conf)
 {
-  CORBA_Environment ev;
-
-  CORBA_exception_init (&ev);
-  
-  if (!CORBA_Object_is_nil (conf->database, &ev))
+  if (conf->database != CORBA_OBJECT_NIL)
     {
       g_hash_table_remove (engines_by_db, conf->database);
-      
-      CORBA_Object_release (conf->database, &ev);
-      conf->database = CORBA_OBJECT_NIL;
     }
 }
 
@@ -311,7 +320,7 @@ gconf_engine_connect (GConfEngine *conf,
     db = ConfigServer_get_default_database (cs, &ev);      
   else
     db = ConfigServer_get_database (cs, conf->address, &ev);
-  
+
   if (gconf_server_broken(&ev))
     {
       if (tries < MAX_RETRIES)
@@ -484,7 +493,7 @@ gconf_engine_get_for_address (const gcha
 }
 
 void
-gconf_engine_ref             (GConfEngine* conf)
+gconf_engine_ref(GConfEngine* conf)
 {
   g_return_if_fail(conf != NULL);
   g_return_if_fail(conf->refcount > 0);
@@ -493,7 +502,7 @@ gconf_engine_ref             (GConfEngin
 }
 
 void         
-gconf_engine_unref        (GConfEngine* conf)
+gconf_engine_unref(GConfEngine* conf)
 {
   g_return_if_fail(conf != NULL);
   g_return_if_fail(conf->refcount > 0);
@@ -2065,13 +2074,14 @@ try_to_contact_server (gboolean start_if
       
       if (ev._major != CORBA_NO_EXCEPTION)
 	{
-	  server = CORBA_OBJECT_NIL;
           g_set_error (err,
                        GCONF_ERROR,
                        GCONF_ERROR_NO_SERVER,
                        _("Adding client to server's list failed, CORBA error: %s"),
                        CORBA_exception_id (&ev));
 
+	  CORBA_Object_release (server, &ev);
+	  server = CORBA_OBJECT_NIL;
           CORBA_exception_free(&ev);
 	}
     }
@@ -2099,29 +2109,51 @@ gconf_get_config_server(gboolean start_i
   return server; /* return what we have, NIL or not */
 }
 
-static void
+ConfigListener listener = CORBA_OBJECT_NIL;
+
+/**
+ * gconf_detach_config_server:
+ * @void: 
+ * 
+ * Detach from the config server and release
+ * all related resources
+ **/
+void
 gconf_detach_config_server(void)
 {  
-  if (server != CORBA_OBJECT_NIL)
+  CORBA_Environment ev;
+
+  CORBA_exception_init(&ev);
+
+  if (listener != CORBA_OBJECT_NIL)
     {
-      CORBA_Environment ev;
-      
-      CORBA_exception_init(&ev);
+      CORBA_Object_release(listener, &ev);
+    }
 
+  if (server != CORBA_OBJECT_NIL)
+    {
       CORBA_Object_release(server, &ev);
 
       if (ev._major != CORBA_NO_EXCEPTION)
         {
           g_warning("Exception releasing gconfd server object: %s",
                     CORBA_exception_id(&ev));
-          CORBA_exception_free(&ev);
         }
 
       server = CORBA_OBJECT_NIL;
     }
+
+  CORBA_exception_free(&ev);
+
+  if (engines_by_db != NULL)
+    {
+      g_hash_table_destroy (engines_by_db);
+      engines_by_db = NULL;
+    }
+
+  gconf_orb_release ();
 }
 
-ConfigListener listener = CORBA_OBJECT_NIL;
 static void notify                  (PortableServer_Servant     servant,
                                      ConfigDatabase             db,
                                      CORBA_unsigned_long        cnxn,
@@ -2299,13 +2331,12 @@ drop_all_caches (PortableServer_Servant 
 
 static ConfigListener 
 gconf_get_config_listener(void)
-{
-  static ConfigListener listener = CORBA_OBJECT_NIL;
-  
+{  
   if (listener == CORBA_OBJECT_NIL)
     {
       CORBA_Environment ev;
       PortableServer_POA poa;
+      PortableServer_POAManager poa_mgr;
 
       CORBA_exception_init (&ev);
       POA_ConfigListener__init (&poa_listener_servant, &ev);
@@ -2318,13 +2349,17 @@ gconf_get_config_listener(void)
 
       g_assert (ev._major == CORBA_NO_EXCEPTION);
 
-      PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(poa, &ev), &ev);
+      poa_mgr = PortableServer_POA__get_the_POAManager (poa, &ev);
+      PortableServer_POAManager_activate (poa_mgr, &ev);
 
       g_assert (ev._major == CORBA_NO_EXCEPTION);
 
       listener = PortableServer_POA_servant_to_reference(poa,
                                                          &poa_listener_servant,
                                                          &ev);
+
+      CORBA_Object_release ((CORBA_Object) poa_mgr, &ev);
+      CORBA_Object_release ((CORBA_Object) poa, &ev);
 
       g_assert (listener != CORBA_OBJECT_NIL);
       g_assert (ev._major == CORBA_NO_EXCEPTION);
Index: gconf/gconf.h
===================================================================
RCS file: /cvs/gnome/gconf/gconf/gconf.h,v
retrieving revision 1.68
diff -u -p -u -r1.68 gconf.h
--- gconf/gconf.h	2002/01/23 19:56:25	1.68
+++ gconf/gconf.h	2002/01/25 16:30:24
@@ -292,6 +292,7 @@ extern struct poptOption gconf_options[]
 
 void gconf_clear_cache(GConfEngine* conf, GError** err);
 void gconf_synchronous_sync(GConfEngine* conf, GError** err);
+void gconf_detach_config_server(void);
 
 GConfValue * gconf_engine_get_full (GConfEngine *conf,
                                     const gchar *key,
@@ -308,6 +309,3 @@ GConfValue * gconf_engine_get_full (GCon
 #endif /* __cplusplus */
 
 #endif
-
-
-
Index: tests/testaddress.c
===================================================================
RCS file: /cvs/gnome/gconf/tests/testaddress.c,v
retrieving revision 1.2
diff -u -p -u -r1.2 testaddress.c
--- tests/testaddress.c	2001/12/11 20:26:41	1.2
+++ tests/testaddress.c	2002/01/25 16:30:24
@@ -29,7 +29,7 @@
 /*
  *
  *
- * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples/*
+ * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples
  *
  *
  *
@@ -46,6 +46,8 @@
 #include <gconf/gconf.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
 #include <math.h>
 #include <gconf/gconf-internals.h>
 #include <gconf/gconf-backend.h>
Index: tests/testencode.c
===================================================================
RCS file: /cvs/gnome/gconf/tests/testencode.c,v
retrieving revision 1.5
diff -u -p -u -r1.5 testencode.c
--- tests/testencode.c	2000/10/06 17:26:26	1.5
+++ tests/testencode.c	2002/01/25 16:30:25
@@ -20,6 +20,8 @@
 #include <gconf/gconf.h>
 #include <gconf/gconf-internals.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <math.h>
 
Index: tests/testgconf.c
===================================================================
RCS file: /cvs/gnome/gconf/tests/testgconf.c,v
retrieving revision 1.23
diff -u -p -u -r1.23 testgconf.c
--- tests/testgconf.c	2002/01/13 04:41:02	1.23
+++ tests/testgconf.c	2002/01/25 16:30:28
@@ -30,7 +30,7 @@
 /*
  *
  *
- * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples/*
+ * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples
  *
  *
  *
@@ -46,6 +46,8 @@
 
 #include <gconf/gconf.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <math.h>
 #include <gconf/gconf-internals.h>
@@ -969,10 +971,15 @@ main (int argc, char** argv)
   printf("\nChecking bool storage:");
   
   check_bool_storage(conf);
-  
+
+  gconf_engine_set_bool(conf, "/foo", TRUE, &err);
+
   gconf_engine_unref(conf);
 
+  gconf_detach_config_server ();
+
   printf("\n\n");
   
   return 0;
 }
+
Index: tests/testpersistence.c
===================================================================
RCS file: /cvs/gnome/gconf/tests/testpersistence.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 testpersistence.c
--- tests/testpersistence.c	2001/12/11 20:26:41	1.9
+++ tests/testpersistence.c	2002/01/25 16:30:28
@@ -30,7 +30,7 @@
 /*
  *
  *
- * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples/*
+ * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples
  *
  *
  *
@@ -46,6 +46,8 @@
 
 #include <gconf/gconf.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <math.h>
 #include <gconf/gconf-internals.h>
Index: tests/testschemas.c
===================================================================
RCS file: /cvs/gnome/gconf/tests/testschemas.c,v
retrieving revision 1.18
diff -u -p -u -r1.18 testschemas.c
--- tests/testschemas.c	2001/12/11 20:26:41	1.18
+++ tests/testschemas.c	2002/01/25 16:30:30
@@ -30,7 +30,7 @@
 /*
  *
  *
- * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples/*
+ * DO NOT USE THESE CRAPPY TESTS AS EXAMPLE CODE. USE THE DOCS AND examples
  *
  *
  *
@@ -45,6 +45,8 @@
 
 #include <gconf/gconf.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <math.h>
 #include <gconf/gconf-internals.h>

-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot




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