Visitar URL original
gh-139165: Make Py_SIZE, Py_IS_TYPE,Py_ SET_SIZE regular functions in stable ABI by encukou · Pull Request #139166 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20250923004300/https://github.com/python/cpython/pull/139166
Skip to content

Conversation

encukou
Copy link
Member

@encukou encukou commented Sep 19, 2025 •

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/

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.
Include/object.h Outdated
Comment on lines 325 to 326
#elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15)
# if Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean >=?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I can expand the comments :)

Comment on lines +3398 to +3402
PyTypeObject* Py_TYPE(PyObject *ob) { return _Py_TYPE_impl(ob); }
Py_ssize_t Py_REFCNT(PyObject *ob) { return _Py_REFCNT(ob); }
Py_ssize_t Py_SIZE(PyObject *o) { return _Py_SIZE_impl(o); }
int Py_IS_TYPE(PyObject *o, PyTypeObject *t) { return _Py_IS_TYPE_impl(o, t); }
void Py_SET_SIZE(PyVarObject *o, Py_ssize_t s) { _Py_SET_SIZE_impl(o, s); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the regular PEP 7 formatting?

Suggested change
PyTypeObject* Py_TYPE(PyObject *ob) { return _Py_TYPE_impl(ob); }
Py_ssize_t Py_REFCNT(PyObject *ob) { return _Py_REFCNT(ob); }
Py_ssize_t Py_SIZE(PyObject *o) { return _Py_SIZE_impl(o); }
int Py_IS_TYPE(PyObject *o, PyTypeObject *t) { return _Py_IS_TYPE_impl(o, t); }
void Py_SET_SIZE(PyVarObject *o, Py_ssize_t s) { _Py_SET_SIZE_impl(o, s); }
PyTypeObject*
Py_TYPE(PyObject *ob)
{
return _Py_TYPE_impl(ob);
}
Py_ssize_t
Py_REFCNT(PyObject *ob)
{
return _Py_REFCNT(ob);
}
Py_ssize_t
Py_SIZE(PyObject *o)
{
return _Py_SIZE_impl(o);
}
int
Py_IS_TYPE(PyObject *o, PyTypeObject *t)
{
return _Py_IS_TYPE_impl(o, t);
}
void
Py_SET_SIZE(PyVarObject *o, Py_ssize_t s)
{
_Py_SET_SIZE_impl(o, s);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's easier to read in the compact form. If every line has the same structure it's easier to scan that the names match.
Plus, the comment is more visible as you don't need to scroll up to see it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, as you want. I don't have a strong preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants