After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 397125 - g_enum_get_value should return const
g_enum_get_value should return const
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-01-16 04:28 UTC by Behdad Esfahbod
Modified: 2017-09-11 21:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Bug 397125 — g_enum_get_value should return const (4.14 KB, patch)
2010-04-01 01:09 UTC, Philip Withnall
needs-work Details | Review
Bug 397125 — g_enum_get_value should return const (updated) (4.80 KB, patch)
2012-03-24 22:49 UTC, Philip Withnall
rejected Details | Review

Description Behdad Esfahbod 2007-01-16 04:28:24 UTC
g_enum_get_value and g_flag_get_value should return a "const GEnumValue *" and "const GFlagValue *" respectively.  Moreover, document the return value as belonging to glib and should not be freed...  Or, available as long as the type is available, or something...
Comment 1 Philip Withnall 2010-04-01 01:09:21 UTC
Created attachment 157656 [details] [review]
Bug 397125 — g_enum_get_value should return const

Add a G_CONST_RETURN attribute to g_enum_get_value(),
g_enum_get_value_by_name(), g_enum_get_value_by_nick(),
g_flags_get_first_value(), g_flags_get_value_by_name() and
g_flags_get_value_by_nick(). Closes: bgo#397125
Comment 2 Philip Withnall 2010-04-01 01:10:36 UTC
I don't think the documentation changes are necessary, since the returned values can't be freed or modified if they're const. No other GLib functions seem to specify that const returns shouldn't be freed, anyway.
Comment 3 Marc-Andre Lureau 2012-03-12 22:27:13 UTC
+1, patch looks ok, although people might have to fix their code.
Comment 4 Javier Jardón (IRC: jjardon) 2012-03-12 23:35:05 UTC
Review of attachment 157656 [details] [review]:

Not a Glib maintainer, but G_CONST_RETURN is deprecated, use const directly instead
Comment 5 Philip Withnall 2012-03-24 22:49:50 UTC
Created attachment 210539 [details] [review]
Bug 397125 — g_enum_get_value should return const (updated)

Updated version which uses const instead of G_CONST_RETURN and also expands the documentation to mention the lifetimes of the returned values, as Behdad suggested.
Comment 6 Philip Withnall 2017-09-11 21:44:11 UTC
As per https://bugzilla.gnome.org/show_bug.cgi?id=401176#c8, and the fact that this would cause warnings in all existing code which does `GEnumValue *not_const = g_enum_get_value(…)`, let’s not change this.
Comment 7 Philip Withnall 2017-09-11 21:44:59 UTC
Review of attachment 210539 [details] [review]:

--