gh-141004: Document Py_ARRAY_LENGTH macro by Yashp002 · Pull Request #141598 · python/cpython
Fixes part of #141004
Added documentation for the Py_ARRAY_LENGTH macro in Doc/c-api/structures.rst. This macro computes the length of a statically allocated C array at compile time.
The documentation includes:
- Description of the macro's purpose
- Explanation of what it works with (static arrays only)
- Warning about pointer incompatibility
- Code definition
📚 Documentation preview 📚: https://cpython-previews--141598.org.readthedocs.build/
Comment on lines +741 to +743
| This macro is defined as:: | ||
|
|
||
| #define Py_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0])) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this is wrong since depending on the GCC version it varies.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's just say something like "This is generally equivalent to ..."
|
|
||
| #define Py_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0])) | ||
|
|
||
| .. versionadded:: 3.13 |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, it has been around for many years (2.7 & before).
Comment on lines 717 to 727
| In previous versions, the macros were only available with | ||
| ``#include "structmember.h"`` and were named without the ``Py_`` prefix | ||
| (e.g. as ``T_INT``). | ||
| The header is still available and contains the old names, along with | ||
| the following deprecated types: | ||
|
|
||
| .. c:macro:: T_OBJECT | ||
|
|
||
| Like ``Py_T_OBJECT_EX``, but ``NULL`` is converted to ``None``. | ||
| This results in surprising behavior in Python: deleting the attribute | ||
| effectively sets it to ``None``. |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it in this section? Useful macros seems to be a better place IMO.
Thanks @StanFromIreland for the review, Fixing all three issues now:
Moving to Useful macros section
Removing versionadded tag (my mistake on the version)
Changing to "generally equivalent to" for the definition
| @@ -1 +1 @@ | |||
| ../../Lib/_colorize.py No newline at end of file | |||
| ../../Lib/_colorize.py | |||
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I take that back, this happened and the CI broke, please revert unrelated changes.
Comment on lines +733 to +734
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mypy failures appear unrelated to the documentation changes
Indeed, but you have made changes to their configuration files too, see my review above, please revert the unrelated changes.