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

Implement Py_UNUSED() for Windows MSVC compiler #107249

Closed
vstinner opened this issue Jul 25, 2023 · 0 comments
Closed

Implement Py_UNUSED() for Windows MSVC compiler #107249

vstinner opened this issue Jul 25, 2023 · 0 comments
Labels
type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Jul 25, 2023

The Py_UNUSED() is not implemented for the Windows MSVC compiler.

Example with this function included by Python.h: see #107239 (comment)

static inline unsigned int
PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
{ return 1; }

Without my change, building a C program with cl /W4 which just includes Python.h emits the warning:

Include\cpython/unicodeobject.h(199): warning C4100: '_unused_op': unreferenced formal parameter

With my change, no warnings are emitted!

Linked PRs

@vstinner vstinner added the type-feature A feature request or enhancement label Jul 25, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Jul 25, 2023
Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".

Example with this function included by Python.h:

    static inline unsigned int
    PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
    { return 1; }

Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:

    Include\cpython/unicodeobject.h(199):
    warning C4100: '_unused_op': unreferenced formal parameter

This change fix this warning.
vstinner added a commit that referenced this issue Jul 25, 2023
Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".

Example with this function included by Python.h:

    static inline unsigned int
    PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
    { return 1; }

Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:

    Include\cpython/unicodeobject.h(199):
    warning C4100: '_unused_op': unreferenced formal parameter

This change fix this warning.
jtcave pushed a commit to jtcave/cpython that referenced this issue Jul 27, 2023
Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".

Example with this function included by Python.h:

    static inline unsigned int
    PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
    { return 1; }

Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:

    Include\cpython/unicodeobject.h(199):
    warning C4100: '_unused_op': unreferenced formal parameter

This change fix this warning.
bdegreve added a commit to cocamware/lass that referenced this issue Aug 15, 2024
On Windows, with cl /W4, we get following warning with Python 3.12:

  C:\Program Files\Python312\include\cpython/unicodeobject.h(203,57): warning C4100: '_unused_op': unreferenced formal parameter

Py_UNUSED hasn't changed in 5 years [1], but in Python 3.12 it started
being used in unicodeobject.h [2] so it became part of the public
interface. Because Py_UNUSED only prepended _unused_ to the parameter
name for MSVC [1], we get the C4100 warning when compiling with /W4.
In Python 3.13 this got fixed by adding a specific implementation of
Py_UNUSED for MSVC [3], so the warning is unique to Python 3.12.
However, as we don't know PY_VERSION_HEX _before_ including Python.h,
we'll indiscriminately suppress the C4100 while including Python.h.

[1] https://github.com/python/cpython/blame/3.12/Include/pymacro.h#L114-L123
[2] python/cpython@b2694ab
[3] python/cpython#107249
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 13, 2024
Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".

Example with this function included by Python.h:

    static inline unsigned int
    PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
    { return 1; }

Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:

    Include\cpython/unicodeobject.h(199):
    warning C4100: '_unused_op': unreferenced formal parameter

This change fix this warning.
(cherry picked from commit 6a43cce)

Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this issue Dec 13, 2024
gh-107249: Implement Py_UNUSED() for MSVC (GH-107250)

Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".

Example with this function included by Python.h:

    static inline unsigned int
    PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
    { return 1; }

Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:

    Include\cpython/unicodeobject.h(199):
    warning C4100: '_unused_op': unreferenced formal parameter

This change fix this warning.
(cherry picked from commit 6a43cce)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants