added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
authorTim Janik <timj@gtk.org>
Sun, 17 Jan 1999 14:52:20 +0000 (14:52 +0000)
committerTim Janik <timj@src.gnome.org>
Sun, 17 Jan 1999 14:52:20 +0000 (14:52 +0000)
Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>

        * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
        GHookList.hook_destroy function.

        * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
        is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
        we now clean up the hook completely afterwards, i.e. data, func and
        destroy are immediately set to NULL and hook_free can't play with that
        values anymore.

        * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
        instead of using an ugly _noop() hack, this is to avoid an uneccessary
        function invokation. set hook_free to g_source_destroy_func, this way
        we always invoke the destroy notifiers for user_data and source_data
        after execution of dispatch(). thus, g_source_destroy_func() will always
        be called within the main_loop lock (this wasn't really assured
        before), and can release and reaquire the look around destroy notifier
        invokation.

14 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
ghook.c
glib.h
glib/ghook.c
glib/glib.h
glib/gmain.c
gmain.c

index 1f144d2..7762008 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
index 1f144d2..7762008 100644 (file)
@@ -1,3 +1,23 @@
+Sun Jan 17 14:13:52 1999  Tim Janik  <timj@gtk.org>
+
+       * glib.h: added a define G_HOOK_DEFERRED_DESTROY, to substitute a noop
+       GHookList.hook_destroy function.
+
+       * ghook.c (g_hook_destroy_link): don't really call hook_destroy if it
+       is G_HOOK_DEFERRED_DESTROY. for the case where we invoke hook->destroy()
+       we now clean up the hook completely afterwards, i.e. data, func and
+       destroy are immediately set to NULL and hook_free can't play with that
+       values anymore.
+
+       * gmain.c (g_source_add): set hook_destroy to G_HOOK_DEFERRED_DESTROY,
+       instead of using an ugly _noop() hack, this is to avoid an uneccessary
+       function invokation. set hook_free to g_source_destroy_func, this way
+       we always invoke the destroy notifiers for user_data and source_data
+       after execution of dispatch(). thus, g_source_destroy_func() will always
+       be called within the main_loop lock (this wasn't really assured
+       before), and can release and reaquire the look around destroy notifier
+       invokation.
+
 Sun Jan 17 11:01:40 1999  Tor Lillqvist  <tml@iki.fi>
 
        * config.h.win32 glibconfig.h.win32: Increment version number here
@@ -16,7 +36,7 @@ Sun Jan 17 05:12:17 1999  Tim Janik  <timj@gtk.org>
        * gmain.c: removed g_source_free_func and added g_source_destroy_func,
        which marshalls the user_data and source_data destructors of sources
        outside of the main_loop lock.
-       removed GIdleData struct since its single member callback can be passed
+       removed GIdleData struct since its sole member callback can be passed
        as source_data directly.
        added a gboolean return value to all g_source_remove* functions,
        indicating whether the source could be removed, because these functions
diff --git a/ghook.c b/ghook.c
index fae6927..7e1c82d 100644 (file)
--- a/ghook.c
+++ b/ghook.c
@@ -131,10 +131,15 @@ g_hook_destroy_link (GHookList *hook_list,
       hook->hook_id = 0;
       hook->flags &= ~G_HOOK_FLAG_ACTIVE;
       if (hook_list->hook_destroy)
-       hook_list->hook_destroy (hook_list, hook);
+       {
+         if (hook_list->hook_destroy != G_HOOK_DEFERRED_DESTROY)
+           hook_list->hook_destroy (hook_list, hook);
+       }
       else if (hook->destroy)
        {
          hook->destroy (hook->data);
+         hook->data = NULL;
+         hook->func = NULL;
          hook->destroy = NULL;
        }
       g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
diff --git a/glib.h b/glib.h
index 6848d2b..03951b6 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -1112,6 +1112,8 @@ typedef enum
   G_HOOK_FLAG_MASK     = 0x0f
 } GHookFlagMask;
 
