gh-139165: Make Py_SIZE, Py_IS_TYPE,Py_ SET_SIZE regular functions in stable ABI#139166
Conversation
Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros. Format repetitive definitions in object.c more concisely. Py_SET_TYPE is still left out of the Limited API.
| #elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15) | ||
| # if Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14) |
There was a problem hiding this comment.
No, but I can expand the comments :)
- Don't expose the "real" functions for old Limited API - Move implementations below defines so that they pick up the right Py_TYPE definition
…ons in stable ABI (pythonGH-139166) * Make Py_{SIZE,IS_TYPE,SET_SIZE} regular functions in stable ABI Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros. Format repetitive definitions in object.c more concisely. Py_SET_TYPE is still left out of the Limited API.
…ons in stable ABI (pythonGH-139166) * Make Py_{SIZE,IS_TYPE,SET_SIZE} regular functions in stable ABI Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros. Format repetitive definitions in object.c more concisely. Py_SET_TYPE is still left out of the Limited API.
| #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15) | ||
| PyAPI_FUNC(Py_ssize_t) Py_SIZE(PyObject *ob); | ||
| PyAPI_FUNC(int) Py_IS_TYPE(PyObject *ob, PyTypeObject *type); | ||
| PyAPI_FUNC(void) Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size); | ||
| #endif |
There was a problem hiding this comment.
I'm just checking PyO3's FFI definitions against 3.15b1 and it seems to me that this PR has changed these symbols to always be exported functions on 3.15.
That seems to differ with the issue description, which apparently intended to keep the static inline functions for the non-limited API?
There was a problem hiding this comment.
Extract of object.c in the 3.15 branch:
static inline int
_Py_IS_TYPE_impl(PyObject *ob, PyTypeObject *type)
{
return Py_TYPE(ob) == type;
}
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11)
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl(_PyObject_CAST(ob), (type))
#elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15)
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl((ob), (type))
#else
// Limited API 3.15+: use function calls
#endifIf Py_LIMITED_API is not defined or if it's defined to Python 3.14 or older, Py_IS_TYPE() is implemented as a static inline function. The code has been modified since this PR.
Would you mind to elaborate which API is implemented as a function call? Using the limited C API or not? Which limited C API version?
There was a problem hiding this comment.
You're right, sorry for the confusion. I think the tooling I was using to check had a bug, and then I saw this diff and got myself confused. 🤦
Even looking at this diff again, the #define macros just below starting on 292 will implement as a static inline function.
Sorry for the noise!
There was a problem hiding this comment.
No problem. Thanks for double checking.
Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros.
Format repetitive definitions in object.c more concisely.
Py_SET_TYPE is still left out of the Limited API.
📚 Documentation preview 📚: https://cpython-previews--139166.org.readthedocs.build/