Sometimes in C extern module, in some function that returned an int (0 means successful and -1 means failed), people may mistaken write return NULL; in error branch (for example: in tp_setattro slot). Usually the IDE won’t warn it in c++ because it will be change to return 0; and 0 is a valid value to return, and then compiler will pass, but then problem will occurred in runtime because python find the return value is 0 means all right but error occurred.
However, in musllinux python version 3.10, the compiling will failed. The message is usually:
In file included from /usr/include/c++/14.2.0/clocale:42,
from /usr/include/c++/14.2.0/x86_64-alpine-linux-musl/bits/c++locale.h:41,
from /usr/include/c++/14.2.0/bits/localefwd.h:40,
from /usr/include/c++/14.2.0/string:45,
from xxx.cpp:8:
xxx.cpp: In function 'int XXX_delattr(PyObject*, PyObject*)':
xxx.cpp:a:b: error: cannot convert 'std::nullptr_t' to 'int' in return
a | return NULL;
| ^~~~
xxx.cpp:c:d: error: cannot convert 'std::nullptr_t' to 'int' in return
c | return NULL;
| ^~~~
error: command '/usr/bin/g++' failed with exit code 1
This can note programmer to change the wrong return value. So can we use that way in all of the systems to ensure programmer can find the problem in advance?