make the datalists a safe type (not using a generic gpointer) by expecting
authorTim Janik <timj@gtk.org>
Fri, 18 Sep 1998 18:16:49 +0000 (18:16 +0000)
committerTim Janik <timj@src.gnome.org>
Fri, 18 Sep 1998 18:16:49 +0000 (18:16 +0000)
Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>

        * glib.h:
        * gdataset.c: make the datalists a safe type (not using a generic
        gpointer) by expecting a GData* argument in the g_datalist functions.
        provide g_dataset_foreach() and g_datalist_foreach() functions that
        allow a GDataForeachFunc function to walk the data lists.
        (g_dataset_destroy_internal): made this function truely reentrant (i.e.
        can be called from within destroy notifiers as well).
        the *_foreach functions are _not_ reentrant (unless all the other
        dataset and datalist functions).

12 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
gdataset.c
glib.h
glib/gdataset.c
glib/glib.h

index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 191fea97c086d088ea534e3bf586e1a9f9294394..84690abb04f071791ae35192c546dbe833b03823 100644 (file)
@@ -1,3 +1,15 @@
+Fri Sep 18 18:46:14 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h:
+       * gdataset.c: make the datalists a safe type (not using a generic
+       gpointer) by expecting a GData* argument in the g_datalist functions.
+       provide g_dataset_foreach() and g_datalist_foreach() functions that
+       allow a GDataForeachFunc function to walk the data lists.
+       (g_dataset_destroy_internal): made this function truely reentrant (i.e.
+       can be called from within destroy notifiers as well).
+       the *_foreach functions are _not_ reentrant (unless all the other
+       dataset and datalist functions).
+
 Fri Sep 18 03:41:20 1998  Tim Janik  <timj@gtk.org>
 
        * gtree.c (g_tree_new): check for key_compare_func != NULL (reported
index 904d31ab2112a999a121dbc58ee3d80f768e2c9d..cb0ad03234b3d73e4afb471f30d9b25ecdfc720d 100644 (file)
 
 
 /* --- structures --- */
-typedef struct _GData GData;
 typedef struct _GDataset GDataset;
 struct _GData
 {
   GData *next;
-  guint id;
+  GQuark id;
   gpointer data;
   GDestroyNotify destroy_func;
 };
@@ -44,19 +43,19 @@ struct _GData
 struct _GDataset
 {
   gconstpointer location;
-  gpointer datalist;
+  GData        *datalist;
 };
 
 
 /* --- prototypes --- */
-static inline GDataset*        g_dataset_lookup                (gconstpointer   dataset_location);
-static inline void     g_datalist_clear_i              (gpointer       *datalist);
-static void            g_dataset_destroy_internal      (GDataset       *dataset);
-static inline void     g_data_set_internal             (gpointer       *datalist,
-                                                        GQuark          key_id,
-                                                        gpointer        data,
-                                                        GDestroyNotify  destroy_func,
-                                                        GDataset       *d_dataset);
+static inline GDataset*        g_dataset_lookup                (gconstpointer    dataset_location);
+static inline void     g_datalist_clear_i              (GData          **datalist);
+static void            g_dataset_destroy_internal      (GDataset        *dataset);
+static inline void     g_data_set_internal             (GData          **datalist,
+                                                        GQuark           key_id,
+                                                        gpointer         data,
+                                                        GDestroyNotify   destroy_func,
+                                                        GDataset        *dataset);
 static void            g_data_initialize               (void);
 static inline GQuark   g_quark_new                     (const gchar    *string);
 
@@ -75,7 +74,7 @@ static guint       g_data_cache_length = 0;
 
 /* --- functions --- */
 static inline void
-g_datalist_clear_i (gpointer *datalist)
+g_datalist_clear_i (GData **datalist)
 {
   register GData *list;
   
@@ -106,7 +105,7 @@ g_datalist_clear_i (gpointer *datalist)
 }
 
 void
-g_datalist_clear (gpointer       *datalist)
+g_datalist_clear (GData **datalist)
 {
   g_return_if_fail (datalist != NULL);
   
@@ -132,27 +131,34 @@ g_dataset_lookup (gconstpointer   dataset_location)
 static void
 g_dataset_destroy_internal (GDataset *dataset)
 {
-  gpointer datalist;
+  register gconstpointer dataset_location;
   
-  if (dataset == g_dataset_cached)
-    g_dataset_cached = NULL;
-  g_hash_table_remove (g_dataset_location_ht, dataset->location);
-  
-  datalist = dataset->datalist;
-  g_mem_chunk_free (g_dataset_mem_chunk, dataset);
-  
-  g_datalist_clear_i (&datalist);
+  dataset_location = dataset->location;
+  while (dataset)
+    {
+      if (!dataset->datalist)
+       {
+         if (dataset == g_dataset_cached)
+           g_dataset_cached = NULL;
+         g_hash_table_remove (g_dataset_location_ht, dataset_location);
+         g_mem_chunk_free (g_dataset_mem_chunk, dataset);
+         break;
+       }
+      
+      g_datalist_clear_i (&dataset->datalist);
+      dataset = g_dataset_lookup (dataset_location);
+    }
 }
 
 void
 g_dataset_destroy (gconstpointer  dataset_location)
 {
-  register GDataset *dataset;
-  
   g_return_if_fail (dataset_location != NULL);
   
   if (g_dataset_location_ht)
     {
+      register GDataset *dataset;
+
       dataset = g_dataset_lookup (dataset_location);
       if (dataset)
        g_dataset_destroy_internal (dataset);
@@ -160,11 +166,11 @@ g_dataset_destroy (gconstpointer  dataset_location)
 }
 
 static inline void
-g_data_set_internal (gpointer      *datalist,
+g_data_set_internal (GData       **datalist,
                     GQuark         key_id,
                     gpointer       data,
                     GDestroyNotify destroy_func,
-                    GDataset      *d_dataset)
+                    GDataset      *dataset)
 {
   register GData *list;
   
@@ -187,8 +193,8 @@ g_data_set_internal (gpointer      *datalist,
                  /* the dataset destruction *must* be done
                   * prior to invokation of the data destroy function
                   */
-                 if (!*datalist && d_dataset)
-                   g_dataset_destroy_internal (d_dataset);
+                 if (!*datalist && dataset)
+                   g_dataset_destroy_internal (dataset);
                }
              
              /* the GData struct *must* already be unlinked
@@ -287,7 +293,7 @@ g_dataset_id_set_data_full (gconstpointer  dataset_location,
     {
       dataset = g_chunk_new (GDataset, g_dataset_mem_chunk);
       dataset->location = dataset_location;
-      dataset->datalist = NULL;
+      g_datalist_init (&dataset->datalist);
       g_hash_table_insert (g_dataset_location_ht, 
                           (gpointer) dataset->location,
                           dataset);
@@ -297,10 +303,10 @@ g_dataset_id_set_data_full (gconstpointer  dataset_location,
 }
 
 void
-g_datalist_id_set_data_full (gpointer       *datalist,
-                            GQuark          key_id,
-                            gpointer        data,
-                            GDestroyNotify  destroy_func)
+g_datalist_id_set_data_full (GData       **datalist,
+                            GQuark         key_id,
+                            gpointer       data,
+                            GDestroyNotify destroy_func)
 {
   g_return_if_fail (datalist != NULL);
   if (!key_id)
@@ -342,9 +348,9 @@ g_dataset_id_set_destroy (gconstpointer  dataset_location,
 }
 
 void
-g_datalist_id_set_destroy (gpointer       *datalist,
-                          GQuark          key_id,
-                          GDestroyNotify  destroy_func)
+g_datalist_id_set_destroy (GData       **datalist,
+                          GQuark         key_id,
+                          GDestroyNotify destroy_func)
 {
   register GData *list;
   
@@ -384,8 +390,8 @@ g_dataset_id_get_data (gconstpointer  dataset_location,
 }
 
 gpointer
-g_datalist_id_get_data (gpointer *datalist,
-                       GQuark    key_id)
+g_datalist_id_get_data (GData   **datalist,
+                       GQuark     key_id)
 {
   g_return_val_if_fail (datalist != NULL, NULL);
   
@@ -402,7 +408,41 @@ g_datalist_id_get_data (gpointer *datalist,
 }
 
 void
-g_datalist_init (gpointer       *datalist)
+g_dataset_foreach (gconstpointer    dataset_location,
+                  GDataForeachFunc func,
+                  gpointer         user_data)
+{
+  register GDataset *dataset;
+  
+  g_return_if_fail (dataset_location != NULL);
+  g_return_if_fail (func != NULL);
+  
+  dataset = g_dataset_lookup (dataset_location);
+  if (dataset)
+    {
+      register GData *list;
+      
+      for (list = dataset->datalist; list; list = list->next)
+       func (list->id, list->data, user_data);
+    }
+}
+
+void
+g_datalist_foreach (GData         **datalist,
+                   GDataForeachFunc func,
+                   gpointer         user_data)
+{
+  register GData *list;
+
+  g_return_if_fail (datalist != NULL);
+  g_return_if_fail (func != NULL);
+  
+  for (list = *datalist; list; list = list->next)
+    func (list->id, list->data, user_data);
+}
+
+void
+g_datalist_init (GData **datalist)
 {
   g_return_if_fail (datalist != NULL);
   
diff --git a/glib.h b/glib.h
index 0512e8b66adab43dce57d573f8094de34a3cbc86..f9725b6cfbe4cb86e049253d8b64cc99ec12a539 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -575,27 +575,28 @@ extern const guint glib_binary_age;
 /* Forward declarations of glib types.
  */
 
-typedef struct _GList          GList;
-typedef struct _GSList         GSList;
-typedef struct _GHashTable     GHashTable;
-typedef struct _GCache         GCache;
-typedef struct _GTree          GTree;
-typedef struct _GTimer         GTimer;
-typedef struct _GMemChunk      GMemChunk;
-typedef struct _GListAllocator GListAllocator;
-typedef struct _GStringChunk   GStringChunk;
-typedef struct _GString                GString;
 typedef struct _GArray         GArray;
-typedef struct _GPtrArray      GPtrArray;
 typedef struct _GByteArray     GByteArray;
-typedef struct _GDebugKey      GDebugKey;
-typedef struct _GScannerConfig GScannerConfig;
-typedef struct _GScanner       GScanner;
-typedef union  _GValue         GValue;
+typedef struct _GCache         GCache;
 typedef struct _GCompletion    GCompletion;
+typedef        struct _GData           GData;
+typedef struct _GDebugKey      GDebugKey;
+typedef struct _GHashTable     GHashTable;
+typedef struct _GList          GList;
+typedef struct _GListAllocator GListAllocator;
+typedef struct _GMemChunk      GMemChunk;
+typedef struct _GNode          GNode;
+typedef struct _GPtrArray      GPtrArray;
 typedef struct _GRelation      GRelation;
+typedef struct _GScanner       GScanner;
+typedef struct _GScannerConfig GScannerConfig;
+typedef struct _GSList         GSList;
+typedef struct _GString                GString;
+typedef struct _GStringChunk   GStringChunk;
+typedef struct _GTimer         GTimer;
+typedef struct _GTree          GTree;
 typedef struct _GTuples                GTuples;
-typedef struct _GNode          GNode;
+typedef union  _GValue         GValue;
 
 
 typedef enum
@@ -649,6 +650,9 @@ typedef gint                (*GCompareFunc)         (gconstpointer  a,
                                                 gconstpointer  b);
 typedef gchar*         (*GCompletionFunc)      (gpointer);
 typedef void           (*GDestroyNotify)       (gpointer       data);
+typedef void           (*GDataForeachFunc)     (GQuark         key_id,
+                                                gpointer       data,
+                                                gpointer       user_data);
 typedef void           (*GFunc)                (gpointer       data,
                                                 gpointer       user_data);
 typedef guint          (*GHashFunc)            (gconstpointer  key);
@@ -1443,17 +1447,20 @@ gchar*    g_quark_to_string             (GQuark          quark);
 
 /* Keyed Data List
  */
-void     g_datalist_init               (gpointer       *datalist);
-void     g_datalist_clear              (gpointer       *datalist);
-gpointer  g_datalist_id_get_data       (gpointer       *datalist,
-                                        GQuark          key_id);
-void     g_datalist_id_set_data_full   (gpointer       *datalist,
-                                        GQuark          key_id,
-                                        gpointer        data,
-                                        GDestroyNotify  destroy_func);
-void     g_datalist_id_set_destroy     (gpointer       *datalist,
-                                        GQuark          key_id,
-                                        GDestroyNotify  destroy_func);
+void     g_datalist_init               (GData          **datalist);
+void     g_datalist_clear              (GData          **datalist);
+gpointer  g_datalist_id_get_data       (GData          **datalist,
+                                        GQuark           key_id);
+void     g_datalist_id_set_data_full   (GData          **datalist,
+                                        GQuark           key_id,
+                                        gpointer         data,
+                                        GDestroyNotify   destroy_func);
+void     g_datalist_id_set_destroy     (GData          **datalist,
+                                        GQuark           key_id,
+                                        GDestroyNotify   destroy_func);
+void     g_datalist_foreach            (GData          **datalist,
+                                        GDataForeachFunc func,
+                                        gpointer         user_data);
 #define          g_datalist_id_set_data(dl, q, d)      \
      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
 #define          g_datalist_id_remove_data(dl, q)      \
@@ -1472,16 +1479,19 @@ void      g_datalist_id_set_destroy     (gpointer       *datalist,
 
 /* Location Associated Keyed Data
  */
-void     g_dataset_destroy             (gconstpointer   dataset_location);
-gpointer  g_dataset_id_get_data                (gconstpointer   dataset_location,
-                                        GQuark          key_id);
-void     g_dataset_id_set_data_full    (gconstpointer   dataset_location,
-                                        GQuark          key_id,
-                                        gpointer        data,
-                                        GDestroyNotify  destroy_func);
-void     g_dataset_id_set_destroy      (gconstpointer   dataset_location,
-                                        GQuark          key_id,
-                                        GDestroyNotify  destroy_func);
+void     g_dataset_destroy             (gconstpointer    dataset_location);
+gpointer  g_dataset_id_get_data                (gconstpointer    dataset_location,
+                                        GQuark           key_id);
+void     g_dataset_id_set_data_full    (gconstpointer    dataset_location,
+                                        GQuark           key_id,
+                                        gpointer         data,
+                                        GDestroyNotify   destroy_func);
+void     g_dataset_id_set_destroy      (gconstpointer    dataset_location,
+                                        GQuark           key_id,
+                                        GDestroyNotify   destroy_func);
+void     g_dataset_foreach             (gconstpointer    dataset_location,
+                                        GDataForeachFunc func,
+                                        gpointer         user_data);
 #define          g_dataset_id_set_data(l, k, d)        \
      g_dataset_id_set_data_full ((l), (k), (d), NULL)
 #define          g_dataset_id_remove_data(l, k)        \
index 904d31ab2112a999a121dbc58ee3d80f768e2c9d..cb0ad03234b3d73e4afb471f30d9b25ecdfc720d 100644 (file)
 
 
 /* --- structures --- */
-typedef struct _GData GData;
 typedef struct _GDataset GDataset;
 struct _GData
 {
   GData *next;
-  guint id;
+  GQuark id;
   gpointer data;
   GDestroyNotify destroy_func;
 };
@@ -44,19 +43,19 @@ struct _GData
 struct _GDataset
 {
   gconstpointer location;
-  gpointer datalist;
+  GData        *datalist;
 };
 
 
 /* --- prototypes --- */
-static inline GDataset*        g_dataset_lookup                (gconstpointer   dataset_location);
-static inline void     g_datalist_clear_i              (gpointer       *datalist);
-static void            g_dataset_destroy_internal      (GDataset       *dataset);
-static inline void     g_data_set_internal             (gpointer       *datalist,
-                                                        GQuark          key_id,
-                                                        gpointer        data,
-                                                        GDestroyNotify  destroy_func,
-                                                        GDataset       *d_dataset);
+static inline GDataset*        g_dataset_lookup                (gconstpointer    dataset_location);
+static inline void     g_datalist_clear_i              (GData          **datalist);
+static void            g_dataset_destroy_internal      (GDataset        *dataset);
+static inline void     g_data_set_internal             (GData          **datalist,
+                                                        GQuark           key_id,
+                                                        gpointer         data,
+                                                        GDestroyNotify   destroy_func,
+                                                        GDataset        *dataset);
 static void            g_data_initialize               (void);
 static inline GQuark   g_quark_new                     (const gchar    *string);
 
@@ -75,7 +74,7 @@ static guint       g_data_cache_length = 0;
 
 /* --- functions --- */
 static inline void
-g_datalist_clear_i (gpointer *datalist)
+g_datalist_clear_i (GData **datalist)
 {
   register GData *list;
   
@@ -106,7 +105,7 @@ g_datalist_clear_i (gpointer *datalist)
 }
 
 void
-g_datalist_clear (gpointer       *datalist)
+g_datalist_clear (GData **datalist)
 {
   g_return_if_fail (datalist != NULL);
   
@@ -132,27 +131,34 @@ g_dataset_lookup (gconstpointer   dataset_location)
 static void
 g_dataset_destroy_internal (GDataset *dataset)
 {
-  gpointer datalist;
+  register gconstpointer dataset_location;
   
-  if (dataset == g_dataset_cached)
-    g_dataset_cached = NULL;
-  g_hash_table_remove (g_dataset_location_ht, dataset->location);
-  
-  datalist = dataset->datalist;
-  g_mem_chunk_free (g_dataset_mem_chunk, dataset);
-  
-  g_datalist_clear_i (&datalist);
+  dataset_location = dataset->location;
+  while (dataset)
+    {
+      if (!dataset->datalist)
+       {
+         if (dataset == g_dataset_cached)
+           g_dataset_cached = NULL;
+         g_hash_table_remove (g_dataset_location_ht, dataset_location);
+         g_mem_chunk_free (g_dataset_mem_chunk, dataset);
+         break;
+       }
+      
+      g_datalist_clear_i (&dataset->datalist);
+      dataset = g_dataset_lookup (dataset_location);
+    }
 }
 
 void
 g_dataset_destroy (gconstpointer  dataset_location)
 {
-  register GDataset *dataset;
-  
   g_return_if_fail (dataset_location != NULL);
   
   if (g_dataset_location_ht)
     {
+      register GDataset *dataset;
+
       dataset = g_dataset_lookup (dataset_location);
       if (dataset)
        g_dataset_destroy_internal (dataset);
@@ -160,11 +166,11 @@ g_dataset_destroy (gconstpointer  dataset_location)
 }
 
 static inline void
-g_data_set_internal (gpointer      *datalist,
+g_data_set_internal (GData       **datalist,
                     GQuark         key_id,
                     gpointer       data,
                     GDestroyNotify destroy_func,
-                    GDataset      *d_dataset)
+                    GDataset      *dataset)
 {
   register GData *list;
   
@@ -187,8 +193,8 @@ g_data_set_internal (gpointer      *datalist,
                  /* the dataset destruction *must* be done
                   * prior to invokation of the data destroy function
                   */
-                 if (!*datalist && d_dataset)
-                   g_dataset_destroy_internal (d_dataset);
+                 if (!*datalist && dataset)
+                   g_dataset_destroy_internal (dataset);
                }
              
              /* the GData struct *must* already be unlinked
@@ -287,7 +293,7 @@ g_dataset_id_set_data_full (gconstpointer  dataset_location,
     {
       dataset = g_chunk_new (GDataset, g_dataset_mem_chunk);
       dataset->location = dataset_location;
-      dataset->datalist = NULL;
+      g_datalist_init (&dataset->datalist);
       g_hash_table_insert (g_dataset_location_ht, 
                           (gpointer) dataset->location,
                           dataset);
@@ -297,10 +303,10 @@ g_dataset_id_set_data_full (gconstpointer  dataset_location,
 }
 
 void
-g_datalist_id_set_data_full (gpointer       *datalist,
-                            GQuark          key_id,
-                            gpointer        data,
-                            GDestroyNotify  destroy_func)
+g_datalist_id_set_data_full (GData       **datalist,
+                            GQuark         key_id,
+                            gpointer       data,
+                            GDestroyNotify destroy_func)
 {
   g_return_if_fail (datalist != NULL);
   if (!key_id)
@@ -342,9 +348,9 @@ g_dataset_id_set_destroy (gconstpointer  dataset_location,
 }
 
 void
-g_datalist_id_set_destroy (gpointer       *datalist,
-                          GQuark          key_id,
-                          GDestroyNotify  destroy_func)
+g_datalist_id_set_destroy (GData       **datalist,
+                          GQuark         key_id,
+                          GDestroyNotify destroy_func)
 {
   register GData *list;
   
@@ -384,8 +390,8 @@ g_dataset_id_get_data (gconstpointer  dataset_location,
 }
 
 gpointer
-g_datalist_id_get_data (gpointer *datalist,
-                       GQuark    key_id)
+g_datalist_id_get_data (GData   **datalist,
+                       GQuark     key_id)
 {
   g_return_val_if_fail (datalist != NULL, NULL);
   
@@ -402,7 +408,41 @@ g_datalist_id_get_data (gpointer *datalist,
 }
 
 void
-g_datalist_init (gpointer       *datalist)
+g_dataset_foreach (gconstpointer    dataset_location,
+                  GDataForeachFunc func,
+                  gpointer         user_data)
+{
+  register GDataset *dataset;
+  
+  g_return_if_fail (dataset_location != NULL);
+  g_return_if_fail (func != NULL);
+  
+  dataset = g_dataset_lookup (dataset_location);
+  if (dataset)
+    {
+      register GData *list;
+      
+      for (list = dataset->datalist; list; list = list->next)
+       func (list->id, list->data, user_data);
+    }
+}
+
+void
+g_datalist_foreach (GData         **datalist,
+                   GDataForeachFunc func,
+                   gpointer         user_data)
+{
+  register GData *list;
+
+  g_return_if_fail (datalist != NULL);
+  g_return_if_fail (func != NULL);
+  
+  for (list = *datalist; list; list = list->next)
+    func (list->id, list->data, user_data);
+}
+
+void
+g_datalist_init (GData **datalist)
 {
   g_return_if_fail (datalist != NULL);
   
index 0512e8b66adab43dce57d573f8094de34a3cbc86..f9725b6cfbe4cb86e049253d8b64cc99ec12a539 100644 (file)
@@ -575,27 +575,28 @@ extern const guint glib_binary_age;
 /* Forward declarations of glib types.
  */
 
-typedef struct _GList          GList;
-typedef struct _GSList         GSList;
-typedef struct _GHashTable     GHashTable;
-typedef struct _GCache         GCache;
-typedef struct _GTree          GTree;
-typedef struct _GTimer         GTimer;
-typedef struct _GMemChunk      GMemChunk;
-typedef struct _GListAllocator GListAllocator;
-typedef struct _GStringChunk   GStringChunk;
-typedef struct _GString                GString;
 typedef struct _GArray         GArray;
-typedef struct _GPtrArray      GPtrArray;
 typedef struct _GByteArray     GByteArray;
-typedef struct _GDebugKey      GDebugKey;
-typedef struct _GScannerConfig GScannerConfig;
-typedef struct _GScanner       GScanner;
-typedef union  _GValue         GValue;
+typedef struct _GCache         GCache;
 typedef struct _GCompletion    GCompletion;
+typedef        struct _GData           GData;
+typedef struct _GDebugKey      GDebugKey;
+typedef struct _GHashTable     GHashTable;
+typedef struct _GList          GList;
+typedef struct _GListAllocator GListAllocator;
+typedef struct _GMemChunk      GMemChunk;
+typedef struct _GNode          GNode;
+typedef struct _GPtrArray      GPtrArray;
 typedef struct _GRelation      GRelation;
+typedef struct _GScanner       GScanner;
+typedef struct _GScannerConfig GScannerConfig;
+typedef struct _GSList         GSList;
+typedef struct _GString                GString;
+typedef struct _GStringChunk   GStringChunk;
+typedef struct _GTimer         GTimer;
+typedef struct _GTree          GTree;
 typedef struct _GTuples                GTuples;
-typedef struct _GNode          GNode;
+typedef union  _GValue         GValue;
 
 
 typedef enum
@@ -649,6 +650,9 @@ typedef gint                (*GCompareFunc)         (gconstpointer  a,
                                                 gconstpointer  b);
 typedef gchar*         (*GCompletionFunc)      (gpointer);
 typedef void           (*GDestroyNotify)       (gpointer       data);
+typedef void           (*GDataForeachFunc)     (GQuark         key_id,
+                                                gpointer       data,
+                                                gpointer       user_data);
 typedef void           (*GFunc)                (gpointer       data,
                                                 gpointer       user_data);
 typedef guint          (*GHashFunc)            (gconstpointer  key);
@@ -1443,17 +1447,20 @@ gchar*    g_quark_to_string             (GQuark          quark);
 
 /* Keyed Data List
  */
-void     g_datalist_init               (gpointer       *datalist);
-void     g_datalist_clear              (gpointer       *datalist);
-gpointer  g_datalist_id_get_data       (gpointer       *datalist,
-                                        GQuark          key_id);
-void     g_datalist_id_set_data_full   (gpointer       *datalist,
-                                        GQuark          key_id,
-                                        gpointer        data,
-                                        GDestroyNotify  destroy_func);
-void     g_datalist_id_set_destroy     (gpointer       *datalist,
-                                        GQuark          key_id,
-                                        GDestroyNotify  destroy_func);
+void     g_datalist_init               (GData          **datalist);
+void     g_datalist_clear              (GData          **datalist);
+gpointer  g_datalist_id_get_data       (GData          **datalist,
+                                        GQuark           key_id);
+void     g_datalist_id_set_data_full   (GData          **datalist,
+                                        GQuark           key_id,
+                                        gpointer         data,
+                                        GDestroyNotify   destroy_func);
+void     g_datalist_id_set_destroy     (GData          **datalist,
+                                        GQuark           key_id,
+                                        GDestroyNotify   destroy_func);
+void     g_datalist_foreach            (GData          **datalist,
+                                        GDataForeachFunc func,
+                                        gpointer         user_data);
 #define          g_datalist_id_set_data(dl, q, d)      \
      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
 #define          g_datalist_id_remove_data(dl, q)      \
@@ -1472,16 +1479,19 @@ void      g_datalist_id_set_destroy     (gpointer       *datalist,
 
 /* Location Associated Keyed Data
  */
-void     g_dataset_destroy             (gconstpointer   dataset_location);
-gpointer  g_dataset_id_get_data                (gconstpointer   dataset_location,
-                                        GQuark          key_id);
-void     g_dataset_id_set_data_full    (gconstpointer   dataset_location,
-                                        GQuark          key_id,
-                                        gpointer        data,
-                                        GDestroyNotify  destroy_func);
-void     g_dataset_id_set_destroy      (gconstpointer   dataset_location,
-                                        GQuark          key_id,
-                                        GDestroyNotify  destroy_func);
+void     g_dataset_destroy             (gconstpointer    dataset_location);
+gpointer  g_dataset_id_get_data                (gconstpointer    dataset_location,
+                                        GQuark           key_id);
+void     g_dataset_id_set_data_full    (gconstpointer    dataset_location,
+                                        GQuark           key_id,
+                                        gpointer         data,
+                                        GDestroyNotify   destroy_func);
+void     g_dataset_id_set_destroy      (gconstpointer    dataset_location,
+                                        GQuark           key_id,
+                                        GDestroyNotify   destroy_func);
+void     g_dataset_foreach             (gconstpointer    dataset_location,
+                                        GDataForeachFunc func,
+                                        gpointer         user_data);
 #define          g_dataset_id_set_data(l, k, d)        \
      g_dataset_id_set_data_full ((l), (k), (d), NULL)
 #define          g_dataset_id_remove_data(l, k)        \