Issue 14085: PyUnicode_WRITE: "comparison is always true" warnings (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/58293

classification

Title: PyUnicode_WRITE: "comparison is always true" warnings
Type: behavior Stage: resolved
Components: Interpreter Core, macOS Versions: Python 3.3

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: flox, python-dev, ronaldoussoren, skrah, vstinner
Priority: normal Keywords: patch

Created on 2012-02-22 08:51 by skrah, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
comparison-always-true.diff skrah,2012-02-22 12:36 review
Messages (7)
msg153936 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-02-22 08:51
The FreeBSD-9.0 bot shows a couple of warnings because some comparisons in PyUnicode_WRITE are always true: Objects/unicodeobject.c:2598: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:2598: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:2598: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:2671: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:2671: warning: comparison is always true due to limited range of data type [...]
msg153944 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-02-22 09:43
Can you try to cast value to Py_UCS4 in assertions of PyUnicode_WRITE() macro? For example, replace assert(value <= 0xff); by assert((Py_UCS4)value <= 0xff);
msg153951 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-02-22 12:36
Your suggestion eliminates many warnings, but not all. FreeBSD is still stuck with gcc-4.2, so perhaps this is a good compromise. Getting rid of the remaining warnings might require a more bloated solution. These are the remaining warnings: Objects/unicodeobject.c: In function 'PyUnicode_DecodeUTF16Stateful': Objects/unicodeobject.c:5474: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5474: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5475: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5475: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5477: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5477: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5478: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5478: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c: In function 'PyUnicode_DecodeASCII': Objects/unicodeobject.c:6878: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:6878: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:6878: warning: comparison is always true due to limited range of data type
msg153955 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-02-22 14:31
It looks like in the FreeBSD (patched?) gcc version -Wtype-limits is part of -Wall. I can reproduce the same warnings on Ubuntu with: ./configure --with-pydebug CFLAGS=-Wtype-limits So I'm not so sure anymore if this is worth a patch at all. I could also export CFLAGS=-Wno-type-limits on the bot.
msg154352 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2012-02-26 14:34
Same on OSX, building trunk (3.3.0a0) $ uname -v Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 $ gcc --version i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) $ ./configure MACOSX_DEPLOYMENT_TARGET=10.8 --with-pydebug (...) $ make -s -j12 (...) Objects/unicodeobject.c: In function ‘PyUnicode_FromFormatV’: Objects/unicodeobject.c:2729: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:2729: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:2729: warning: comparison is always true due to limited range of data type Python/import.c: In function ‘make_compiled_pathname’: Python/import.c:981: warning: comparison is always true due to limited range of data type Python/import.c:981: warning: comparison is always true due to limited range of data type Python/import.c:981: warning: comparison is always true due to limited range of data type Python/import.c:987: warning: comparison is always true due to limited range of data type Python/import.c:987: warning: comparison is always true due to limited range of data type Python/import.c:987: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c: In function ‘PyUnicode_DecodeUTF16Stateful’: Objects/unicodeobject.c:5525: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5525: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5526: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5526: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5528: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5528: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5529: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:5529: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c: In function ‘PyUnicode_DecodeASCII’: Objects/unicodeobject.c:6929: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:6929: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:6929: warning: comparison is always true due to limited range of data type Python/formatter_unicode.c: In function ‘fill_number’: Python/formatter_unicode.c:561: warning: comparison is always true due to limited range of data type Python/formatter_unicode.c:561: warning: comparison is always true due to limited range of data type Python/formatter_unicode.c:561: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c: In function ‘unicode_repr’: Objects/unicodeobject.c:12325: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12325: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12325: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12326: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12326: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12326: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12344: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12344: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12344: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12345: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12345: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12345: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12351: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12351: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12351: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12352: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12352: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12352: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12353: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12353: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12353: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12354: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12354: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12354: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12355: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12355: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12355: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12356: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12356: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12356: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12357: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12357: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12357: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12358: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12358: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12358: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12364: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12364: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12364: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12365: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12365: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12365: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12366: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12366: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12366: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12367: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12367: warning: comparison is always true due to limited range of data type Objects/unicodeobject.c:12367: warning: comparison is always true due to limited range of data type
msg154417 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-02-26 22:49
Castng to Py_UCS4 doesn't make the warning quiet. Does someone know how to make the warning quiet. If not, assertions can be removed from PyUnicode_WRITE. We might write a function for Python compiled in debug mode to add the assertions. More consistency tests (e.g. check for non-ASCII character in an ASCII string) could be added if the macro got the object, but it only takes data and kind.
msg154867 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-03-04 00:38
New changeset ba0bd949ddf5 by Victor Stinner in branch 'default': Close #14085: remove assertions from PyUnicode_WRITE macro http://hg.python.org/cpython/rev/ba0bd949ddf5
History
Date User Action Args
2022-04-11 14:57:27 admin set github: 58293
2012-03-04 00:38:53 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2012-02-26 22:49:01 vstinner set messages: +
2012-02-26 14:37:32 flox set assignee: ronaldoussoren ->
2012-02-26 14:34:35 flox set nosy: + ronaldoussoren, floxmessages: + assignee: ronaldoussorencomponents: + macOS
2012-02-22 14:31:56 skrah set messages: +
2012-02-22 12:36:17 skrah set files: + comparison-always-true.diffkeywords: + patchmessages: +
2012-02-22 09:43:13 vstinner set messages: +
2012-02-22 08:51:31 skrah create