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 547199 - Constness of args in 'NULL terminated string array' functions
Constness of args in 'NULL terminated string array' functions
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: general
2.24.x
Other All
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-08-10 20:18 UTC by Marius Konitzer
Modified: 2017-09-11 21:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Bug 547199 — Constness of args in 'NULL terminated string array' functions (2.37 KB, patch)
2010-03-31 18:17 UTC, Philip Withnall
none Details | Review
Bug 547199 — Constness of args in 'NULL terminated string array' functions (4.48 KB, patch)
2010-03-31 18:28 UTC, Philip Withnall
none Details | Review
Bug 547199 — Constness of args in 'NULL terminated string array' functions (4.77 KB, patch)
2010-03-31 18:43 UTC, Philip Withnall
rejected Details | Review

Description Marius Konitzer 2008-08-10 20:18:44 UTC
Is there any reason why g_strv_length() is declared as:
guint g_strv_length (gchar **str_array)
instead of
guint g_strv_length (const gchar * const * str_array)
as one would expect? (Same question for g_strdupv() and g_strjoinv().)

The implementation of the a.m. functions doesn't seem to require write access to pointers and data in str_array, so we should tell this to both the developer and the compiler.

Other information:
Comment 1 Philip Withnall 2010-03-31 18:17:56 UTC
Created attachment 157626 [details] [review]
Bug 547199 — Constness of args in 'NULL terminated string array' functions

Make g_strv_length(), g_strdupv() and g_strjoinv() const-correct.
Closes: bgo#547199
Comment 2 Philip Withnall 2010-03-31 18:28:58 UTC
Created attachment 157627 [details] [review]
Bug 547199 — Constness of args in 'NULL terminated string array' functions

Make g_strv_length(), g_strdupv() and g_strjoinv() const-correct and
fix various internal uses of them in GLib. Closes: bgo#547199
Comment 3 Philip Withnall 2010-03-31 18:43:57 UTC
Created attachment 157628 [details] [review]
Bug 547199 — Constness of args in 'NULL terminated string array' functions

Make g_strv_length(), g_strdupv() and g_strjoinv() const-correct and
fix various internal uses of them in GLib. Closes: bgo#547199
Comment 4 Philip Withnall 2010-04-01 00:12:32 UTC
I'm getting gcc warnings like the one below with the patch applied, but I can't work out why it doesn't want to promote "char**" to "const char * const *" implicitly.

gthemedicon.c: In function ‘IA__g_themed_icon_append_name’:
gthemedicon.c:384: warning: passing argument 1 of ‘g_strv_length’ from incompatible pointer type
../glib/gstrfuncs.h:243: note: expected ‘const gchar * const*’ but argument is of type ‘char **’
Comment 5 Marius Konitzer 2010-04-23 23:30:50 UTC
AFAIK this is a notorious C problem: implicit casts work on the top level only (i.e. without recursion). A shortcoming of the C standard, if you put it that way.

It leads to (char * *) implicitly being casted to (char * const *), but never
to (const char * const *) as we would need.

I suppose using an explicit cast is the only way out here.
Comment 6 Philip Withnall 2017-09-11 21:45:26 UTC
(In reply to Philip Withnall from comment #4)
> I'm getting gcc warnings like the one below with the patch applied, but I
> can't work out why it doesn't want to promote "char**" to "const char *
> const *" implicitly.
> 
> gthemedicon.c: In function ‘IA__g_themed_icon_append_name’:
> gthemedicon.c:384: warning: passing argument 1 of ‘g_strv_length’ from
> incompatible pointer type
> ../glib/gstrfuncs.h:243: note: expected ‘const gchar * const*’ but argument
> is of type ‘char **’

⇒ And for this reason, we can’t change this API, as it would cause warnings in loads of existing code.
Comment 7 Philip Withnall 2017-09-11 21:46:01 UTC
Review of attachment 157628 [details] [review]:

--