From 7788ead1376fd75d4798c5602b9ad6b742020570 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 12 Aug 2005 16:09:19 +0000 Subject: [PATCH] Special-case flag value of 0. Instead of returning the first random * gobject/genums.c: (g_flags_get_first_value): Special-case flag value of 0. Instead of returning the first random GFlagsValue we come across, return the GFlagsValue for 0 if it exists or NULL if it does not exist. Never return the GFlagsValue for 0 if the requested flags value is nonzero. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ gobject/genums.c | 17 +++++++++++++---- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c3d2530..f1dd89ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-08-12 Tim-Philipp Müller + + * gobject/genums.c: (g_flags_get_first_value): Special-case flag + value of 0. Instead of returning the first random GFlagsValue + we come across, return the GFlagsValue for 0 if it exists or + NULL if it does not exist. Never return the GFlagsValue for 0 + if the requested flags value is nonzero. + 2005-08-12 Matthias Clasen * configure.in: Bump version to 2.8.0 diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1c3d2530..f1dd89ef 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2005-08-12 Tim-Philipp Müller + + * gobject/genums.c: (g_flags_get_first_value): Special-case flag + value of 0. Instead of returning the first random GFlagsValue + we come across, return the GFlagsValue for 0 if it exists or + NULL if it does not exist. Never return the GFlagsValue for 0 + if the requested flags value is nonzero. + 2005-08-12 Matthias Clasen * configure.in: Bump version to 2.8.0 diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 1c3d2530..f1dd89ef 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2005-08-12 Tim-Philipp Müller + + * gobject/genums.c: (g_flags_get_first_value): Special-case flag + value of 0. Instead of returning the first random GFlagsValue + we come across, return the GFlagsValue for 0 if it exists or + NULL if it does not exist. Never return the GFlagsValue for 0 + if the requested flags value is nonzero. + 2005-08-12 Matthias Clasen * configure.in: Bump version to 2.8.0 diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1c3d2530..f1dd89ef 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2005-08-12 Tim-Philipp Müller + + * gobject/genums.c: (g_flags_get_first_value): Special-case flag + value of 0. Instead of returning the first random GFlagsValue + we come across, return the GFlagsValue for 0 if it exists or + NULL if it does not exist. Never return the GFlagsValue for 0 + if the requested flags value is nonzero. + 2005-08-12 Matthias Clasen * configure.in: Bump version to 2.8.0 diff --git a/gobject/genums.c b/gobject/genums.c index 63ccd939..2ce3dc3b 100644 --- a/gobject/genums.c +++ b/gobject/genums.c @@ -379,10 +379,19 @@ g_flags_get_first_value (GFlagsClass *flags_class, if (flags_class->n_values) { GFlagsValue *flags_value; - - for (flags_value = flags_class->values; flags_value->value_name; flags_value++) - if ((flags_value->value & value) == flags_value->value) - return flags_value; + + if (value == 0) + { + for (flags_value = flags_class->values; flags_value->value_name; flags_value++) + if (flags_value->value == 0) + return flags_value; + } + else + { + for (flags_value = flags_class->values; flags_value->value_name; flags_value++) + if (flags_value->value != 0 && (flags_value->value & value) == flags_value->value) + return flags_value; + } } return NULL; -- 2.34.1