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

Py_IS_TYPE(): cast discards ‘const’ qualifier from pointer target type #88544

Closed
vstinner opened this issue Jun 10, 2021 · 4 comments
Closed
Labels
3.10 only security fixes 3.11 bug and security fixes topic-C-API

Comments

@vstinner
Copy link
Member

BPO 44378
Nosy @vstinner, @miss-islington
PRs
  • bpo-44378: Fix a compiler warning in Py_IS_TYPE() #26644
  • [3.10] bpo-44378: Fix a compiler warning in Py_IS_TYPE() (GH-26644) #26668
  • 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-06-11.09:44:59.760>
    created_at = <Date 2021-06-10.13:19:54.087>
    labels = ['expert-C-API', '3.10', '3.11']
    title = 'Py_IS_TYPE(): cast discards \xe2\x80\x98const\xe2\x80\x99 qualifier from pointer target type'
    updated_at = <Date 2021-06-11.09:44:59.760>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2021-06-11.09:44:59.760>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-11.09:44:59.760>
    closer = 'vstinner'
    components = ['C API']
    creation = <Date 2021-06-10.13:19:54.087>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44378
    keywords = ['patch']
    message_count = 4.0
    messages = ['395534', '395535', '395617', '395622']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'miss-islington']
    pr_nums = ['26644', '26668']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44378'
    versions = ['Python 3.10', 'Python 3.11']

    @vstinner
    Copy link
    Member Author

    The following change introduced a compiler warning:

    commit c5cb077
    Author: Victor Stinner <vstinner@python.org>
    Date: Tue Sep 22 12:42:28 2020 +0200

    Py_IS_TYPE() macro uses Py_TYPE() (GH-22341)
    

    Steps to Reproduce:

    1. dnf install -y python3-devel pkgconf-pkg-config gcc
    2. printf '#include <Python.h>' > test.c
    3. gcc -Wcast-qual -Werror -c test.c pkg-config --cflags --libs python-3.10

    Actual results:
    sh-5.1# gcc -Wcast-qual -Werror -c test.c pkg-config --cflags --libs python-3.10
    In file included from /usr/include/python3.10/Python.h:78,
    from test.c:1:
    /usr/include/python3.10/object.h: In function ‘_Py_IS_TYPE’:
    /usr/include/python3.10/object.h:112:29: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
    112 | #define _PyObject_CAST(op) ((PyObject*)(op))
    | ^
    /usr/include/python3.10/object.h:137:34: note: in expansion of macro ‘_PyObject_CAST’
    137 | #define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
    | ^~~~~~~~~~~~~~
    /usr/include/python3.10/object.h:144:12: note: in expansion of macro ‘Py_TYPE’
    144 | return Py_TYPE(ob) == type;
    | ^~~~~~~
    cc1: all warnings being treated as errors

    Attached PR fix the compiler warning.

    Issue reported on Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=1969663

    @vstinner vstinner added 3.10 only security fixes 3.11 bug and security fixes topic-C-API labels Jun 10, 2021
    @vstinner
    Copy link
    Member Author

    Comment from my PR:

    // bpo-44378: Don't use Py_TYPE() since Py_TYPE() requires a non-const
    // object.

    By the way, I wrote a change in Python 3.11 to convert Py_TYPE() macro into a static inline function which accepts a *const* PyObject pointer ("const PyObject*"):
    f3fa63e

    But this change had to be reverted since it caused a buildbot regression (bpo-44348).

    @vstinner
    Copy link
    Member Author

    New changeset 304dfec by Victor Stinner in branch 'main':
    bpo-44378: Fix a compiler warning in Py_IS_TYPE() (GH-26644)
    304dfec

    @miss-islington
    Copy link
    Contributor

    New changeset e6d28a1 by Miss Islington (bot) in branch '3.10':
    bpo-44378: Fix a compiler warning in Py_IS_TYPE() (GH-26644)
    e6d28a1

    @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.10 only security fixes 3.11 bug and security fixes topic-C-API
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants