Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner 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
MemberAuthor

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

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

warning C4013: '__typeof__' undefined 

@vstinner
Copy link
MemberAuthor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@bedevere-bot