◐ Shell
clean mode source ↗

gh-91321: Add _Py_NULL macro by vstinner · Pull Request #92253 · python/cpython

Currently, with gcc -Wzero-as-null-pointer-constant, there is no C++ compiler warning when including <Python.h>. But using clang -Wzero-as-null-pointer-constant, I get many warnings (errors). A few examples:

$ CC=clang ./python -m test -v test_cppext
(...)
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:44:
/home/vstinner/python/main/Include/object.h:590:15: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
    if (op != NULL) {
              ^~~~
              nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:44:
/home/vstinner/python/main/Include/object.h:600:15: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
    if (op != NULL) {
              ^~~~
              nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:51:
In file included from /home/vstinner/python/main/Include/unicodeobject.h:1042:
/home/vstinner/python/main/Include/cpython/unicodeobject.h:645:42: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
    if (_PyASCIIObject_CAST(op)->wstr == NULL) {
                                         ^~~~
                                         nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^
(...)
Tests result: FAILURE