Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ebe8a5

Browse files
committed
Don't fine a macro if it's already defined
1 parent a11cc68 commit 6ebe8a5

2 files changed

Lines changed: 44 additions & 22 deletions

File tree

README.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,33 +178,33 @@ Python 3.9
178178
::
179179

180180
// PyObject
181-
void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
182-
void Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
183-
void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
184-
int Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type)
181+
void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt);
182+
void Py_SET_TYPE(PyObject *ob, PyTypeObject *type);
183+
void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size);
184+
int Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type);
185185

186-
PyObject* PyObject_CallNoArgs(PyObject *func)
187-
PyObject* PyObject_CallOneArg(PyObject *func, PyObject *arg)
186+
PyObject* PyObject_CallNoArgs(PyObject *func);
187+
PyObject* PyObject_CallOneArg(PyObject *func, PyObject *arg);
188188

189189
// PyFrameObject
190-
PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
191-
PyFrameObject* PyFrame_GetBack(PyFrameObject *frame)
190+
PyCodeObject* PyFrame_GetCode(PyFrameObject *frame);
191+
PyFrameObject* PyFrame_GetBack(PyFrameObject *frame);
192192

193193
// PyThreadState
194-
PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
195-
PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate)
194+
PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate);
195+
PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate);
196196
// Availability: Python 3.7+
197-
uint64_t PyThreadState_GetID(PyThreadState *tstate)
197+
uint64_t PyThreadState_GetID(PyThreadState *tstate);
198198

199199
// PyInterpreterState
200-
PyInterpreterState* PyInterpreterState_Get(void)
200+
PyInterpreterState* PyInterpreterState_Get(void);
201201

202202
// GC protocol
203-
int PyObject_GC_IsTracked(PyObject* obj)
204-
int PyObject_GC_IsFinalized(PyObject *obj)
203+
int PyObject_GC_IsTracked(PyObject* obj);
204+
int PyObject_GC_IsFinalized(PyObject *obj);
205205

206206
// Module helper
207-
int PyModule_AddType(PyObject *module, PyTypeObject *type)
207+
int PyModule_AddType(PyObject *module, PyTypeObject *type);
208208

209209

210210
Run tests

pythoncapi_compat.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ extern "C" {
2525
#endif
2626

2727

28-
// bpo-42262 added Py_NewRef() and Py_XNewRef() to Python 3.10.0a3
28+
// bpo-42262 added Py_NewRef() to Python 3.10.0a3
2929
#if PY_VERSION_HEX < 0x030a00A3
3030
static inline PyObject* Py_NewRef(PyObject *obj)
3131
{
3232
Py_INCREF(obj);
3333
return obj;
3434
}
35+
#endif
36+
3537

38+
// bpo-42262 added Py_XNewRef() to Python 3.10.0a3
39+
#if PY_VERSION_HEX < 0x030a00A3
3640
static inline PyObject* Py_XNewRef(PyObject *obj)
3741
{
3842
Py_XINCREF(obj);
@@ -41,33 +45,39 @@ static inline PyObject* Py_XNewRef(PyObject *obj)
4145
#endif
4246

4347

44-
// bpo-39573: Py_TYPE(), Py_REFCNT() and Py_SIZE() can no longer be used
45-
// as l-value in Python 3.10.
46-
#if PY_VERSION_HEX < 0x030900A4
48+
// bpo-39573 added Py_SET_REFCNT() to Python 3.9.0a4
49+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_REFCNT)
4750
static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
4851
{
4952
ob->ob_refcnt = refcnt;
5053
}
5154
#define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT((PyObject*)(ob), refcnt)
55+
#endif
5256

5357

58+
// bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4
59+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
5460
static inline void
5561
_Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
5662
{
5763
ob->ob_type = type;
5864
}
5965
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
66+
#endif
67+
6068

69+
// bpo-39573 added Py_SET_SIZE() to Python 3.9.0a4
70+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
6171
static inline void
6272
_Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
6373
{
6474
ob->ob_size = size;
6575
}
6676
#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
67-
68-
#endif // PY_VERSION_HEX < 0x030900A4
77+
#endif
6978

7079

80+
// bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1
7181
#if PY_VERSION_HEX < 0x030900B1
7282
static inline PyCodeObject*
7383
PyFrame_GetCode(PyFrameObject *frame)
@@ -89,6 +99,7 @@ _PyFrame_GetCodeBorrow(PyFrameObject *frame)
8999
}
90100

91101

102+
// bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1
92103
#if PY_VERSION_HEX < 0x030900B1
93104
static inline PyFrameObject*
94105
PyFrame_GetBack(PyFrameObject *frame)
@@ -109,6 +120,7 @@ _PyFrame_GetBackBorrow(PyFrameObject *frame)
109120
}
110121

111122

123+
// bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5
112124
#if PY_VERSION_HEX < 0x030900A5
113125
static inline PyInterpreterState *
114126
PyThreadState_GetInterpreter(PyThreadState *tstate)
@@ -119,6 +131,7 @@ PyThreadState_GetInterpreter(PyThreadState *tstate)
119131
#endif
120132

121133

134+
// bpo-40429 added PyThreadState_GetFrame() to Python 3.9.0b1
122135
#if PY_VERSION_HEX < 0x030900B1
123136
static inline PyFrameObject*
124137
PyThreadState_GetFrame(PyThreadState *tstate)
@@ -139,6 +152,7 @@ _PyThreadState_GetFrameBorrow(PyThreadState *tstate)
139152
}
140153

141154

155+
// bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a5
142156
#if PY_VERSION_HEX < 0x030900A5
143157
static inline PyInterpreterState *
144158
PyInterpreterState_Get(void)
@@ -156,6 +170,7 @@ PyInterpreterState_Get(void)
156170
#endif
157171

158172

173+
// bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a6
159174
#if 0x030700A1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030900A6
160175
static inline uint64_t
161176
PyThreadState_GetID(PyThreadState *tstate)
@@ -166,6 +181,7 @@ PyThreadState_GetID(PyThreadState *tstate)
166181
#endif
167182

168183

184+
// bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1
169185
#if PY_VERSION_HEX < 0x030900A1
170186
static inline PyObject*
171187
PyObject_CallNoArgs(PyObject *func)
@@ -175,6 +191,8 @@ PyObject_CallNoArgs(PyObject *func)
175191
#endif
176192

177193

194+
// bpo-39245 made PyObject_CallOneArg() public (previously called
195+
// _PyObject_CallOneArg) in Python 3.9.0a4
178196
#if PY_VERSION_HEX < 0x030900A4
179197
static inline PyObject*
180198
PyObject_CallOneArg(PyObject *func, PyObject *arg)
@@ -184,6 +202,7 @@ PyObject_CallOneArg(PyObject *func, PyObject *arg)
184202
#endif
185203

186204

205+
// bpo-40024 added PyModule_AddType() to Python 3.9.0a5
187206
#if PY_VERSION_HEX < 0x030900A5
188207
static inline int
189208
PyModule_AddType(PyObject *module, PyTypeObject *type)
@@ -211,6 +230,8 @@ PyModule_AddType(PyObject *module, PyTypeObject *type)
211230
#endif
212231

213232

233+
// bpo-40241 added PyObject_GC_IsTracked() and PyObject_GC_IsFinalized()
234+
// to Python 3.9.0a6
214235
#if PY_VERSION_HEX < 0x030900A6
215236
static inline int
216237
PyObject_GC_IsTracked(PyObject* obj)
@@ -226,7 +247,8 @@ PyObject_GC_IsFinalized(PyObject *obj)
226247
#endif // PY_VERSION_HEX < 0x030900A6
227248

228249

229-
#if PY_VERSION_HEX < 0x030900A4
250+
// bpo-39573 added Py_IS_TYPE() to Python 3.9.0a4
251+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE)
230252
static inline int
231253
_Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
232254
return ob->ob_type == type;

0 commit comments

Comments
 (0)