Package: python3
Version: 3.8.2-3
Severity: normal
Tags: patch upstream

Dear Maintainer,

There is a signed/unsigned mismatch in the Py_UNICODE_ISSPACE() macro in
Python's unicodeobject.h.  The following program demonstrates the problem

#include <Python.h>

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

        return Py_UNICODE_ISSPACE(x);
}

compile with

$ gcc -Wsign-compare -Werror $(pkg-config --cflags python3) a.c
In file included from /usr/include/python3.8/unicodeobject.h:1037,
                 from /usr/include/python3.8/Python.h:97,
                 from a.c:1:
a.c: In function ‘main’:
/usr/include/python3.8/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))
      |           ^
a.c:7:9: note: in expansion of macro ‘Py_UNICODE_ISSPACE’
    7 |  return Py_UNICODE_ISSPACE(x);
      |         ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors


The comparison is between the macro's parameter ch and the unsigned integer
128.  On Debian amd64, Py_UNICODE is typedef'd to signed int causing a
signed/unsigned mismatch warning when the Py_UNICODE_ISSPACE() macro is used
with variables that have been defined to be the correct Py_UNICODE type.  The
warning is mostly harmless, but it prevents Python extension  modules from
being compiled with warnings enabled and -Werror.

The following patch fixes it

$ diff /usr/include/python3.8/cpython/unicodeobject.h unicodeobject.h
25c25
<     ((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
---
>     ((ch) < (Py_UNICODE)128 ? _Py_ascii_whitespace[(ch)] :
_PyUnicode_IsWhitespace(ch))


I don't know if this problem is unique to the Debian packaging of Python or if
it exists upstream, so I'm reporting it here.  If I should report this upstream
instead please let me know.  Thanks,

                                                        -Kipp



-- System Information:
Debian Release: bullseye/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.6.0-1-amd64 (SMP w/4 CPU cores)
Kernel taint flags: TAINT_FIRMWARE_WORKAROUND
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_CA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages python3 depends on:
ii  libpython3-stdlib  3.8.2-3
ii  python3-minimal    3.8.2-3
ii  python3.8          3.8.3-1

python3 recommends no packages.

Versions of packages python3 suggests:
pn  python3-doc   <none>
ii  python3-tk    3.8.2-2
pn  python3-venv  <none>

-- no debconf information

Reply via email to