make the datalists a safe type (not using a generic gpointer) by expecting

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).
This commit is contained in:
Tim Janik 1998-09-18 18:16:49 +00:00 committed by Tim Janik
parent ac3a8ac9a7
commit 4193614b1c
12 changed files with 350 additions and 154 deletions

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View 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> Fri Sep 18 03:41:20 1998 Tim Janik <timj@gtk.org>
* gtree.c (g_tree_new): check for key_compare_func != NULL (reported * gtree.c (g_tree_new): check for key_compare_func != NULL (reported

View File

@ -31,12 +31,11 @@
/* --- structures --- */ /* --- structures --- */
typedef struct _GData GData;
typedef struct _GDataset GDataset; typedef struct _GDataset GDataset;
struct _GData struct _GData
{ {
GData *next; GData *next;
guint id; GQuark id;
gpointer data; gpointer data;
GDestroyNotify destroy_func; GDestroyNotify destroy_func;
}; };
@ -44,19 +43,19 @@ struct _GData
struct _GDataset struct _GDataset
{ {
gconstpointer location; gconstpointer location;
gpointer datalist; GData *datalist;
}; };
/* --- prototypes --- */ /* --- prototypes --- */
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location); static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
static inline void g_datalist_clear_i (gpointer *datalist); static inline void g_datalist_clear_i (GData **datalist);
static void g_dataset_destroy_internal (GDataset *dataset); static void g_dataset_destroy_internal (GDataset *dataset);
static inline void g_data_set_internal (gpointer *datalist, static inline void g_data_set_internal (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func, GDestroyNotify destroy_func,
GDataset *d_dataset); GDataset *dataset);
static void g_data_initialize (void); static void g_data_initialize (void);
static inline GQuark g_quark_new (const gchar *string); static inline GQuark g_quark_new (const gchar *string);
@ -75,7 +74,7 @@ static guint g_data_cache_length = 0;
/* --- functions --- */ /* --- functions --- */
static inline void static inline void
g_datalist_clear_i (gpointer *datalist) g_datalist_clear_i (GData **datalist)
{ {
register GData *list; register GData *list;
@ -106,7 +105,7 @@ g_datalist_clear_i (gpointer *datalist)
} }
void void
g_datalist_clear (gpointer *datalist) g_datalist_clear (GData **datalist)
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
@ -132,27 +131,34 @@ g_dataset_lookup (gconstpointer dataset_location)
static void static void
g_dataset_destroy_internal (GDataset *dataset) g_dataset_destroy_internal (GDataset *dataset)
{ {
gpointer datalist; register gconstpointer dataset_location;
if (dataset == g_dataset_cached) dataset_location = dataset->location;
g_dataset_cached = NULL; while (dataset)
g_hash_table_remove (g_dataset_location_ht, dataset->location); {
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;
}
datalist = dataset->datalist; g_datalist_clear_i (&dataset->datalist);
g_mem_chunk_free (g_dataset_mem_chunk, dataset); dataset = g_dataset_lookup (dataset_location);
}
g_datalist_clear_i (&datalist);
} }
void void
g_dataset_destroy (gconstpointer dataset_location) g_dataset_destroy (gconstpointer dataset_location)
{ {
register GDataset *dataset;
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
if (g_dataset_location_ht) if (g_dataset_location_ht)
{ {
register GDataset *dataset;
dataset = g_dataset_lookup (dataset_location); dataset = g_dataset_lookup (dataset_location);
if (dataset) if (dataset)
g_dataset_destroy_internal (dataset); g_dataset_destroy_internal (dataset);
@ -160,11 +166,11 @@ g_dataset_destroy (gconstpointer dataset_location)
} }
static inline void static inline void
g_data_set_internal (gpointer *datalist, g_data_set_internal (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func, GDestroyNotify destroy_func,
GDataset *d_dataset) GDataset *dataset)
{ {
register GData *list; register GData *list;
@ -187,8 +193,8 @@ g_data_set_internal (gpointer *datalist,
/* the dataset destruction *must* be done /* the dataset destruction *must* be done
* prior to invokation of the data destroy function * prior to invokation of the data destroy function
*/ */
if (!*datalist && d_dataset) if (!*datalist && dataset)
g_dataset_destroy_internal (d_dataset); g_dataset_destroy_internal (dataset);
} }
/* the GData struct *must* already be unlinked /* 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 = g_chunk_new (GDataset, g_dataset_mem_chunk);
dataset->location = dataset_location; dataset->location = dataset_location;
dataset->datalist = NULL; g_datalist_init (&dataset->datalist);
g_hash_table_insert (g_dataset_location_ht, g_hash_table_insert (g_dataset_location_ht,
(gpointer) dataset->location, (gpointer) dataset->location,
dataset); dataset);
@ -297,10 +303,10 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
} }
void void
g_datalist_id_set_data_full (gpointer *datalist, g_datalist_id_set_data_full (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func) GDestroyNotify destroy_func)
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
if (!key_id) if (!key_id)
@ -342,9 +348,9 @@ g_dataset_id_set_destroy (gconstpointer dataset_location,
} }
void void
g_datalist_id_set_destroy (gpointer *datalist, g_datalist_id_set_destroy (GData **datalist,
GQuark key_id, GQuark key_id,
GDestroyNotify destroy_func) GDestroyNotify destroy_func)
{ {
register GData *list; register GData *list;
@ -384,8 +390,8 @@ g_dataset_id_get_data (gconstpointer dataset_location,
} }
gpointer gpointer
g_datalist_id_get_data (gpointer *datalist, g_datalist_id_get_data (GData **datalist,
GQuark key_id) GQuark key_id)
{ {
g_return_val_if_fail (datalist != NULL, NULL); g_return_val_if_fail (datalist != NULL, NULL);
@ -402,7 +408,41 @@ g_datalist_id_get_data (gpointer *datalist,
} }
void 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); g_return_if_fail (datalist != NULL);

86
glib.h
View File

@ -575,27 +575,28 @@ extern const guint glib_binary_age;
/* Forward declarations of glib types. /* 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 _GArray GArray;
typedef struct _GPtrArray GPtrArray;
typedef struct _GByteArray GByteArray; typedef struct _GByteArray GByteArray;
typedef struct _GDebugKey GDebugKey; typedef struct _GCache GCache;
typedef struct _GScannerConfig GScannerConfig;
typedef struct _GScanner GScanner;
typedef union _GValue GValue;
typedef struct _GCompletion GCompletion; typedef struct _GCompletion GCompletion;
typedef struct _GRelation GRelation; typedef struct _GData GData;
typedef struct _GTuples GTuples; 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 _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 union _GValue GValue;
typedef enum typedef enum
@ -649,6 +650,9 @@ typedef gint (*GCompareFunc) (gconstpointer a,
gconstpointer b); gconstpointer b);
typedef gchar* (*GCompletionFunc) (gpointer); typedef gchar* (*GCompletionFunc) (gpointer);
typedef void (*GDestroyNotify) (gpointer data); typedef void (*GDestroyNotify) (gpointer data);
typedef void (*GDataForeachFunc) (GQuark key_id,
gpointer data,
gpointer user_data);
typedef void (*GFunc) (gpointer data, typedef void (*GFunc) (gpointer data,
gpointer user_data); gpointer user_data);
typedef guint (*GHashFunc) (gconstpointer key); typedef guint (*GHashFunc) (gconstpointer key);
@ -1443,17 +1447,20 @@ gchar* g_quark_to_string (GQuark quark);
/* Keyed Data List /* Keyed Data List
*/ */
void g_datalist_init (gpointer *datalist); void g_datalist_init (GData **datalist);
void g_datalist_clear (gpointer *datalist); void g_datalist_clear (GData **datalist);
gpointer g_datalist_id_get_data (gpointer *datalist, gpointer g_datalist_id_get_data (GData **datalist,
GQuark key_id); GQuark key_id);
void g_datalist_id_set_data_full (gpointer *datalist, void g_datalist_id_set_data_full (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_datalist_id_set_destroy (gpointer *datalist, void g_datalist_id_set_destroy (GData **datalist,
GQuark key_id, GQuark key_id,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_datalist_foreach (GData **datalist,
GDataForeachFunc func,
gpointer user_data);
#define g_datalist_id_set_data(dl, q, d) \ #define g_datalist_id_set_data(dl, q, d) \
g_datalist_id_set_data_full ((dl), (q), (d), NULL) g_datalist_id_set_data_full ((dl), (q), (d), NULL)
#define g_datalist_id_remove_data(dl, q) \ #define g_datalist_id_remove_data(dl, q) \
@ -1472,16 +1479,19 @@ void g_datalist_id_set_destroy (gpointer *datalist,
/* Location Associated Keyed Data /* Location Associated Keyed Data
*/ */
void g_dataset_destroy (gconstpointer dataset_location); void g_dataset_destroy (gconstpointer dataset_location);
gpointer g_dataset_id_get_data (gconstpointer dataset_location, gpointer g_dataset_id_get_data (gconstpointer dataset_location,
GQuark key_id); GQuark key_id);
void g_dataset_id_set_data_full (gconstpointer dataset_location, void g_dataset_id_set_data_full (gconstpointer dataset_location,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_dataset_id_set_destroy (gconstpointer dataset_location, void g_dataset_id_set_destroy (gconstpointer dataset_location,
GQuark key_id, GQuark key_id,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_dataset_foreach (gconstpointer dataset_location,
GDataForeachFunc func,
gpointer user_data);
#define g_dataset_id_set_data(l, k, d) \ #define g_dataset_id_set_data(l, k, d) \
g_dataset_id_set_data_full ((l), (k), (d), NULL) g_dataset_id_set_data_full ((l), (k), (d), NULL)
#define g_dataset_id_remove_data(l, k) \ #define g_dataset_id_remove_data(l, k) \

View File

@ -31,12 +31,11 @@
/* --- structures --- */ /* --- structures --- */
typedef struct _GData GData;
typedef struct _GDataset GDataset; typedef struct _GDataset GDataset;
struct _GData struct _GData
{ {
GData *next; GData *next;
guint id; GQuark id;
gpointer data; gpointer data;
GDestroyNotify destroy_func; GDestroyNotify destroy_func;
}; };
@ -44,19 +43,19 @@ struct _GData
struct _GDataset struct _GDataset
{ {
gconstpointer location; gconstpointer location;
gpointer datalist; GData *datalist;
}; };
/* --- prototypes --- */ /* --- prototypes --- */
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location); static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
static inline void g_datalist_clear_i (gpointer *datalist); static inline void g_datalist_clear_i (GData **datalist);
static void g_dataset_destroy_internal (GDataset *dataset); static void g_dataset_destroy_internal (GDataset *dataset);
static inline void g_data_set_internal (gpointer *datalist, static inline void g_data_set_internal (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func, GDestroyNotify destroy_func,
GDataset *d_dataset); GDataset *dataset);
static void g_data_initialize (void); static void g_data_initialize (void);
static inline GQuark g_quark_new (const gchar *string); static inline GQuark g_quark_new (const gchar *string);
@ -75,7 +74,7 @@ static guint g_data_cache_length = 0;
/* --- functions --- */ /* --- functions --- */
static inline void static inline void
g_datalist_clear_i (gpointer *datalist) g_datalist_clear_i (GData **datalist)
{ {
register GData *list; register GData *list;
@ -106,7 +105,7 @@ g_datalist_clear_i (gpointer *datalist)
} }
void void
g_datalist_clear (gpointer *datalist) g_datalist_clear (GData **datalist)
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
@ -132,27 +131,34 @@ g_dataset_lookup (gconstpointer dataset_location)
static void static void
g_dataset_destroy_internal (GDataset *dataset) g_dataset_destroy_internal (GDataset *dataset)
{ {
gpointer datalist; register gconstpointer dataset_location;
if (dataset == g_dataset_cached) dataset_location = dataset->location;
g_dataset_cached = NULL; while (dataset)
g_hash_table_remove (g_dataset_location_ht, dataset->location); {
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;
}
datalist = dataset->datalist; g_datalist_clear_i (&dataset->datalist);
g_mem_chunk_free (g_dataset_mem_chunk, dataset); dataset = g_dataset_lookup (dataset_location);
}
g_datalist_clear_i (&datalist);
} }
void void
g_dataset_destroy (gconstpointer dataset_location) g_dataset_destroy (gconstpointer dataset_location)
{ {
register GDataset *dataset;
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
if (g_dataset_location_ht) if (g_dataset_location_ht)
{ {
register GDataset *dataset;
dataset = g_dataset_lookup (dataset_location); dataset = g_dataset_lookup (dataset_location);
if (dataset) if (dataset)
g_dataset_destroy_internal (dataset); g_dataset_destroy_internal (dataset);
@ -160,11 +166,11 @@ g_dataset_destroy (gconstpointer dataset_location)
} }
static inline void static inline void
g_data_set_internal (gpointer *datalist, g_data_set_internal (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func, GDestroyNotify destroy_func,
GDataset *d_dataset) GDataset *dataset)
{ {
register GData *list; register GData *list;
@ -187,8 +193,8 @@ g_data_set_internal (gpointer *datalist,
/* the dataset destruction *must* be done /* the dataset destruction *must* be done
* prior to invokation of the data destroy function * prior to invokation of the data destroy function
*/ */
if (!*datalist && d_dataset) if (!*datalist && dataset)
g_dataset_destroy_internal (d_dataset); g_dataset_destroy_internal (dataset);
} }
/* the GData struct *must* already be unlinked /* 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 = g_chunk_new (GDataset, g_dataset_mem_chunk);
dataset->location = dataset_location; dataset->location = dataset_location;
dataset->datalist = NULL; g_datalist_init (&dataset->datalist);
g_hash_table_insert (g_dataset_location_ht, g_hash_table_insert (g_dataset_location_ht,
(gpointer) dataset->location, (gpointer) dataset->location,
dataset); dataset);
@ -297,10 +303,10 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
} }
void void
g_datalist_id_set_data_full (gpointer *datalist, g_datalist_id_set_data_full (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func) GDestroyNotify destroy_func)
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
if (!key_id) if (!key_id)
@ -342,9 +348,9 @@ g_dataset_id_set_destroy (gconstpointer dataset_location,
} }
void void
g_datalist_id_set_destroy (gpointer *datalist, g_datalist_id_set_destroy (GData **datalist,
GQuark key_id, GQuark key_id,
GDestroyNotify destroy_func) GDestroyNotify destroy_func)
{ {
register GData *list; register GData *list;
@ -384,8 +390,8 @@ g_dataset_id_get_data (gconstpointer dataset_location,
} }
gpointer gpointer
g_datalist_id_get_data (gpointer *datalist, g_datalist_id_get_data (GData **datalist,
GQuark key_id) GQuark key_id)
{ {
g_return_val_if_fail (datalist != NULL, NULL); g_return_val_if_fail (datalist != NULL, NULL);
@ -402,7 +408,41 @@ g_datalist_id_get_data (gpointer *datalist,
} }
void 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); g_return_if_fail (datalist != NULL);

View File

@ -575,27 +575,28 @@ extern const guint glib_binary_age;
/* Forward declarations of glib types. /* 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 _GArray GArray;
typedef struct _GPtrArray GPtrArray;
typedef struct _GByteArray GByteArray; typedef struct _GByteArray GByteArray;
typedef struct _GDebugKey GDebugKey; typedef struct _GCache GCache;
typedef struct _GScannerConfig GScannerConfig;
typedef struct _GScanner GScanner;
typedef union _GValue GValue;
typedef struct _GCompletion GCompletion; typedef struct _GCompletion GCompletion;
typedef struct _GRelation GRelation; typedef struct _GData GData;
typedef struct _GTuples GTuples; 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 _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 union _GValue GValue;
typedef enum typedef enum
@ -649,6 +650,9 @@ typedef gint (*GCompareFunc) (gconstpointer a,
gconstpointer b); gconstpointer b);
typedef gchar* (*GCompletionFunc) (gpointer); typedef gchar* (*GCompletionFunc) (gpointer);
typedef void (*GDestroyNotify) (gpointer data); typedef void (*GDestroyNotify) (gpointer data);
typedef void (*GDataForeachFunc) (GQuark key_id,
gpointer data,
gpointer user_data);
typedef void (*GFunc) (gpointer data, typedef void (*GFunc) (gpointer data,
gpointer user_data); gpointer user_data);
typedef guint (*GHashFunc) (gconstpointer key); typedef guint (*GHashFunc) (gconstpointer key);
@ -1443,17 +1447,20 @@ gchar* g_quark_to_string (GQuark quark);
/* Keyed Data List /* Keyed Data List
*/ */
void g_datalist_init (gpointer *datalist); void g_datalist_init (GData **datalist);
void g_datalist_clear (gpointer *datalist); void g_datalist_clear (GData **datalist);
gpointer g_datalist_id_get_data (gpointer *datalist, gpointer g_datalist_id_get_data (GData **datalist,
GQuark key_id); GQuark key_id);
void g_datalist_id_set_data_full (gpointer *datalist, void g_datalist_id_set_data_full (GData **datalist,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_datalist_id_set_destroy (gpointer *datalist, void g_datalist_id_set_destroy (GData **datalist,
GQuark key_id, GQuark key_id,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_datalist_foreach (GData **datalist,
GDataForeachFunc func,
gpointer user_data);
#define g_datalist_id_set_data(dl, q, d) \ #define g_datalist_id_set_data(dl, q, d) \
g_datalist_id_set_data_full ((dl), (q), (d), NULL) g_datalist_id_set_data_full ((dl), (q), (d), NULL)
#define g_datalist_id_remove_data(dl, q) \ #define g_datalist_id_remove_data(dl, q) \
@ -1472,16 +1479,19 @@ void g_datalist_id_set_destroy (gpointer *datalist,
/* Location Associated Keyed Data /* Location Associated Keyed Data
*/ */
void g_dataset_destroy (gconstpointer dataset_location); void g_dataset_destroy (gconstpointer dataset_location);
gpointer g_dataset_id_get_data (gconstpointer dataset_location, gpointer g_dataset_id_get_data (gconstpointer dataset_location,
GQuark key_id); GQuark key_id);
void g_dataset_id_set_data_full (gconstpointer dataset_location, void g_dataset_id_set_data_full (gconstpointer dataset_location,
GQuark key_id, GQuark key_id,
gpointer data, gpointer data,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_dataset_id_set_destroy (gconstpointer dataset_location, void g_dataset_id_set_destroy (gconstpointer dataset_location,
GQuark key_id, GQuark key_id,
GDestroyNotify destroy_func); GDestroyNotify destroy_func);
void g_dataset_foreach (gconstpointer dataset_location,
GDataForeachFunc func,
gpointer user_data);
#define g_dataset_id_set_data(l, k, d) \ #define g_dataset_id_set_data(l, k, d) \
g_dataset_id_set_data_full ((l), (k), (d), NULL) g_dataset_id_set_data_full ((l), (k), (d), NULL)
#define g_dataset_id_remove_data(l, k) \ #define g_dataset_id_remove_data(l, k) \