Introduce macro `Py_NOEXCEPT`

This macro can reduce the size of c++ extensions’ size:

#ifdef __cplusplus
#define Py_NOEXCEPT noexcept
#else
#define Py_NOEXCEPT
#endif

By this way we can safely declare that python-capi functions won’t throw c++ exceptions, which can make c++ extension faster.

First, have you measured that it actually gives a meaningful improvement? The same logic applies to basically all c libraries called from c++ and I don’t think I’ve ever seen anyone worry about your before.

Second, Python is compiled with a c compiler but can be called with a c++ compiler. This means that you only get one half of the mechanism: a c++ function marked with noexcept will call std::terminate if an exception is about to escape. The Python C API functions won’t do that. So all you’re getting is the assumption from the caller that it won’t happen?

It’d obviously be a bad thing if a c++ exception did propagate through the Python stack because it just isn’t designed to handle them. But there’s nothing actually stopping it.

When I just add noexcept on my c++ extension, the size of the product drop about 5%.

The noexcept will be shown just to c++ compiler and it can do more optimizing on calling c functions.

Anyway, without the assume that the programmer will write code rightly, all actions are nonsence.