diff --git a/glib/ChangeLog b/glib/ChangeLog index 14b819b9bf..d8f66af73f 100644 --- a/glib/ChangeLog +++ b/glib/ChangeLog @@ -1,3 +1,15 @@ +Wed May 20 05:02:26 1998 Tim Janik + + * glib.h: conditionally define NULL, FALSE and TRUE. + added G_GNUC_FORMAT(), G_GNUC_NORETURN and G_GNUC_CONST macros to + feature more function arguments. + (g_mem_chunk_create): new convenience macro as a short hand for + g_mem_chunk_new(). + (g_chunk_free): new convenience macro to be consistent with g_chunk_new. + + * glist.c: backmerged g_list_nth_data(). + * gslist.c: backmerged g_slist_nth_data(). + Mon May 18 22:14:39 1998 Owen Taylor (Yasuhiro SHIRASAKI : gtk-joke-980517-0.patch) diff --git a/glib/glib.h b/glib/glib.h index 56adc37fe2..f37da5bf26 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -89,16 +89,21 @@ /* Provide definitions for some commonly used macros. + * Some of them are only provided if they haven't already + * been defined. It is assumed that if they are already + * defined then the current definition is correct. */ +#ifndef NULL +#define NULL ((void*) 0) +#endif -#undef NULL -#define NULL ((void*) 0) +#ifndef FALSE +#define FALSE (0) +#endif -#undef FALSE -#define FALSE 0 - -#undef TRUE -#define TRUE 1 +#ifndef TRUE +#define TRUE (!FALSE) +#endif #undef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) @@ -118,7 +123,7 @@ * if (x) G_STMT_START { ... } G_STMT_END; else ... * * For gcc we will wrap the statements within `({' and `})' braces. - * For SunOS they will be wrapped within `if (1)' and `else (void)0', + * For SunOS they will be wrapped within `if (1)' and `else (void) 0', * and otherwise within `do' and `while (0)'. */ #if !(defined (G_STMT_START) && defined (G_STMT_END)) @@ -136,16 +141,25 @@ # endif #endif -/* Provide macros to feature the GCC printf format function attribute. +/* Provide macros to feature the GCC function attribute. */ #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) #define G_GNUC_PRINTF( format_idx, arg_idx ) \ __attribute__((format (printf, format_idx, arg_idx))) #define G_GNUC_SCANF( format_idx, arg_idx ) \ __attribute__((format (scanf, format_idx, arg_idx))) +#define G_GNUC_FORMAT( arg_idx ) \ + __attribute__((format_arg (arg_idx))) +#define G_GNUC_NORETURN \ + __attribute__((noreturn)) +#define G_GNUC_CONST \ + __attribute__((const)) #else /* !__GNUC__ */ #define G_GNUC_PRINTF( format_idx, arg_idx ) #define G_GNUC_SCANF( format_idx, arg_idx ) +#define G_GNUC_FORMAT( arg_idx ) +#define G_GNUC_NORETURN +#define G_GNUC_CONST #endif /* !__GNUC__ */ /* Wrap the __PRETTY_FUNCTION__ and __FUNCTION__ variables with macros, @@ -187,9 +201,18 @@ ((type *) g_malloc0 ((unsigned) sizeof (type) * (count))) #endif /* __DMALLOC_H__ */ -#define g_chunk_new(type, chunk) \ - ((type *) g_mem_chunk_alloc (chunk)) - +#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \ + g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \ + sizeof (type), \ + sizeof (type) * (pre_alloc), \ + (alloc_type)) \ +) +#define g_chunk_new(type, chunk) ( \ + (type *) g_mem_chunk_alloc (chunk) \ +) +#define g_chunk_free(mem, mem_chunk) G_STMT_START { \ + g_mem_chunk_free ((mem_chunk), (mem)); \ +} G_STMT_END #define g_string(x) #x @@ -502,6 +525,8 @@ guint g_list_length (GList *list); void g_list_foreach (GList *list, GFunc func, gpointer user_data); +gpointer g_list_nth_data (GList *list, + guint n); #define g_list_previous(list) ((list) ? (((GList *)list)->prev) : NULL) #define g_list_next(list) ((list) ? (((GList *)list)->next) : NULL) @@ -542,6 +567,8 @@ guint g_slist_length (GSList *list); void g_slist_foreach (GSList *list, GFunc func, gpointer user_data); +gpointer g_slist_nth_data (GSList *list, + guint n); #define g_slist_next(list) ((list) ? (((GSList *)list)->next) : NULL) diff --git a/glib/glist.c b/glib/glist.c index 06cfd54905..a24751cbc3 100644 --- a/glib/glist.c +++ b/glib/glist.c @@ -300,6 +300,16 @@ g_list_nth (GList *list, return list; } +gpointer +g_list_nth_data (GList *list, + guint n) +{ + while ((n-- > 0) && list) + list = list->next; + + return list ? list->data : NULL; +} + GList* g_list_find (GList *list, gpointer data) diff --git a/glib/gslist.c b/glib/gslist.c index e608f131e8..636dd37dc4 100644 --- a/glib/gslist.c +++ b/glib/gslist.c @@ -289,6 +289,16 @@ g_slist_nth (GSList *list, return list; } +gpointer +g_slist_nth_data (GSList *list, + guint n) +{ + while ((n-- > 0) && list) + list = list->next; + + return list ? list->data : NULL; +} + GSList* g_slist_find (GSList *list, gpointer data) diff --git a/glib/gstring.c b/glib/gstring.c index 35346f104b..9cb8d272a9 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -163,14 +163,14 @@ g_string_chunk_insert_const (GStringChunk *fchunk, const gchar *string) { GRealStringChunk *chunk = (GRealStringChunk*) fchunk; - char* lookup; + gchar* lookup; g_return_val_if_fail (chunk != NULL, NULL); if (!chunk->const_table) chunk->const_table = g_hash_table_new (g_str_hash, g_str_equal); - lookup = (char*) g_hash_table_lookup (chunk->const_table, string); + lookup = (gchar*) g_hash_table_lookup (chunk->const_table, (gchar*) string); if (!lookup) {