Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signed/unsigned mismatch in Py_UNICODE_ISSPACE macro #87196

Closed
doko42 opened this issue Jan 26, 2021 · 8 comments
Closed

signed/unsigned mismatch in Py_UNICODE_ISSPACE macro #87196

doko42 opened this issue Jan 26, 2021 · 8 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes topic-C-API

Comments

@doko42
Copy link
Member

doko42 commented Jan 26, 2021

BPO 43030
Nosy @doko42, @vstinner, @methane, @serhiy-storchaka, @miss-islington
PRs
  • bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t #24350
  • [3.9] bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350) #24396
  • [3.8] bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350) #24397
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-01-31.14:46:58.135>
    created_at = <Date 2021-01-26.12:40:22.465>
    labels = ['expert-C-API', '3.8', '3.9', '3.10']
    title = 'signed/unsigned mismatch in Py_UNICODE_ISSPACE macro'
    updated_at = <Date 2021-01-31.14:46:58.131>
    user = 'https://github.com/doko42'

    bugs.python.org fields:

    activity = <Date 2021-01-31.14:46:58.131>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-31.14:46:58.135>
    closer = 'serhiy.storchaka'
    components = ['C API']
    creation = <Date 2021-01-26.12:40:22.465>
    creator = 'doko'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43030
    keywords = ['patch']
    message_count = 8.0
    messages = ['385707', '385708', '385711', '385747', '385750', '386016', '386019', '386022']
    nosy_count = 5.0
    nosy_names = ['doko', 'vstinner', 'methane', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['24350', '24396', '24397']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43030'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @doko42
    Copy link
    Member Author

    doko42 commented Jan 26, 2021

    [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

    @doko42 doko42 added extension-modules C modules in the Modules dir 3.9 only security fixes labels Jan 26, 2021
    @vstinner
    Copy link
    Member

    ‘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.

    @doko42
    Copy link
    Member Author

    doko42 commented Jan 26, 2021

    # 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.

    @methane
    Copy link
    Member

    methane commented Jan 27, 2021

    Just replacing "128U" with "128" enough?
    Will ch < 128 emit warning on platforms wchar_t is unsigned?

    @serhiy-storchaka
    Copy link
    Member

    No, it is not enough, because we do not want to use ch as index if it is negative.

    @serhiy-storchaka
    Copy link
    Member

    New changeset 42b1806 by Serhiy Storchaka in branch 'master':
    bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350)
    42b1806

    @miss-islington
    Copy link
    Contributor

    New changeset 995a6c0 by Miss Islington (bot) in branch '3.9':
    bpo-43030: Fixed a compiler warning in Py_UNICODE_ISSPACE with signed wchar_t (GH-24350)
    995a6c0

    @serhiy-storchaka
    Copy link
    Member

    New changeset 229ef39 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)
    229ef39

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes 3.10 only security fixes topic-C-API and removed extension-modules C modules in the Modules dir labels Jan 31, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes topic-C-API
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants