Skip to content

COMMON_FIELDS macro in funcobject.h leaks to user code #118207

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

Closed
itamaro opened this issue Apr 24, 2024 · 2 comments
Closed

COMMON_FIELDS macro in funcobject.h leaks to user code #118207

itamaro opened this issue Apr 24, 2024 · 2 comments
Labels
topic-C-API type-bug An unexpected behavior, bug, or error

Comments

@itamaro
Copy link
Contributor

itamaro commented Apr 24, 2024

Bug report

Bug description:

the COMMON_FIELDS macro is defined here, and can end up being included in user code (via Python.h).

"COMMON_FIELDS" is not a unique enough identifier, and can conflict with other use of the same name in user C/C++ code (has happened to us at Meta).

this macro is used only twice within the same header as it is defined, so it should be straight forward to undef it after it is used to prevent it from leaking (PR coming up).

CPython versions tested on:

3.10, 3.12, 3.13

Operating systems tested on:

Linux, macOS

Linked PRs

@encukou
Copy link
Member

encukou commented Apr 25, 2024

FWIW: I have a script almost ready to detect other stray definitions without the Py prefix. Right now the focus is on getting features into 3.13 beta1; I plan to run the script after that.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 25, 2024
…ndef it after use (pythonGH-118208)

(cherry picked from commit 796b3fb)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
@itamaro
Copy link
Contributor Author

itamaro commented Apr 26, 2024

thanks @encukou ! waiting for the backport to land and then we can close this issue :)

JelleZijlstra pushed a commit that referenced this issue Apr 26, 2024
…undef it after use (GH-118208) (#118269)

gh-118207: Rename the COMMON_FIELDS macro in funcobject.h and undef it after use (GH-118208)
(cherry picked from commit 796b3fb)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
@encukou encukou closed this as completed Apr 26, 2024
facebook-github-bot pushed a commit to facebookincubator/cinder that referenced this issue Apr 26, 2024
…nd undef it after use

Summary:
supersedes D56454529 by backporting the upstream version instead of an internal patch

upstream issue: python/cpython#118207
upstream PR: python/cpython#118269

still undef'ing the macro, but also renaming it to have `_Py` prefix, for consistency, and to avoid conflicts if the same name is already defined before including `Python.h`

Reviewed By: aleivag

Differential Revision: D56579827

fbshipit-source-id: c8260818f5901bc9c3eb582999575af9c64f189f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants