Skip to content

Commit

Permalink
Backport: gh-118207: Rename the COMMON_FIELDS macro in funcobject.h a…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
itamaro authored and facebook-github-bot committed Apr 26, 2024
1 parent 14707ac commit 7f4c505
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Include/cpython/funcobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern "C" {
#endif


#define COMMON_FIELDS(PREFIX) \
#define _Py_COMMON_FIELDS(PREFIX) \
PyObject *PREFIX ## globals; \
PyObject *PREFIX ## builtins; \
PyObject *PREFIX ## name; \
Expand All @@ -19,7 +19,7 @@ extern "C" {
PyObject *PREFIX ## closure; /* NULL or a tuple of cell objects */

typedef struct {
COMMON_FIELDS(fc_)
_Py_COMMON_FIELDS(fc_)
} PyFrameConstructor;

/* Function objects and code objects should not be confused with each other:
Expand All @@ -35,7 +35,7 @@ typedef struct {

typedef struct {
PyObject_HEAD
COMMON_FIELDS(func_)
_Py_COMMON_FIELDS(func_)
PyObject *func_doc; /* The __doc__ attribute, can be anything */
PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */
PyObject *func_weakreflist; /* List of weak references */
Expand All @@ -60,9 +60,7 @@ typedef struct {
*/
} PyFunctionObject;

// START META PATCH (undef COMMON_FIELDS to avoid leaking into C++ code)
#undef COMMON_FIELDS
// END META PATCH
#undef _Py_COMMON_FIELDS

PyAPI_DATA(PyTypeObject) PyFunction_Type;

Expand Down

0 comments on commit 7f4c505

Please sign in to comment.