Skip to content

Conversation

@Yashp002
Copy link

@Yashp002 Yashp002 commented Nov 15, 2025

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/

@python-cla-bot
Copy link

python-cla-bot bot commented Nov 15, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Comment on lines 741 to 743
This macro is defined as::
#define Py_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0]))
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

@StanFromIreland StanFromIreland Nov 15, 2025

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``.
Copy link
Member

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.

@ZeroIntensity ZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Nov 15, 2025
@Yashp002
Copy link
Author

Yashp002 commented Nov 15, 2025

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

@StanFromIreland
Copy link
Member

Something odd happened and the CI broke :-(

@@ -1 +1 @@
../../Lib/_colorize.py
../../Lib/_colorize.py
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Unrelated changes.

@Yashp002
Copy link
Author

Yashp002 commented Nov 15, 2025

right sorry gimme a minute, it's my first PR actually 😭

@StanFromIreland
Copy link
Member

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.

@Yashp002 Yashp002 closed this Nov 15, 2025
@Yashp002
Copy link
Author

I'm closing this to submit clean version in a couple of minutes and actively awaiting review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants