GNOME Bugzilla – Bug 397125
g_enum_get_value should return const
Last modified: 2017-09-11 21:44:59 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...
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
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.
+1, patch looks ok, although people might have to fix their code.
Review of attachment 157656 [details] [review]: Not a Glib maintainer, but G_CONST_RETURN is deprecated, use const directly instead
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.
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.
Review of attachment 210539 [details] [review]: --