Skip to content

gh-158810: Fix Py_ARRAY_LENGTH() macro on C++ - #158812

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:array_length
Oct 5, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:array_length

Conversation

@vstinner

@vstinner vstinner commented Oct 4, 2026 •

Copy link
Copy Markdown
Member
@vstinner

vstinner commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

I tested manually that the added test fails without the fix with g++ 16.2.1 (on Fedora 44): TestPublicCpp.test_build of test_cext fails in this case. The test pass with the fix.

@vstinner
vstinner merged commit b2bfbce into python:main Oct 5, 2026
56 checks passed
@vstinner
vstinner deleted the array_length branch October 5, 2026 11:30
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

I will backport the change to stable branches once the 3.15 branch will be unlocked (next week). I should first backport the test_cext refactoring which merged C and C++ tests in test_cext (remove test_cppext).

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 macOS 3.x (tier-2) has failed when building commit b2bfbce.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/725/builds/14663) and take a look at the build logs.
  4. Check if the failure is related to this commit (b2bfbce) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/725/builds/14663

Failed tests:

  • test_cext

Failed subtests:

  • test_build_abi3t - test.test_cext.TestPublicC.test_build_abi3t
  • test_build - test.test_cext.TestPublicC.test_build
  • test_build_limited - test.test_cext.TestPublicC.test_build_limited

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 127, in test_build_limited
    self.check_build('_test_cext_limited', limited=True)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 101, in check_build
    run_cmd('Install', cmd)
    ~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 81, in run_cmd
    subprocess.run(cmd, check=True, env=env)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/subprocess.py", line 692, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ['/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/env/bin/python.exe', '-X', 'dev', '-m', 'pip', 'install', '--no-build-isolation', '/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/pkg', '-v'] returned non-zero exit status 1.


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 134, in test_build_abi3t
    self.check_build('_test_cext_abi3t', abi3t=True)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 101, in check_build
    run_cmd('Install', cmd)
    ~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 81, in run_cmd
    subprocess.run(cmd, check=True, env=env)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/subprocess.py", line 692, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ['/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/env/bin/python.exe', '-X', 'dev', '-m', 'pip', 'install', '--no-build-isolation', '/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/pkg', '-v'] returned non-zero exit status 1.


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 114, in test_build
    self.check_build('_test_cext')
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 101, in check_build
    run_cmd('Install', cmd)
    ~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 81, in run_cmd
    subprocess.run(cmd, check=True, env=env)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/subprocess.py", line 692, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ['/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/env/bin/python.exe', '-X', 'dev', '-m', 'pip', 'install', '--no-build-isolation', '/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/pkg', '-v'] returned non-zero exit status 1.


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 134, in test_build_abi3t
    self.check_build('_test_cext_abi3t', abi3t=True)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 101, in check_build
    run_cmd('Install', cmd)
    ~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 81, in run_cmd
    subprocess.run(cmd, check=True, env=env)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/subprocess.py", line 692, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ['/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_32288æ/tempcwd/env/bin/python.exe', '-X', 'dev', '-m', 'pip', 'install', '--no-build-isolation', '/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_32288æ/tempcwd/pkg', '-v'] returned non-zero exit status 1.


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 114, in test_build
    self.check_build('_test_cext')
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 101, in check_build
    run_cmd('Install', cmd)
    ~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 81, in run_cmd
    subprocess.run(cmd, check=True, env=env)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/subprocess.py", line 692, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ['/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_32288æ/tempcwd/env/bin/python.exe', '-X', 'dev', '-m', 'pip', 'install', '--no-build-isolation', '/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_32288æ/tempcwd/pkg', '-v'] returned non-zero exit status 1.


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 127, in test_build_limited
    self.check_build('_test_cext_limited', limited=True)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 101, in check_build
    run_cmd('Install', cmd)
    ~~~~~~~^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_cext/__init__.py", line 81, in run_cmd
    subprocess.run(cmd, check=True, env=env)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/subprocess.py", line 692, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ['/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_32288æ/tempcwd/env/bin/python.exe', '-X', 'dev', '-m', 'pip', 'install', '--no-build-isolation', '/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_32288æ/tempcwd/pkg', '-v'] returned non-zero exit status 1.
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

Hi! The buildbot ARM64 macOS 3.x (tier-2) has failed

Ah, 3 tests build C extensions failed:

ERROR: test_build (test.test_cext.TestPublicC.test_build)
ERROR: test_build_abi3t (test.test_cext.TestPublicC.test_build_abi3t)
ERROR: test_build_limited (test.test_cext.TestPublicC.test_build_limited)

Example of error: extension used: (...) typeof()

  gcc -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -g -Og -Wall -I/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/build/test_python_28872æ/tempcwd/env/include -I/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Include -I/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build -c extension.c -o build/temp.macosx-26.6-arm64-cpython-316-pydebug/extension.o -Werror -D_Py_IS_TESTCEXT -Wcast-qual -pedantic-errors -Werror=declaration-after-statement -DMODULE_NAME=_test_cext
  extension.c:139:12: error: extension used [-Werror,-Wlanguage-extension-token]
    139 |     assert(Py_ARRAY_LENGTH(small_array) == 3);
        |            ^
  /Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Include/pymacro.h:221:59: note: expanded from macro 'Py_ARRAY_LENGTH'
    221 |      + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
        |                                                           ^
  extension.c:139:12: error: extension used [-Werror,-Wlanguage-extension-token]
  /Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Include/pymacro.h:222:59: note: expanded from macro 'Py_ARRAY_LENGTH'
    222 |                                                           typeof(&(array)[0]))))
        |                                                           ^
  extension.c:139:12: error: extension used [-Werror,-Wlanguage-extension-token]
  /Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Include/pymacro.h:221:59: note: expanded from macro 'Py_ARRAY_LENGTH'
    221 |      + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
        |                                                           ^
  extension.c:139:12: error: extension used [-Werror,-Wlanguage-extension-token]
  /Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Include/pymacro.h:222:59: note: expanded from macro 'Py_ARRAY_LENGTH'
    222 |                                                           typeof(&(array)[0]))))
        |                                                           ^
  4 errors generated.
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

I wrote PR #158838 to fix the "extension used" error.

vstinner added a commit that referenced this pull request Oct 13, 2026
* gh-158810: Fix Py_ARRAY_LENGTH() macro on C++ (#158812)

(cherry picked from commit b2bfbce)

* gh-158810: Use _Py_TYPEOF in Py_ARRAY_LENGTH() (#158838)

Fix the compiler warning "extension used" when building test_cext
with clang.

* test_cext no longer overrides the CC environment variable if it's
  already defined.
* test_cext now also logs __STRICT_ANSI__ macro.

(cherry picked from commit 85c03d4)

* Add Py_SETREF/XSETREF tests to test_cext
vstinner added a commit that referenced this pull request Oct 13, 2026
* [3.15] gh-158810: Fix Py_ARRAY_LENGTH() macro on C++ (#159315)

* gh-158810: Fix Py_ARRAY_LENGTH() macro on C++ (#158812)

(cherry picked from commit b2bfbce)

* gh-158810: Use _Py_TYPEOF in Py_ARRAY_LENGTH() (#158838)

Fix the compiler warning "extension used" when building test_cext
with clang.

* test_cext no longer overrides the CC environment variable if it's
  already defined.
* test_cext now also logs __STRICT_ANSI__ macro.

(cherry picked from commit 85c03d4)

* Add Py_SETREF/XSETREF tests to test_cext

(cherry picked from commit 152185f)

* Backport Py_CLEAR/Py_SETREF/Py_XSETREF from main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants