Skip to content

Commit 66b3cd7

Browse files
authored
bpo-45459: Rename buffer.h to pybuffer.h (#31201)
Rename Include/buffer.h header file to Include/pybuffer.h to avoid conflicts 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.
1 parent b899126 commit 66b3cd7

File tree

7 files changed

+13
-4
lines changed

7 files changed

+13
-4
lines changed

Include/Python.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "pymacro.h"
4040
#include "pymath.h"
4141
#include "pymem.h"
42+
#include "pybuffer.h"
4243
#include "object.h"
4344
#include "objimpl.h"
4445
#include "typeslots.h"
@@ -50,7 +51,6 @@
5051
#include "longobject.h"
5152
#include "cpython/longintrepr.h"
5253
#include "boolobject.h"
53-
#include "buffer.h"
5454
#include "floatobject.h"
5555
#include "complexobject.h"
5656
#include "rangeobject.h"

Include/cpython/object.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
#include "buffer.h" // for Py_buffer, included after PyObject has been defined
6-
75
PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
86

97
#ifdef Py_TRACE_REFS

Include/buffer.h renamed to Include/pybuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ extern "C" {
1717
*
1818
*/
1919

20+
// Forward declaration to be able to include pybuffer.h before object.h:
21+
// pybuffer.h uses PyObject and object.h uses Py_buffer.
22+
typedef struct _object PyObject;
23+
2024
typedef struct {
2125
void *buf;
2226
PyObject *obj; /* owned reference */

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ PYTHON_HEADERS= \
14391439
$(srcdir)/Include/abstract.h \
14401440
$(srcdir)/Include/bltinmodule.h \
14411441
$(srcdir)/Include/boolobject.h \
1442-
$(srcdir)/Include/buffer.h \
14431442
$(srcdir)/Include/bytearrayobject.h \
14441443
$(srcdir)/Include/bytesobject.h \
14451444
$(srcdir)/Include/ceval.h \
@@ -1472,6 +1471,7 @@ PYTHON_HEADERS= \
14721471
$(srcdir)/Include/osdefs.h \
14731472
$(srcdir)/Include/osmodule.h \
14741473
$(srcdir)/Include/patchlevel.h \
1474+
$(srcdir)/Include/pybuffer.h \
14751475
$(srcdir)/Include/pycapsule.h \
14761476
$(srcdir)/Include/pydtrace.h \
14771477
$(srcdir)/Include/pyerrors.h \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Rename ``Include/buffer.h`` header file to ``Include/pybuffer.h`` to avoid
2+
conflits with projects having an existing ``buffer.h`` header file. Patch by
3+
Victor Stinner.

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
<ClInclude Include="..\Include\osmodule.h" />
264264
<ClInclude Include="..\Include\patchlevel.h" />
265265
<ClInclude Include="..\Include\py_curses.h" />
266+
<ClInclude Include="..\Include\pybuffer.h" />
266267
<ClInclude Include="..\Include\pycapsule.h" />
267268
<ClInclude Include="..\Include\pyerrors.h" />
268269
<ClInclude Include="..\Include\pyexpat.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
<ClInclude Include="..\Include\py_curses.h">
148148
<Filter>Include</Filter>
149149
</ClInclude>
150+
<ClInclude Include="..\Include\pybuffer.h">
151+
<Filter>Include</Filter>
152+
</ClInclude>
150153
<ClInclude Include="..\Include\pycapsule.h">
151154
<Filter>Include</Filter>
152155
</ClInclude>

0 commit comments

Comments
 (0)