Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39573: Py_TYPE becomes a static inline function #28128

Merged
merged 2 commits into from Sep 8, 2021

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Sep 2, 2021

Convert the Py_TYPE() and Py_SIZE() macros to static inline
functions. The Py_SET_TYPE() and Py_SET_SIZE() functions must now be
used to set an object type and size.

https://bugs.python.org/issue39573

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 2, 2021

I already pushed this change in June: f3fa63e

But it was reverted since it broke a Windows debug buildbot and I failed to find time to analyze why: https://bugs.python.org/issue39573#msg395205

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Sep 2, 2021

🤖 New build scheduled with the buildbot fleet by @vstinner for commit d57df22 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 3, 2021

buildbot/AMD64 Windows10 PR failed:

Py_DEBUG: Yes (sys.gettotalrefcount() present)
...
Windows fatal exception: stack overflow
Current thread 0x000012f8 (most recent call first):
  File "D:\buildarea\pull_request.bolen-windows10\build\lib\test\test_exceptions.py", line 1313 in test_recursion_in_except_handler

buildbot/AMD64 Windows10 Pro PR: failed

Py_DEBUG: Yes (sys.gettotalrefcount() present)
...
Windows fatal exception: stack overflow
Current thread 0x000022e8 (most recent call first):
  File "C:\buildbot.python.org\pull_request.kloth-win64\build\lib\test\test_exceptions.py", line 1313 in test_recursion_in_except_handler

buildbot/AMD64 Arch Linux Asan Debug PR:

(...)
  File "/buildbot/buildarea/pull_request.pablogsal-arch-x86_64.asan_debug/build/Lib/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/buildbot/buildarea/pull_request.pablogsal-arch-x86_64.asan_debug/build/Lib/subprocess.py", line 1775, in _execute_child
    self.pid = _posixsubprocess.fork_exec(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: subprocess not supported for isolated subinterpreters

Hum, usually this error comes from an incremental build: a C structure changed, the compiler reused old object files (.o).

buildbot/x86 Gentoo Non-Debug with X PR:

0:36:34 load avg: 8.91 [239/427/1] test_peg_generator crashed (Exit code 1)
Timeout (0:25:00)!
Thread 0xb7bc1700 (most recent call first):
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/subprocess.py", line 1896 in _try_wait
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/subprocess.py", line 1938 in _wait
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/subprocess.py", line 1204 in wait
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/spawn.py", line 80 in spawn
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/ccompiler.py", line 910 in spawn
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/unixccompiler.py", line 117 in _compile
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/ccompiler.py", line 574 in compile
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/command/build_ext.py", line 529 in build_extension
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/command/build_ext.py", line 474 in _build_extensions_serial
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/command/build_ext.py", line 449 in build_extensions
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/distutils/command/build_ext.py", line 340 in run
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Tools/peg_generator/pegen/build.py", line 93 in compile_c_extension
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Tools/peg_generator/pegen/testutil.py", line 105 in generate_parser_c_extension
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/test/test_peg_generator/test_c_parser.py", line 93 in build_extension
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/test/test_peg_generator/test_c_parser.py", line 96 in run_test
  File "/buildbot/buildarea/cpython/pull_request.ware-gentoo-x86.nondebug/build/Lib/test/test_peg_generator/test_c_parser.py", line 257 in test_return_stmt_noexpr_action
(...)

It seems like the timeout is just too low for this slow buildbot. On a previous build, the test took 21 min which is close to the timeout of 25 min:

https://buildbot.python.org/all/#/builders/344/builds/151

10 slowest tests:
- test_peg_generator: 21 min 46 sec

@Fidget-Spinner
Copy link
Contributor

@Fidget-Spinner Fidget-Spinner commented Sep 3, 2021

For the test_exceptions bug, there's an issue at https://bugs.python.org/issue44348. Some time ago I proposed that we need to increase stack size on windows.

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 3, 2021

I created python/buildmaster-config#262 to increase "/x86 Gentoo Non-Debug with X" buildbot timeout: python/buildmaster-config@eeff117

@Fidget-Spinner: "For the test_exceptions bug, there's an issue at https://bugs.python.org/issue44348. Some time ago I proposed that we need to increase stack size on windows."

Right, I'm aware of that. But I was optimistic and hoped that the bug gone magically :-)

For test_exceptions, my notes on the stack size and stack overflow on a recursion error on Windows: https://pythondev.readthedocs.io/unstable_tests.html#unlimited-recursion

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 3, 2021

I created https://bugs.python.org/issue45094 for the test_exceptions stack overflow.

@vstinner vstinner marked this pull request as draft Sep 3, 2021
@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 3, 2021

I converted this PR to a draft until https://bugs.python.org/issue45094 is fixed.

I pushed changes to test if Py_ALWAYS_INLINE (PR #28141) would fix the test_exceptions on Windows when Python is built in debug mode.

@vstinner vstinner force-pushed the vstinner:py_type_func branch from f330ea1 to 413c72e Sep 3, 2021
@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 3, 2021

Oh, it seems like adding __declspec(noinline) didn't fix test_exceptions, or my PR has an issue, or __declspec(noinline) is ignored when Python is built in debug mode.

Windows fatal exception: stack overflow
0:06:07 load avg: 8.17 [236/427/1] test_exceptions crashed (Exit code 3221225725)

Current thread 0x00000348 (most recent call first):
  File "D:\a\cpython\cpython\lib\test\test_exceptions.py", line 1313 in test_recursion_in_except_handler

@vstinner vstinner force-pushed the vstinner:py_type_func branch from 413c72e to 515b51f Sep 6, 2021
@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 6, 2021

New approach: bpo-45115: Enable optimiaztions on Windows debug build. I included PR #28181 in this PR, to see if PR #28181 fix test_exceptions.

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 7, 2021

I pushed a change to run the test suite with a debug mode on Windows (commit " [WIP] GitHub Action: Windows uses a debug build"): tests now pass thanks to my test_exceptions fix!

Convert the Py_TYPE() and Py_SIZE() macros to static inline
functions. The Py_SET_TYPE() and Py_SET_SIZE() functions must now be
used to set an object type and size.
@vstinner vstinner force-pushed the vstinner:py_type_func branch from 709c77b to cb33989 Sep 7, 2021
@vstinner vstinner marked this pull request as ready for review Sep 7, 2021
@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 7, 2021

I removed the debug commits of this PR (since tests pass) and I removed the Draft status.

Don't use _PyObject_CAST() which doesn't exist in old Python versions.
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Sep 7, 2021

🤖 New build scheduled with the buildbot fleet by @vstinner for commit d411467 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 7, 2021

buildbot/AMD64 Arch Linux Asan Debug PR

The compile step failed with "RuntimeError: subprocess not supported for isolated subinterpreters". This issue is unrelated to this PR.

@vstinner vstinner merged commit cb15afc into python:main Sep 8, 2021
75 of 76 checks passed
75 of 76 checks passed
@github-actions
Docs Docs
Details
@github-actions
Check for source changes
Details
@github-actions
Check if generated files are up to date
Details
@github-actions
Windows (x86)
Details
@github-actions
Windows (x64)
Details
@github-actions
macOS
Details
@github-actions
Ubuntu
Details
@github-actions
Ubuntu SSL tests with OpenSSL
Details
@github-actions
Address sanitizer Address sanitizer
Details
@bedevere-bot
buildbot/AMD64 Arch Linux Asan Debug PR Build done.
Details
Azure Pipelines PR #20210907.49 succeeded
Details
@bedevere-bot
bedevere/issue-number Issue number 39573 found
Details
@bedevere-bot
bedevere/news News entry found in Misc/NEWS.d
@bedevere-bot
buildbot/AMD64 Arch Linux Asan PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Arch Linux TraceRefs PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Arch Linux Usan PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Debian PGO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Debian root PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Fedora Stable Clang Installed PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Fedora Stable Clang PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Fedora Stable LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Fedora Stable LTO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Fedora Stable PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Fedora Stable Refleaks PR Build done.
Details
@bedevere-bot
buildbot/AMD64 FreeBSD Non-Debug PR Build done.
Details
@bedevere-bot
buildbot/AMD64 FreeBSD Shared PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL7 LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL7 LTO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL7 PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL7 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL8 FIPS Only Blake2 Builtin Hash PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL8 LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL8 LTO PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL8 PR Build done.
Details
@bedevere-bot
buildbot/AMD64 RHEL8 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Ubuntu Shared PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Windows10 PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Windows10 Pro PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Windows8.1 Non-Debug PR Build done.
Details
@bedevere-bot
buildbot/AMD64 Windows8.1 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/PPC64 Fedora PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE Fedora Stable Clang Installed PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE Fedora Stable Clang PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE Fedora Stable LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE Fedora Stable LTO PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE Fedora Stable PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE Fedora Stable Refleaks PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL7 LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL7 LTO PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL7 PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL7 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL8 LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL8 LTO PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL8 PR Build done.
Details
@bedevere-bot
buildbot/PPC64LE RHEL8 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/aarch64 Fedora Stable PR Build done.
Details
@bedevere-bot
buildbot/aarch64 RHEL8 PR Build done.
Details
@bedevere-bot
buildbot/s390x Debian PR Build done.
Details
@bedevere-bot
buildbot/s390x Fedora Clang Installed PR Build done.
Details
@bedevere-bot
buildbot/s390x Fedora Clang PR Build done.
Details
@bedevere-bot
buildbot/s390x Fedora LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/s390x Fedora LTO PR Build done.
Details
@bedevere-bot
buildbot/s390x Fedora PR Build done.
Details
@bedevere-bot
buildbot/s390x Fedora Refleaks PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL7 LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL7 LTO PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL7 PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL7 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL8 LTO + PGO PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL8 LTO PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL8 PR Build done.
Details
@bedevere-bot
buildbot/s390x RHEL8 Refleaks PR Build done.
Details
@bedevere-bot
buildbot/s390x SLES PR Build done.
Details
@bedevere-bot
buildbot/x86 Gentoo Installed with X PR Build done.
Details
@bedevere-bot
buildbot/x86 Gentoo Non-Debug with X PR Build done.
Details
@bedevere-bot
buildbot/x86-64 macOS PR Build done.
Details
@vstinner vstinner deleted the vstinner:py_type_func branch Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants