From f1f5622aa1cfd320b776925413d12d68a00e0aa5 Mon Sep 17 00:00:00 2001 From: trcrsired Date: Thu, 23 Jun 2022 14:39:06 -0400 Subject: [PATCH 1/3] Fix PyObject_NEW and PyObject_NEW_VAR by removing their first bracket pair The problem is that ((type) *) is not working. Randomly adding brackets to macros are not going to work --- Include/objimpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/objimpl.h b/Include/objimpl.h index 140918198dae0e..6ca9eb8e003903 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -135,7 +135,7 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); // Alias to PyObject_New(). In Python 3.8, PyObject_NEW() called directly // PyObject_MALLOC() with _PyObject_SIZE(). -#define PyObject_NEW(type, typeobj) PyObject_New((type), (typeobj)) +#define PyObject_NEW(type, typeobj) PyObject_New(type, (typeobj)) #define PyObject_NewVar(type, typeobj, n) \ ( (type *) _PyObject_NewVar((typeobj), (n)) ) From 2f96e2e0c5781b764cb533e5fa19d4b703a322d0 Mon Sep 17 00:00:00 2001 From: trcrsired Date: Thu, 23 Jun 2022 14:40:19 -0400 Subject: [PATCH 2/3] Forget to commit the fix for PyObject_New_VAR Fix them --- Include/objimpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/objimpl.h b/Include/objimpl.h index 6ca9eb8e003903..dde8df34835328 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -142,7 +142,7 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); // Alias to PyObject_NewVar(). In Python 3.8, PyObject_NEW_VAR() called // directly PyObject_MALLOC() with _PyObject_VAR_SIZE(). -#define PyObject_NEW_VAR(type, typeobj, n) PyObject_NewVar((type), (typeobj), (n)) +#define PyObject_NEW_VAR(type, typeobj, n) PyObject_NewVar(type, (typeobj), (n)) /* From 7dc8d6dd261d80a59c9974e9632c37fef61a82d8 Mon Sep 17 00:00:00 2001 From: trcrsired Date: Thu, 23 Jun 2022 15:01:22 -0400 Subject: [PATCH 3/3] Add NEWs for Fix PyObject_NEW and PyObject_NEW_VAR --- .../C API/2022-06-23-15-00-49.gh-issue-94185.dQkHfg.rst | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2022-06-23-15-00-49.gh-issue-94185.dQkHfg.rst diff --git a/Misc/NEWS.d/next/C API/2022-06-23-15-00-49.gh-issue-94185.dQkHfg.rst b/Misc/NEWS.d/next/C API/2022-06-23-15-00-49.gh-issue-94185.dQkHfg.rst new file mode 100644 index 00000000000000..5a7b0fafb1bd5a --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-06-23-15-00-49.gh-issue-94185.dQkHfg.rst @@ -0,0 +1,7 @@ +Fix PyObject_NEW and PyObject_NEW_VAR + +The commit 7ad6f74 tried to add brackets to tons of macros, but they break +PyObject_New and PyObject_MEW_VAR since the macro would expand to ((Type)*) +which breaks compilation for those CPython headers. + +Fix the issue 94185.