GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||
GeezerVison is showing github.com — gh-98724: Fix Py_CLEAR() macro side effects (#99100) by vstinner · Pull Request #100070 · python/cpython Conversation
|
✅ Deploy Preview for python-cpython-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
cc @serge-sans-paille @erlend-aasland: This version should no longer miscompile Python: it avoids the type punning issue thanks to memcpy(). I wrote a comment in Py_CLEAR() to explain the rationale for memcpy(). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR no longer reintroduces the miscompilation bug: issue #99701. I tested manually. I tested this PR with this local patch (otherwise the output is just too verbose!): diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 8209132ebc..cf243c8ef9 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1891,9 +1891,6 @@ Py_FinalizeEx(void) /* Destroy all modules */ finalize_modules(tstate); - /* Print debug stats if any */ - _PyEval_Fini(); - /* Flush sys.stdout and sys.stderr (again, in case more was printed) */ if (flush_std_files() < 0) { status = -1; Test command: The test succeeded with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I updated my PR to use My previous attempt PR #99739 always used |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I ran my test for 4 cases and all succeeded:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
To also emit a warning in the memcpy() implementation, @serge-sans-paille suggested to me using I'm not sure about this one. Maybe this enhancement can be made later, once the initial issue #98724 is fixed with my current PR implementation. So it's easy to revert if something goes wrong. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit 86d8878 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
test_ast.test_recursion_direct() crash with a stack overflow. It sounds unrelated to this change. The ARM64 Windows 3.x buildbot is sick for 2 days: it fails with "exception" (don't build+test Python). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The Py_CLEAR(), Py_SETREF() and Py_XSETREF() macros now only evaluate their arguments once. If an argument has side effects, these side effects are no longer duplicated. Use temporary variables to avoid duplicating side effects of macro arguments side effects. If available, use _Py_TYPEOF() to avoid type punning. Otherwise, use memcpy() for the assignment to prevent a miscompilation with strict aliasing caused by type punning. Add _Py_TYPEOF() macro: __typeof__() on GCC and clang. Add test_py_clear() and test_py_setref() unit tests to _testcapi.
|
Apart of the sick "ARM64 Windows 3.x" buildbot, all buildbots were happy with this change. I fixed a fix typos. I amended the commit message. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
FYI I proposed #100104 to fix this bug (unrelated to this change). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.