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

gh-98724: Fix type punning issue in Py_SETREF() #99739

Closed
wants to merge 1 commit into from
Closed

gh-98724: Fix type punning issue in Py_SETREF() #99739

wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Nov 23, 2022

Fix type punning issue in Py_CLEAR(), Py_SETREF() and Py_XSETREF() macros. Don't cast pointers to avoid type punning which cause miscompilation of functions using these macros.

Fix type punning issue in Py_CLEAR(), Py_SETREF() and Py_XSETREF()
macros. Don't cast pointers to avoid type punning which cause
miscompilation of functions using these macros.
@vstinner
Copy link
Member Author

#define _PY_TYPEOF(EXPR) __typeof__(EXPR)

On GCC and clang, typeof() can maybe used. In "GNU mode", typeof is treated as a keyword by the C compiler.

On MSVC, if __typeof__() doesn't work, maybe decltype() can be used instead.

@vstinner
Copy link
Member Author

Ah, building Python with the PR fails on Windows (MSVC) with:

warning C4013: '__typeof__' undefined

@vstinner
Copy link
Member Author

Since MSVC doesn't implement __typeof__(), I don't think that this approach works. I would like the C API to behave the same on all platforms: see #98724 (comment) I close my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants