From 7c24a14e34eebb0e7ffba5a5c8772c84ffea2147 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 01:57:30 +0530 Subject: [PATCH 1/8] Document Py_ARRAY_LENGTH macro in intro.rst Added documentation for the Py_ARRAY_LENGTH macro, explaining its usage and requirements. --- Doc/c-api/intro.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index c76cc2f70ecccf..b2713df0b10d76 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -303,6 +303,16 @@ 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: From 40acd8f48b0e0c542b4a24768ca5c3991afe540b Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 02:09:57 +0530 Subject: [PATCH 2/8] Update Doc/c-api/intro.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/intro.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index b2713df0b10d76..46c8b0859102b3 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -314,6 +314,7 @@ complete listing. This is generally equivalent to:: sizeof(array) / sizeof((array)[0]) + .. _api-objects: Objects, Types and Reference Counts From 4234c8b52b843618c43f5c4db112f7f1ce9dd927 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 02:10:36 +0530 Subject: [PATCH 3/8] Update Doc/c-api/intro.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/intro.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 46c8b0859102b3..d902959570477b 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -312,6 +312,7 @@ complete listing. not a pointer. Using this macro with a pointer will produce incorrect results. This is generally equivalent to:: + sizeof(array) / sizeof((array)[0]) From 8191b69ac37bcbcabdc1ccd79ef5f8a4e56c4c57 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 02:10:53 +0530 Subject: [PATCH 4/8] Update Doc/c-api/intro.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/intro.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index d902959570477b..fe4f9c2f082e75 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -316,6 +316,7 @@ complete listing. sizeof(array) / sizeof((array)[0]) + .. _api-objects: Objects, Types and Reference Counts From f3a7fb70908cd494d59c5953bdbafc4f177940a4 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 15:16:39 +0530 Subject: [PATCH 5/8] Update Doc/c-api/intro.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/c-api/intro.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index fe4f9c2f082e75..d8669e03f4f249 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -309,7 +309,9 @@ complete listing. 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. + not a pointer. On supported compilers, passing a pointer will result in a + compilation error, otherwise, using this macro with a pointer will + produce incorrect results. This is generally equivalent to:: From 030158711278ba72bbcb10fd81aecffcaf3bee96 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 15:47:55 +0530 Subject: [PATCH 6/8] =?UTF-8?q?Remove=20=E2=80=9Cgenerally=20equivalent?= =?UTF-8?q?=E2=80=9D=20phrasing=20as=20per=20review=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed redundant explanation of array size calculation. --- Doc/c-api/intro.rst | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index d8669e03f4f249..2b9238b7458822 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -313,12 +313,7 @@ complete listing. compilation error, otherwise, using this macro with a pointer will produce incorrect results. - This is generally equivalent to:: - - sizeof(array) / sizeof((array)[0]) - - - + .. _api-objects: Objects, Types and Reference Counts From 7f64d0b4401a2c655456092310afe394f07fde17 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Sun, 16 Nov 2025 15:51:14 +0530 Subject: [PATCH 7/8] Update Doc/c-api/intro.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/c-api/intro.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 2b9238b7458822..d15980cdaf78d1 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -313,7 +313,7 @@ complete listing. compilation error, otherwise, using this macro with a pointer will produce incorrect results. - + .. _api-objects: Objects, Types and Reference Counts From 79622585b3728bc4772216a15b5d9355391a220f Mon Sep 17 00:00:00 2001 From: Yashraj Date: Mon, 17 Nov 2025 23:07:50 +0530 Subject: [PATCH 8/8] Update Doc/c-api/intro.rst Co-authored-by: Peter Bierma --- Doc/c-api/intro.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index d15980cdaf78d1..1458b7c53b1cea 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -310,8 +310,7 @@ complete listing. The *array* argument must be a C array with a size known at compile time, not a pointer. On supported compilers, passing a pointer will result in a - compilation error, otherwise, using this macro with a pointer will - produce incorrect results. + compilation error or otherwise produce incorrect results. .. _api-objects: