@@ -32,7 +32,7 @@ extern "C" {
32
32
#endif
33
33
34
34
35
- // C++ compatibility
35
+ // C++ compatibility: _Py_CAST() and _Py_NULL
36
36
#ifndef _Py_CAST
37
37
# ifdef __cplusplus
38
38
# define _Py_CAST (type , expr ) \
@@ -41,10 +41,12 @@ extern "C" {
41
41
# define _Py_CAST (type , expr ) ((type)(expr))
42
42
# endif
43
43
#endif
44
- #ifdef __cplusplus
45
- # define PYCAPI_COMPAT_NULL nullptr
46
- #else
47
- # define PYCAPI_COMPAT_NULL NULL
44
+ #ifndef _Py_NULL
45
+ # ifdef __cplusplus
46
+ # define _Py_NULL nullptr
47
+ # else
48
+ # define _Py_NULL NULL
49
+ # endif
48
50
#endif
49
51
50
52
// Cast argument to PyObject* type.
@@ -150,8 +152,8 @@ _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
150
152
PYCAPI_COMPAT_STATIC_INLINE (PyCodeObject * )
151
153
PyFrame_GetCode (PyFrameObject * frame )
152
154
{
153
- assert (frame != PYCAPI_COMPAT_NULL );
154
- assert (frame -> f_code != PYCAPI_COMPAT_NULL );
155
+ assert (frame != _Py_NULL );
156
+ assert (frame -> f_code != _Py_NULL );
155
157
return _Py_CAST (PyCodeObject * , Py_NewRef (frame -> f_code ));
156
158
}
157
159
#endif
@@ -170,7 +172,7 @@ _PyFrame_GetCodeBorrow(PyFrameObject *frame)
170
172
PYCAPI_COMPAT_STATIC_INLINE (PyFrameObject * )
171
173
PyFrame_GetBack (PyFrameObject * frame )
172
174
{
173
- assert (frame != PYCAPI_COMPAT_NULL );
175
+ assert (frame != _Py_NULL );
174
176
return _Py_CAST (PyFrameObject * , Py_XNewRef (frame -> f_back ));
175
177
}
176
178
#endif
@@ -248,7 +250,7 @@ PyFrame_GetLasti(PyFrameObject *frame)
248
250
PYCAPI_COMPAT_STATIC_INLINE (PyInterpreterState * )
249
251
PyThreadState_GetInterpreter (PyThreadState * tstate )
250
252
{
251
- assert (tstate != PYCAPI_COMPAT_NULL );
253
+ assert (tstate != _Py_NULL );
252
254
return tstate -> interp ;
253
255
}
254
256
#endif
@@ -259,7 +261,7 @@ PyThreadState_GetInterpreter(PyThreadState *tstate)
259
261
PYCAPI_COMPAT_STATIC_INLINE (PyFrameObject * )
260
262
PyThreadState_GetFrame (PyThreadState * tstate )
261
263
{
262
- assert (tstate != PYCAPI_COMPAT_NULL );
264
+ assert (tstate != _Py_NULL );
263
265
return _Py_CAST (PyFrameObject * , Py_XNewRef (tstate -> frame ));
264
266
}
265
267
#endif
@@ -284,11 +286,11 @@ PyInterpreterState_Get(void)
284
286
PyInterpreterState * interp ;
285
287
286
288
tstate = PyThreadState_GET ();
287
- if (tstate == PYCAPI_COMPAT_NULL ) {
289
+ if (tstate == _Py_NULL ) {
288
290
Py_FatalError ("GIL released (tstate is NULL)" );
289
291
}
290
292
interp = tstate -> interp ;
291
- if (interp == PYCAPI_COMPAT_NULL ) {
293
+ if (interp == _Py_NULL ) {
292
294
Py_FatalError ("no current interpreter" );
293
295
}
294
296
return interp ;
@@ -301,7 +303,7 @@ PyInterpreterState_Get(void)
301
303
PYCAPI_COMPAT_STATIC_INLINE (uint64_t )
302
304
PyThreadState_GetID (PyThreadState * tstate )
303
305
{
304
- assert (tstate != PYCAPI_COMPAT_NULL );
306
+ assert (tstate != _Py_NULL );
305
307
return tstate -> id ;
306
308
}
307
309
#endif
@@ -325,8 +327,8 @@ PyThreadState_EnterTracing(PyThreadState *tstate)
325
327
PYCAPI_COMPAT_STATIC_INLINE (void )
326
328
PyThreadState_LeaveTracing (PyThreadState * tstate )
327
329
{
328
- int use_tracing = (tstate -> c_tracefunc != PYCAPI_COMPAT_NULL
329
- || tstate -> c_profilefunc != PYCAPI_COMPAT_NULL );
330
+ int use_tracing = (tstate -> c_tracefunc != _Py_NULL
331
+ || tstate -> c_profilefunc != _Py_NULL );
330
332
tstate -> tracing -- ;
331
333
#if PY_VERSION_HEX >= 0x030A00A1
332
334
tstate -> cframe -> use_tracing = use_tracing ;
@@ -387,9 +389,9 @@ PyModule_AddType(PyObject *module, PyTypeObject *type)
387
389
388
390
// inline _PyType_Name()
389
391
name = type -> tp_name ;
390
- assert (name != PYCAPI_COMPAT_NULL );
392
+ assert (name != _Py_NULL );
391
393
dot = strrchr (name , '.' );
392
- if (dot != PYCAPI_COMPAT_NULL ) {
394
+ if (dot != _Py_NULL ) {
393
395
name = dot + 1 ;
394
396
}
395
397
0 commit comments