From 75719a613f1fc0eddac61d5982a3164b1d803517 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 7 Feb 2022 18:42:13 +0100 Subject: [PATCH 1/2] bpo-45459: Rename buffer.h to pybuffer.h Rename Include/buffer.h header file to Include/pybuffer.h to avoid conflits with projects having an existing buffer.h header file. * Incude pybuffer.h before object.h in Python.h. * Remove #include "buffer.h" from Include/cpython/object.h. * Add a forward declaration of the PyObject type in pybuffer.h to fix an inter-dependency issue. --- Include/Python.h | 2 +- Include/cpython/object.h | 2 -- Include/{buffer.h => pybuffer.h} | 3 +++ Makefile.pre.in | 2 +- .../NEWS.d/next/C API/2022-02-07-18-47-00.bpo-45459.0FCWM8.rst | 3 +++ PCbuild/pythoncore.vcxproj | 1 + PCbuild/pythoncore.vcxproj.filters | 3 +++ 7 files changed, 12 insertions(+), 4 deletions(-) rename Include/{buffer.h => pybuffer.h} (98%) create mode 100644 Misc/NEWS.d/next/C API/2022-02-07-18-47-00.bpo-45459.0FCWM8.rst diff --git a/Include/Python.h b/Include/Python.h index 5416b04e4bfb32..5bc8cc656af0de 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -39,6 +39,7 @@ #include "pymacro.h" #include "pymath.h" #include "pymem.h" +#include "pybuffer.h" #include "object.h" #include "objimpl.h" #include "typeslots.h" @@ -50,7 +51,6 @@ #include "longobject.h" #include "cpython/longintrepr.h" #include "boolobject.h" -#include "buffer.h" #include "floatobject.h" #include "complexobject.h" #include "rangeobject.h" diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 1554ac8aef1c44..1d1787b75caa50 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -2,8 +2,6 @@ # error "this header file must not be included directly" #endif -#include "buffer.h" // for Py_buffer, included after PyObject has been defined - PyAPI_FUNC(void) _Py_NewReference(PyObject *op); #ifdef Py_TRACE_REFS diff --git a/Include/buffer.h b/Include/pybuffer.h similarity index 98% rename from Include/buffer.h rename to Include/pybuffer.h index 6893505e66e3e8..8baba78c5ab13a 100644 --- a/Include/buffer.h +++ b/Include/pybuffer.h @@ -17,6 +17,9 @@ extern "C" { * */ +// Forward declaration +typedef struct _object PyObject; + typedef struct { void *buf; PyObject *obj; /* owned reference */ diff --git a/Makefile.pre.in b/Makefile.pre.in index 4dcedd684aa6da..8b2ca111123855 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1439,7 +1439,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/abstract.h \ $(srcdir)/Include/bltinmodule.h \ $(srcdir)/Include/boolobject.h \ - $(srcdir)/Include/buffer.h \ $(srcdir)/Include/bytearrayobject.h \ $(srcdir)/Include/bytesobject.h \ $(srcdir)/Include/ceval.h \ @@ -1472,6 +1471,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/osdefs.h \ $(srcdir)/Include/osmodule.h \ $(srcdir)/Include/patchlevel.h \ + $(srcdir)/Include/pybuffer.h \ $(srcdir)/Include/pycapsule.h \ $(srcdir)/Include/pydtrace.h \ $(srcdir)/Include/pyerrors.h \ diff --git a/Misc/NEWS.d/next/C API/2022-02-07-18-47-00.bpo-45459.0FCWM8.rst b/Misc/NEWS.d/next/C API/2022-02-07-18-47-00.bpo-45459.0FCWM8.rst new file mode 100644 index 00000000000000..711c107746d643 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-02-07-18-47-00.bpo-45459.0FCWM8.rst @@ -0,0 +1,3 @@ +Rename ``Include/buffer.h`` header file to ``Include/pybuffer.h`` to avoid +conflits with projects having an existing ``buffer.h`` header file. Patch by +Victor Stinner. diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 8f9c4fe63b8dc9..c2f1a016bc1115 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -263,6 +263,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index dc3b5547794863..b300103bbb4206 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -147,6 +147,9 @@ Include + + Include + Include From 7e32c1c1ca7063206c6962d12165f48253b304f6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 7 Feb 2022 19:02:31 +0100 Subject: [PATCH 2/2] Elaborate the comment --- Include/pybuffer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Include/pybuffer.h b/Include/pybuffer.h index 8baba78c5ab13a..31795b780710fa 100644 --- a/Include/pybuffer.h +++ b/Include/pybuffer.h @@ -17,7 +17,8 @@ extern "C" { * */ -// Forward declaration +// Forward declaration to be able to include pybuffer.h before object.h: +// pybuffer.h uses PyObject and object.h uses Py_buffer. typedef struct _object PyObject; typedef struct {