[Python-checkins] Define _Py_NULL as nullptr on C23 and newer (#108244)

vstinner webhook-mailer at python.org
Mon Aug 21 20:37:36 EDT 2023


https://github.com/python/cpython/commit/c965cf6dd1704a0138a4ef0a9c670e297cf66797
commit: c965cf6dd1704a0138a4ef0a9c670e297cf66797
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2023-08-22T02:37:32+02:00
summary:

Define _Py_NULL as nullptr on C23 and newer (#108244)

C23 standard added nullptr constant:
https://en.wikipedia.org/wiki/C23_(C_standard_revision)

files:
M Include/pyport.h

diff --git a/Include/pyport.h b/Include/pyport.h
index d7c6ae64f2bf2..2dc241389243d 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -24,9 +24,10 @@
 #define _Py_CAST(type, expr) ((type)(expr))
 
 // Static inline functions should use _Py_NULL rather than using directly NULL
-// to prevent C++ compiler warnings. On C++11 and newer, _Py_NULL is defined as
-// nullptr.
-#if defined(__cplusplus) && __cplusplus >= 201103
+// to prevent C++ compiler warnings. On C23 and newer and on C++11 and newer,
+// _Py_NULL is defined as nullptr.
+#if (defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L) \
+        || (defined(__cplusplus) && __cplusplus >= 201103)
 #  define _Py_NULL nullptr
 #else
 #  define _Py_NULL NULL



More information about the Python-checkins mailing list