gtk+ lacks gtk_done()



hi hi,

I've encountered a design problem in gtk+-1.2.X as well as in the gtk+-1.3.X series.
It is the lack of gtk_done(). The problem arises from two facts :
1.) I use gtk+ from a plugin-library which gets loaded via dlopen
2.) gtk+- uses g_atexit()
Now when I am done I dlclose the plugin-library. When I then end the application the
gtk_exit_func() gets triggerd and crashes the application (illegal Instruction). In gtk+-1.2.X I was be able
to install an exit handler myself before calling gtk_init and thus postpoing the
dlclose() untill then. As my exit handler was adderd earlier it was called later
und thus it worked.

Now I switched to gtk+-1.3.X as there is yet no real application using my lib
(which uses gtk+ as one of their backends) and I face the problem again.

Attached you'll find a patch to gtk/gtkmain.(c|h) which allows the developer to disable installing
the exit_handler (gtk_disable_atexit()) simmiliar to disabling gtk+ to set the locale. The developer has
then to call gtk_done() when he is not going to use gt+ anymore.
This in turn just calls the gtk_exit_func().
I still crashes on end though. Any ideas ?

Anyway I keep on debugging this ...

Ciao
  Stefan
--
      \|/
     <@ @> Stefan Kost  private                   business
+-oOO-(_)-OOo------------------------------------------------------------- - - -  -   -
|        __    Address  Zwenkauer Str. 24         HTWK Leipzig, Fb IMN, Postfach 300066
|       ///             04277 Leipzig             04277 Leipzig
|  __  ///              Germany                   Germany
|  \\\///      Phone    +49341 3910483            +49341 3076101
|   \__/       EMail    st_kost gmx net           kost imn htwk-leipzig de
|              WWW      http://www.sonicpulse.de  http://www.imn.htwk-leipzig.de/~kost/about.html
===-=-=--=---=---------------------------------- - - -  -    -
--- gtkmain.old.c	Fri Feb  1 10:38:14 2002
+++ gtkmain.c	Fri Feb  1 10:43:10 2002
@@ -437,6 +437,26 @@
   do_setlocale = FALSE;
 }
 
+static gboolean do_atexit = TRUE;
+
+/**
+ * gtk_disable_atexit:
+ * 
+ * Prevents gtk_init() and gtk_init_check() from installing an
+ * exithander. You would want to use this function if you wanted
+ * to shut down gtk+ youself using gtk_done().
+ *
+ * Most programs should not need to call this function.
+ **/
+void
+gtk_disable_atexit (void)
+{
+  if (gtk_initialized)
+    g_warning ("gtk_disable_atexit() must be called before gtk_init()");
+    
+  do_atexit = FALSE;
+}
+
 gboolean
 gtk_init_check (int	 *argc,
 		char   ***argv)
@@ -632,7 +652,8 @@
   
   /* Register an exit function to make sure we are able to cleanup.
    */
-  g_atexit (gtk_exit_func);
+  if( do_atexit)
+	g_atexit (gtk_exit_func);
   
   /* Set the 'initialized' flag.
    */
@@ -665,6 +686,12 @@
       g_warning ("cannot open display: %s", gdk_get_display ());
       exit (1);
     }
+}
+
+void
+gtk_done (void)
+{
+  gtk_exit_func();
 }
 
 #ifdef G_OS_WIN32
--- gtkmain.old.h	Fri Feb  1 10:44:25 2002
+++ gtkmain.h	Fri Feb  1 10:52:23 2002
@@ -90,6 +90,9 @@
 
 gboolean gtk_init_check           (int    *argc,
                                    char ***argv);
+
+void     gtk_done                 (void);
+
 #ifdef G_PLATFORM_WIN32
 
 /* Variants that are used to check for correct struct packing
@@ -113,6 +116,7 @@
 void     gtk_exit                 (gint    error_code);
 #endif /* GTK_DISABLE_DEPRECATED */
 
+void           gtk_disable_atexit       (void);
 void           gtk_disable_setlocale    (void);
 gchar *        gtk_set_locale           (void);
 PangoLanguage *gtk_get_default_language (void);


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