gh-149707: Fix compiler warning in _ctypes_test on strchr()#149791
Conversation
Change my_strchr() return type to "const char*" (add "const").
Fix the compiler warning:
Modules/_ctypes/_ctypes_test.c: In function 'my_strchr':
Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards
'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
451 | return strchr(s, c);
| ^~~~~~
When using C23, strchr(text, ch) return type is "const char*" if text
type is "const char*".
|
See for example the glibc commit which introduced C23 support in The code is now: extern char *strchr (const char *__s, int __c)
__THROW __attribute_pure__ __nonnull ((1));
# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
# define strchr(S, C) \
__glibc_const_generic (S, const char *, strchr (S, C))
# endif |
|
I edited the title to add the issue, someone reported this recently: #149707 |
| } | ||
|
|
||
| EXPORT(char *)my_strchr(const char *s, int c) | ||
| EXPORT(const char *) my_strchr(const char *s, int c) |
There was a problem hiding this comment.
| EXPORT(const char *) my_strchr(const char *s, int c) | |
| EXPORT(const char *)my_strchr(const char *s, int c) |
For consistency with the others.
There was a problem hiding this comment.
The majority of exported functions have a space or write EXPORT() on a separated line. I would prefer to fix all functions to add a space, but I don't think that it's worth it :-)
There was a problem hiding this comment.
Ah right, I had a small sample size, I only checked a few.
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-149862 is a backport of this pull request to the 3.15 branch. |
|
GH-149863 is a backport of this pull request to the 3.14 branch. |
|
GH-149864 is a backport of this pull request to the 3.13 branch. |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15. |
…thonGH-149791) Change my_strchr() return type to "const char*" (add "const"). Fix the compiler warning: Modules/_ctypes/_ctypes_test.c: In function 'my_strchr': Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 451 | return strchr(s, c); | ^~~~~~ When using C23, strchr(text, ch) return type is "const char*" if text type is "const char*". (cherry picked from commit 5465b69) Co-authored-by: Victor Stinner <vstinner@python.org>
|
Sorry @vstinner, I had trouble completing the backport. |
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15. |
…thonGH-149791) Change my_strchr() return type to "const char*" (add "const"). Fix the compiler warning: Modules/_ctypes/_ctypes_test.c: In function 'my_strchr': Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 451 | return strchr(s, c); | ^~~~~~ When using C23, strchr(text, ch) return type is "const char*" if text type is "const char*". (cherry picked from commit 5465b69) Co-authored-by: Victor Stinner <vstinner@python.org>
|
Sorry @vstinner, I had trouble completing the backport. |
|
GH-149865 is a backport of this pull request to the 3.15 branch. |
|
GH-149866 is a backport of this pull request to the 3.14 branch. |
|
GH-149867 is a backport of this pull request to the 3.13 branch. |
|
Hum. I don't understand why the bot failed to backport the change to 3.15. I backported the change manually. I backported it to 3.15, 3.14 and 3.13 branches, I didn't notice that the bot already created backports to 3.13 and 3.14 in the meanwhile... |
…149791) (#149867) gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791) Change my_strchr() return type to "const char*" (add "const"). Fix the compiler warning: Modules/_ctypes/_ctypes_test.c: In function 'my_strchr': Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 451 | return strchr(s, c); | ^~~~~~ When using C23, strchr(text, ch) return type is "const char*" if text type is "const char*". (cherry picked from commit 5465b69)
…149791) (#149866) gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791) Change my_strchr() return type to "const char*" (add "const"). Fix the compiler warning: Modules/_ctypes/_ctypes_test.c: In function 'my_strchr': Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 451 | return strchr(s, c); | ^~~~~~ When using C23, strchr(text, ch) return type is "const char*" if text type is "const char*". (cherry picked from commit 5465b69)
…149791) (#149865) gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791) Change my_strchr() return type to "const char*" (add "const"). Fix the compiler warning: Modules/_ctypes/_ctypes_test.c: In function 'my_strchr': Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 451 | return strchr(s, c); | ^~~~~~ When using C23, strchr(text, ch) return type is "const char*" if text type is "const char*". (cherry picked from commit 5465b69)
|
The bot is playing trick on you ;-) |
Change my_strchr() return type to "const char*" (add "const").
Fix the compiler warning:
When using C23, strchr(text, ch) return type is "const char*" if text type is "const char*".