Skip to content

Commit 11cb80f

Browse files
authored
Don't include structmember.h in pythoncapi_compat.h (#161)
Avoids conflicts due to names without "Py" prefixes.
1 parent e3efede commit 11cb80f

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

pythoncapi_compat.h

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ extern "C" {
2525
#if PY_VERSION_HEX < 0x030b00B4 && !defined(PYPY_VERSION)
2626
# include "frameobject.h" // PyFrameObject, PyFrame_GetBack()
2727
#endif
28-
#if PY_VERSION_HEX < 0x030C00A3
29-
# include <structmember.h> // T_SHORT, READONLY
30-
#endif
3128

3229

3330
#ifndef _Py_CAST
@@ -1919,33 +1916,33 @@ PyLongWriter_Finish(PyLongWriter *writer)
19191916

19201917

19211918
#if PY_VERSION_HEX < 0x030C00A3
1922-
# define Py_T_SHORT T_SHORT
1923-
# define Py_T_INT T_INT
1924-
# define Py_T_LONG T_LONG
1925-
# define Py_T_FLOAT T_FLOAT
1926-
# define Py_T_DOUBLE T_DOUBLE
1927-
# define Py_T_STRING T_STRING
1928-
# define _Py_T_OBJECT T_OBJECT
1929-
# define Py_T_CHAR T_CHAR
1930-
# define Py_T_BYTE T_BYTE
1931-
# define Py_T_UBYTE T_UBYTE
1932-
# define Py_T_USHORT T_USHORT
1933-
# define Py_T_UINT T_UINT
1934-
# define Py_T_ULONG T_ULONG
1935-
# define Py_T_STRING_INPLACE T_STRING_INPLACE
1936-
# define Py_T_BOOL T_BOOL
1937-
# define Py_T_OBJECT_EX T_OBJECT_EX
1938-
# define Py_T_LONGLONG T_LONGLONG
1939-
# define Py_T_ULONGLONG T_ULONGLONG
1940-
# define Py_T_PYSSIZET T_PYSSIZET
1919+
# define Py_T_SHORT 0
1920+
# define Py_T_INT 1
1921+
# define Py_T_LONG 2
1922+
# define Py_T_FLOAT 3
1923+
# define Py_T_DOUBLE 4
1924+
# define Py_T_STRING 5
1925+
# define _Py_T_OBJECT 6
1926+
# define Py_T_CHAR 7
1927+
# define Py_T_BYTE 8
1928+
# define Py_T_UBYTE 9
1929+
# define Py_T_USHORT 10
1930+
# define Py_T_UINT 11
1931+
# define Py_T_ULONG 12
1932+
# define Py_T_STRING_INPLACE 13
1933+
# define Py_T_BOOL 14
1934+
# define Py_T_OBJECT_EX 16
1935+
# define Py_T_LONGLONG 17
1936+
# define Py_T_ULONGLONG 18
1937+
# define Py_T_PYSSIZET 19
19411938

19421939
# if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
1943-
# define _Py_T_NONE T_NONE
1940+
# define _Py_T_NONE 20
19441941
# endif
19451942

1946-
# define Py_READONLY READONLY
1947-
# define Py_AUDIT_READ READ_RESTRICTED
1948-
# define _Py_WRITE_RESTRICTED PY_WRITE_RESTRICTED
1943+
# define Py_READONLY 1
1944+
# define Py_AUDIT_READ 2
1945+
# define _Py_WRITE_RESTRICTED 4
19491946
#endif
19501947

19511948

tests/test_pythoncapi_compat_cext.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#undef NDEBUG
33

44
#include "pythoncapi_compat.h"
5+
#include <structmember.h> // T_SHORT, READONLY
56

67
#ifdef NDEBUG
78
# error "assertions must be enabled"
@@ -2118,32 +2119,32 @@ test_long_stdint(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
21182119
static PyObject *
21192120
test_structmember(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
21202121
{
2121-
assert(Py_T_SHORT >= 0);
2122-
assert(Py_T_INT >= 0);
2123-
assert(Py_T_LONG >= 0);
2124-
assert(Py_T_FLOAT >= 0);
2125-
assert(Py_T_DOUBLE >= 0);
2126-
assert(Py_T_STRING >= 0);
2127-
assert(_Py_T_OBJECT >= 0);
2128-
assert(Py_T_CHAR >= 0);
2129-
assert(Py_T_BYTE >= 0);
2130-
assert(Py_T_UBYTE >= 0);
2131-
assert(Py_T_USHORT >= 0);
2132-
assert(Py_T_UINT >= 0);
2133-
assert(Py_T_ULONG >= 0);
2134-
assert(Py_T_STRING_INPLACE >= 0);
2135-
assert(Py_T_BOOL >= 0);
2136-
assert(Py_T_OBJECT_EX >= 0);
2137-
assert(Py_T_LONGLONG >= 0);
2138-
assert(Py_T_ULONGLONG >= 0);
2139-
assert(Py_T_PYSSIZET >= 0);
2122+
assert(Py_T_SHORT == T_SHORT);
2123+
assert(Py_T_SHORT == T_SHORT);
2124+
assert(Py_T_INT == T_INT);
2125+
assert(Py_T_LONG == T_LONG);
2126+
assert(Py_T_FLOAT == T_FLOAT);
2127+
assert(Py_T_DOUBLE == T_DOUBLE);
2128+
assert(Py_T_STRING == T_STRING);
2129+
assert(_Py_T_OBJECT == T_OBJECT);
2130+
assert(Py_T_CHAR == T_CHAR);
2131+
assert(Py_T_BYTE == T_BYTE);
2132+
assert(Py_T_UBYTE == T_UBYTE);
2133+
assert(Py_T_USHORT == T_USHORT);
2134+
assert(Py_T_UINT == T_UINT);
2135+
assert(Py_T_ULONG == T_ULONG);
2136+
assert(Py_T_STRING_INPLACE == T_STRING_INPLACE);
2137+
assert(Py_T_BOOL == T_BOOL);
2138+
assert(Py_T_OBJECT_EX == T_OBJECT_EX);
2139+
assert(Py_T_LONGLONG == T_LONGLONG);
2140+
assert(Py_T_ULONGLONG == T_ULONGLONG);
2141+
assert(Py_T_PYSSIZET == T_PYSSIZET);
21402142
#if PY_VERSION_HEX >= 0x03000000 && !defined(PYPY_VERSION)
2141-
assert(_Py_T_NONE >= 0);
2143+
assert(_Py_T_NONE == T_NONE);
21422144
#endif
2143-
2144-
assert(Py_READONLY >= 0);
2145-
assert(Py_AUDIT_READ >= 0);
2146-
assert(_Py_WRITE_RESTRICTED >= 0);
2145+
assert(Py_READONLY == READONLY);
2146+
assert(Py_AUDIT_READ == READ_RESTRICTED);
2147+
assert(_Py_WRITE_RESTRICTED == PY_WRITE_RESTRICTED);
21472148

21482149
Py_RETURN_NONE;
21492150
}

0 commit comments

Comments
 (0)