This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: signed/unsigned mismatch in Py_UNICODE_ISSPACE macro
Type: Stage: resolved
Components: C API Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: doko, methane, miss-islington, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2021-01-26 12:40 by doko, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24350 merged serhiy.storchaka, 2021-01-27 08:30
PR 24396 merged miss-islington, 2021-01-31 13:55
PR 24397 merged miss-islington, 2021-01-31 13:55
Messages (8)
msg385707 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2021-01-26 12:40
[forwarded from https://bugs.debian.org/961396]

$ cat > foo.c
#include <Python.h>

int main(int argc, char *argv[])
{
        Py_UNICODE x = 0;

        return Py_UNICODE_ISSPACE(x);
}

$ gcc -Wsign-compare -Werror $(pkg-config --cflags python3) foo.c
In file included from /usr/include/python3.9/unicodeobject.h:1026,
                 from /usr/include/python3.9/Python.h:97,
                 from foo.c:1:
foo.c: In function ‘main’:
/usr/include/python3.9/cpython/unicodeobject.h:25:11: error: comparison of integer expressions of different signedness: ‘Py_UNICODE’ {aka ‘int’} and ‘unsigned int’ [-Werror=sign-compare]
   25 |     ((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
      |           ^
foo.c:7:16: note: in expansion of macro ‘Py_UNICODE_ISSPACE’
    7 |         return Py_UNICODE_ISSPACE(x);
      |                ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
msg385708 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-01-26 12:50
> ‘Py_UNICODE’ {aka ‘int’}

Python defines Py_UNICODE as wchar_t: typedef wchar_t Py_UNICODE;

Is wchar_t signed (int type) on Debian? Which is your architecture?

> [forwarded from https://bugs.debian.org/961396]

It says amd64.
msg385711 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2021-01-26 13:06
# 26 "/usr/include/stdlib.h" 2 3 4
# 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4
# 321 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4
typedef int wchar_t;
# 32 "/usr/include/stdlib.h" 2 3 4

[...]

# 1 "/usr/include/python3.9/cpython/unicodeobject.h" 1
# 14 "/usr/include/python3.9/cpython/unicodeobject.h"
                         typedef wchar_t Py_UNICODE;
# 53 "/usr/include/python3.9/cpython/unicodeobject.h"

yes, x86_64-linux-gnu.
msg385747 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-01-27 01:20
Just replacing "128U" with "128" enough?
Will `ch < 128` emit warning on platforms wchar_t is unsigned?
msg385750 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-27 08:31
No, it is not enough, because we do not want to use ch as index if it is negative.
msg386016 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-31 13:55
New changeset 42b1806af90b86ec393ca7da14e99ce95ec6c53b by Serhiy Storchaka in branch 'master':
bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350)
https://github.com/python/cpython/commit/42b1806af90b86ec393ca7da14e99ce95ec6c53b
msg386019 - (view) Author: miss-islington (miss-islington) Date: 2021-01-31 14:20
New changeset 995a6c015024f050b99ba8f9837dfc6b82d83f7d by Miss Islington (bot) in branch '3.9':
bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350)
https://github.com/python/cpython/commit/995a6c015024f050b99ba8f9837dfc6b82d83f7d
msg386022 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-31 14:46
New changeset 229ef39bcc14ee7838968dfda51d045304e5cf39 by Miss Islington (bot) in branch '3.8':
bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350) (GH-24397)
https://github.com/python/cpython/commit/229ef39bcc14ee7838968dfda51d045304e5cf39
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87196
2021-01-31 14:46:58serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
components: + C API, - Extension Modules
versions: + Python 3.8, Python 3.10
2021-01-31 14:46:25serhiy.storchakasetmessages: + msg386022
2021-01-31 14:20:18miss-islingtonsetmessages: + msg386019
2021-01-31 13:55:43miss-islingtonsetpull_requests: + pull_request23211
2021-01-31 13:55:30miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23210
2021-01-31 13:55:22serhiy.storchakasetmessages: + msg386016
2021-01-27 08:31:55serhiy.storchakasetmessages: + msg385750
2021-01-27 08:30:40serhiy.storchakasetkeywords: + patch
nosy: + serhiy.storchaka

pull_requests: + pull_request23170
stage: patch review
2021-01-27 01:20:06methanesetmessages: + msg385747
2021-01-26 13:06:26dokosetmessages: + msg385711
2021-01-26 12:50:36vstinnersetnosy: + vstinner, methane
messages: + msg385708
2021-01-26 12:40:22dokocreate