+#define        G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
+
 struct _GHookList
 {
   guint                 seq_id;
index fae6927..7e1c82d 100644 (file)
@@ -131,10 +131,15 @@ g_hook_destroy_link (GHookList *hook_list,
       hook->hook_id = 0;
       hook->flags &= ~G_HOOK_FLAG_ACTIVE;
       if (hook_list->hook_destroy)
-       hook_list->hook_destroy (hook_list, hook);
+       {
+         if (hook_list->hook_destroy != G_HOOK_DEFERRED_DESTROY)
+           hook_list->hook_destroy (hook_list, hook);
+       }
       else if (hook->destroy)
        {
          hook->destroy (hook->data);
+         hook->data = NULL;
+         hook->func = NULL;
          hook->destroy = NULL;
        }
       g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
index 6848d2b..03951b6 100644 (file)
@@ -1112,6 +1112,8 @@ typedef enum
   G_HOOK_FLAG_MASK     = 0x0f
 } GHookFlagMask;
 
+#define        G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
+
 struct _GHookList
 {
   guint                 seq_id;
index 0bcd51a..28ff057 100644 (file)
@@ -400,7 +400,7 @@ g_source_compare (GHook *a,
   return (source_a->priority < source_b->priority) ? -1 : 1;
 }
 
-/* HOLDS: main_loop_lock */
+/* HOLDS: main_loop lock */
 static void
 g_source_destroy_func (GHookList *hook_list,
                       GHook     *hook)
@@ -421,12 +421,6 @@ g_source_destroy_func (GHookList *hook_list,
   G_LOCK (main_loop);
 }
 
-static void
-g_source_noop (GHookList *hook_list,
-              GHook     *hook)
-{
-}
-
 guint 
 g_source_add (gint           priority,
              gboolean       can_recurse,
@@ -441,12 +435,14 @@ g_source_add (gint           priority,
   G_LOCK (main_loop);
 
   if (!source_list.is_setup)
-    g_hook_list_init (&source_list, sizeof(GSource));
+    {
+      g_hook_list_init (&source_list, sizeof (GSource));
 
-  source_list.hook_destroy = g_source_noop;
-  source_list.hook_free = g_source_destroy_func;
+      source_list.hook_destroy = G_HOOK_DEFERRED_DESTROY;
+      source_list.hook_free = g_source_destroy_func;
+    }
 
-  source = (GSource *)g_hook_alloc (&source_list);
+  source = (GSource*) g_hook_alloc (&source_list);
   source->priority = priority;
   source->source_data = source_data;
   source->hook.func = funcs;
diff --git a/gmain.c b/gmain.c
index 0bcd51a..28ff057 100644 (file)
--- a/gmain.c
+++ b/gmain.c
@@ -400,7 +400,7 @@ g_source_compare (GHook *a,
   return (source_a->priority < source_b->priority) ? -1 : 1;
 }
 
-/* HOLDS: main_loop_lock */
+/* HOLDS: main_loop lock */
 static void
 g_source_destroy_func (GHookList *hook_list,
                       GHook     *hook)
@@ -421,12 +421,6 @@ g_source_destroy_func (GHookList *hook_list,
   G_LOCK (main_loop);
 }
 
-static void
-g_source_noop (GHookList *hook_list,
-              GHook     *hook)
-{
-}
-
 guint 
 g_source_add (gint           priority,
              gboolean       can_recurse,
@@ -441,12 +435,14 @@ g_source_add (gint           priority,
   G_LOCK (main_loop);
 
   if (!source_list.is_setup)
-    g_hook_list_init (&source_list, sizeof(GSource));
+    {
+      g_hook_list_init (&source_list, sizeof (GSource));
 
-  source_list.hook_destroy = g_source_noop;
-  source_list.hook_free = g_source_destroy_func;
+      source_list.hook_destroy = G_HOOK_DEFERRED_DESTROY;
+      source_list.hook_free = g_source_destroy_func;
+    }
 
-  source = (GSource *)g_hook_alloc (&source_list);
+  source = (GSource*) g_hook_alloc (&source_list);
   source->priority = priority;
   source->source_data = source_data;
   source->hook.func = funcs;