From acc6a1aa605f2725cac5a541417272cecc8e98c4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 14 May 2004 13:37:07 +0000 Subject: [PATCH] Add a comment about unused bits. 2004-05-14 Matthias Clasen * gdk/gdktypes.h (GdkModifierType): Add a comment about unused bits. * gtk/gtkstock.c (real_add, gtk_stock_lookup): Use an unused modifier bit to mark stock item which need to be freed eventually. (#140654, Michal Pasternak, Scott Tsai) --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ gdk/gdktypes.h | 4 +++- gtk/gtkstock.c | 21 +++++++++++++++++++-- 6 files changed, 58 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ccaf3175c..34fe2cf028 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-05-14 Matthias Clasen + + * gdk/gdktypes.h (GdkModifierType): Add a comment about unused + bits. + + * gtk/gtkstock.c (real_add, gtk_stock_lookup): Use an unused + modifier bit to mark stock item which need to be freed + eventually. (#140654, Michal Pasternak, Scott Tsai) + 2004-05-11 Robert Ögren * gdk/win32/gdkevents-win32.c (gdk_event_translate): Add missing diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7ccaf3175c..34fe2cf028 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2004-05-14 Matthias Clasen + + * gdk/gdktypes.h (GdkModifierType): Add a comment about unused + bits. + + * gtk/gtkstock.c (real_add, gtk_stock_lookup): Use an unused + modifier bit to mark stock item which need to be freed + eventually. (#140654, Michal Pasternak, Scott Tsai) + 2004-05-11 Robert Ögren * gdk/win32/gdkevents-win32.c (gdk_event_translate): Add missing diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 7ccaf3175c..34fe2cf028 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +2004-05-14 Matthias Clasen + + * gdk/gdktypes.h (GdkModifierType): Add a comment about unused + bits. + + * gtk/gtkstock.c (real_add, gtk_stock_lookup): Use an unused + modifier bit to mark stock item which need to be freed + eventually. (#140654, Michal Pasternak, Scott Tsai) + 2004-05-11 Robert Ögren * gdk/win32/gdkevents-win32.c (gdk_event_translate): Add missing diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 7ccaf3175c..34fe2cf028 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +2004-05-14 Matthias Clasen + + * gdk/gdktypes.h (GdkModifierType): Add a comment about unused + bits. + + * gtk/gtkstock.c (real_add, gtk_stock_lookup): Use an unused + modifier bit to mark stock item which need to be freed + eventually. (#140654, Michal Pasternak, Scott Tsai) + 2004-05-11 Robert Ögren * gdk/win32/gdkevents-win32.c (gdk_event_translate): Add missing diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index c454cae80a..d9fdcd6ec1 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -130,7 +130,9 @@ typedef enum GDK_BUTTON3_MASK = 1 << 10, GDK_BUTTON4_MASK = 1 << 11, GDK_BUTTON5_MASK = 1 << 12, - /* The next few modifiers are used by XKB, so we skip to the end + /* The next few modifiers are used by XKB, so we skip to the end. + * Bits 16 - 28 are currently unused, but will eventually + * be used for "virtual modifiers". Bit 29 is used internally. */ GDK_RELEASE_MASK = 1 << 30, GDK_MODIFIER_MASK = GDK_RELEASE_MASK | 0x1fff diff --git a/gtk/gtkstock.c b/gtk/gtkstock.c index 5aea0eabaa..6bf445190e 100644 --- a/gtk/gtkstock.c +++ b/gtk/gtkstock.c @@ -35,6 +35,11 @@ static GHashTable *stock_hash = NULL; static void init_stock_hash (void); +/* We use an unused modifier bit to mark stock items which + * must be freed when they are removed from the hash table. + */ +#define NON_STATIC_MASK (1 << 29) + static void real_add (const GtkStockItem *items, guint n_items, @@ -52,14 +57,25 @@ real_add (const GtkStockItem *items, { gpointer old_key, old_value; const GtkStockItem *item = &items[i]; + + if (item->modifier & NON_STATIC_MASK) + { + g_warning ("Bit 29 set in stock accelerator.\n"); + copy = TRUE; + } + if (copy) - item = gtk_stock_item_copy (item); + { + item = gtk_stock_item_copy (item); + ((GtkStockItem *)item)->modifier |= NON_STATIC_MASK; + } if (g_hash_table_lookup_extended (stock_hash, item->stock_id, &old_key, &old_value)) { g_hash_table_remove (stock_hash, old_key); - gtk_stock_item_free (old_value); + if (((GtkStockItem *)old_value)->modifier & NON_STATIC_MASK) + gtk_stock_item_free (old_value); } g_hash_table_insert (stock_hash, @@ -136,6 +152,7 @@ gtk_stock_lookup (const gchar *stock_id, if (found) { *item = *found; + item->modifier &= ~NON_STATIC_MASK; if (item->label) item->label = dgettext (item->translation_domain, item->label); }