bpo-40170: PyType_HasFeature() no longer acccess directly tp_flags by vstinner · Pull Request #19378 · python/cpython (original) (raw)

Can we have private inline function?

Yes, that's possible but I would prefer to add new functions to the internal C API for that. For example, add a fast _PyLong_Check() function.


In the past, I tried to reuse the same name for two implementation of the same function: one "slow" using a function call, one "fast" using a macro or static inline function.

I'm thinking at PyThreadState_GET(). The internal C API uses:

/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */
#undef PyThreadState_GET
#define PyThreadState_GET() _PyThreadState_GET()

The problem is that depending if the internal C API is included or not, you may get the slow or the fast function.

I changed my approach: use a different name for the fast function. _PyThreadState_GET() is guaranteed to be fast, but it's only provided by the internal C API. In short, using it ensures that you get the fast implementation, but also that the internal C API is included.