From 424d959c921efbd59689aa81e86f53923b4a36ba Mon Sep 17 00:00:00 2001 From: Yash Date: Sun, 16 Nov 2025 00:28:47 +0530 Subject: [PATCH 1/3] gh-141004: Document Py_ARRAY_LENGTH macro --- Doc/c-api/structures.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index 58dd915e04f619..013dcfbbb9af9a 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -730,6 +730,21 @@ Macro name C type Python type Always ``None``. Must be used with :c:macro:`Py_READONLY`. + .. c:macro:: Py_ARRAY_LENGTH(array) + + Compute the length (number of elements) of a statically allocated C array at + compile time. + + The *array* argument must be a C array with a size known at compile time, + not a pointer. Using this macro with a pointer will produce incorrect results. + + This macro is defined as:: + + #define Py_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0])) + + .. versionadded:: 3.13 + + Defining Getters and Setters ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From cf9336045d072d0a97f9a0d2602ee876cfb04138 Mon Sep 17 00:00:00 2001 From: Yash Date: Sun, 16 Nov 2025 01:02:24 +0530 Subject: [PATCH 2/3] Move Py_ARRAY_LENGTH to Useful macros, use 'generally equivalent' --- Doc/c-api/intro.rst | 12 ++++++++++++ Doc/c-api/structures.rst | 15 +-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index c76cc2f70ecccf..d902959570477b 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -303,6 +303,18 @@ complete listing. PyDoc_VAR(python_doc) = PyDoc_STR("A genus of constricting snakes in the Pythonidae family native " "to the tropics and subtropics of the Eastern Hemisphere."); +.. c:macro:: Py_ARRAY_LENGTH(array) + + Compute the length (number of elements) of a statically allocated C array at + compile time. + + The *array* argument must be a C array with a size known at compile time, + not a pointer. Using this macro with a pointer will produce incorrect results. + + This is generally equivalent to:: + + sizeof(array) / sizeof((array)[0]) + .. _api-objects: diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index 013dcfbbb9af9a..1a26aafbd9233e 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -730,20 +730,7 @@ Macro name C type Python type Always ``None``. Must be used with :c:macro:`Py_READONLY`. - .. c:macro:: Py_ARRAY_LENGTH(array) - - Compute the length (number of elements) of a statically allocated C array at - compile time. - - The *array* argument must be a C array with a size known at compile time, - not a pointer. Using this macro with a pointer will produce incorrect results. - - This macro is defined as:: - - #define Py_ARRAY_LENGTH(array) (sizeof(array) / sizeof((array)[0])) - - .. versionadded:: 3.13 - + Defining Getters and Setters ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From d96374ee1fc18189ec4cfc8d1dce97dfa222c3a7 Mon Sep 17 00:00:00 2001 From: Yash Date: Sun, 16 Nov 2025 01:05:28 +0530 Subject: [PATCH 3/3] Move Py_ARRAY_LENGTH to Useful macros, use 'generally equivalent' --- Doc/c-api/structures.rst | 2 +- Misc/mypy/_colorize.py | 2 +- Misc/mypy/token.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index 1a26aafbd9233e..621bf938895a9c 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -730,7 +730,7 @@ Macro name C type Python type Always ``None``. Must be used with :c:macro:`Py_READONLY`. - + Defining Getters and Setters ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Misc/mypy/_colorize.py b/Misc/mypy/_colorize.py index 9b7304769ec30b..5d2723595daa8d 120000 --- a/Misc/mypy/_colorize.py +++ b/Misc/mypy/_colorize.py @@ -1 +1 @@ -../../Lib/_colorize.py \ No newline at end of file +../../Lib/_colorize.py diff --git a/Misc/mypy/token.py b/Misc/mypy/token.py index 0a39f726dda1aa..9f38e9c897fb0c 120000 --- a/Misc/mypy/token.py +++ b/Misc/mypy/token.py @@ -1 +1 @@ -../../Lib/token.py \ No newline at end of file +../../Lib/token.py