@@ -32,7 +32,7 @@ extern "C" {
3232#endif
3333
3434
35- // C++ compatibility
35+ // C++ compatibility: _Py_CAST() and _Py_NULL
3636#ifndef _Py_CAST
3737# ifdef __cplusplus
3838# define _Py_CAST (type , expr ) \
@@ -41,10 +41,12 @@ extern "C" {
4141# define _Py_CAST (type , expr ) ((type)(expr))
4242# endif
4343#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
4850#endif
4951
5052// Cast argument to PyObject* type.
@@ -150,8 +152,8 @@ _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
150152PYCAPI_COMPAT_STATIC_INLINE (PyCodeObject * )
151153PyFrame_GetCode (PyFrameObject * frame )
152154{
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 );
155157 return _Py_CAST (PyCodeObject * , Py_NewRef (frame -> f_code ));
156158}
157159#endif
@@ -170,7 +172,7 @@ _PyFrame_GetCodeBorrow(PyFrameObject *frame)
170172PYCAPI_COMPAT_STATIC_INLINE (PyFrameObject * )
171173PyFrame_GetBack (PyFrameObject * frame )
172174{
173- assert (frame != PYCAPI_COMPAT_NULL );
175+ assert (frame != _Py_NULL );
174176 return _Py_CAST (PyFrameObject * , Py_XNewRef (frame -> f_back ));
175177}
176178#endif
@@ -248,7 +250,7 @@ PyFrame_GetLasti(PyFrameObject *frame)
248250PYCAPI_COMPAT_STATIC_INLINE (PyInterpreterState * )
249251PyThreadState_GetInterpreter (PyThreadState * tstate )
250252{
251- assert (tstate != PYCAPI_COMPAT_NULL );
253+ assert (tstate != _Py_NULL );
252254 return tstate -> interp ;
253255}
254256#endif
@@ -259,7 +261,7 @@ PyThreadState_GetInterpreter(PyThreadState *tstate)
259261PYCAPI_COMPAT_STATIC_INLINE (PyFrameObject * )
260262PyThreadState_GetFrame (PyThreadState * tstate )
261263{
262- assert (tstate != PYCAPI_COMPAT_NULL );
264+ assert (tstate != _Py_NULL );
263265 return _Py_CAST (PyFrameObject * , Py_XNewRef (tstate -> frame ));
264266}
265267#endif
@@ -284,11 +286,11 @@ PyInterpreterState_Get(void)
284286 PyInterpreterState * interp ;
285287
286288 tstate = PyThreadState_GET ();
287- if (tstate == PYCAPI_COMPAT_NULL ) {
289+ if (tstate == _Py_NULL ) {
288290 Py_FatalError ("GIL released (tstate is NULL)" );
289291 }
290292 interp = tstate -> interp ;
291- if (interp == PYCAPI_COMPAT_NULL ) {
293+ if (interp == _Py_NULL ) {
292294 Py_FatalError ("no current interpreter" );
293295 }
294296 return interp ;
@@ -301,7 +303,7 @@ PyInterpreterState_Get(void)
301303PYCAPI_COMPAT_STATIC_INLINE (uint64_t )
302304PyThreadState_GetID (PyThreadState * tstate )
303305{
304- assert (tstate != PYCAPI_COMPAT_NULL );
306+ assert (tstate != _Py_NULL );
305307 return tstate -> id ;
306308}
307309#endif
@@ -325,8 +327,8 @@ PyThreadState_EnterTracing(PyThreadState *tstate)
325327PYCAPI_COMPAT_STATIC_INLINE (void )
326328PyThreadState_LeaveTracing (PyThreadState * tstate )
327329{
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 );
330332 tstate -> tracing -- ;
331333#if PY_VERSION_HEX >= 0x030A00A1
332334 tstate -> cframe -> use_tracing = use_tracing ;
@@ -387,9 +389,9 @@ PyModule_AddType(PyObject *module, PyTypeObject *type)
387389
388390 // inline _PyType_Name()
389391 name = type -> tp_name ;
390- assert (name != PYCAPI_COMPAT_NULL );
392+ assert (name != _Py_NULL );
391393 dot = strrchr (name , '.' );
392- if (dot != PYCAPI_COMPAT_NULL ) {
394+ if (dot != _Py_NULL ) {
393395 name = dot + 1 ;
394396 }
395397
0 commit comments