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-122527: Fix a crash on deallocation of `PyStructSequence` by colesbury · Pull Request #122577 · python/cpython Conversation
|
|
I think we should probably backport this to 3.13. And maybe 3.12? What do you think? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'll add the labels to get the PRs setup and CI started. If the decision ends up not to backport, we can just close those PRs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @colesbury for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @colesbury for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @colesbury and @encukou, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ythonGH-122577) The `PyStructSequence` destructor would crash if it was deallocated after its type's dictionary was cleared by the GC, because it couldn't compute the "real size" of the instance. This could occur with relatively straightforward code in the free-threaded build or with a reference cycle involving the type in the default build, due to differing orders in which `tp_clear()` was called. Account for the non-sequence fields in `tp_basicsize` and use that, along with `Py_SIZE()`, to compute the "real" size of a `PyStructSequence` in the dealloc function. This avoids the accesses to the type's dictionary during dealloc, which were unsafe. (cherry picked from commit 4b63cd1) Co-authored-by: Sam Gross <[email protected]>
|
GH-122625 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-122626 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
For 3.13.1, definitely. 3.12, doesn't have free-threading, and skipping a version when backporting is confusing, so I'd backport it after 3.13.1. Does that sound reasonable? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ythonGH-122577) The `PyStructSequence` destructor would crash if it was deallocated after its type's dictionary was cleared by the GC, because it couldn't compute the "real size" of the instance. This could occur with relatively straightforward code in the free-threaded build or with a reference cycle involving the type in the default build, due to differing orders in which `tp_clear()` was called. Account for the non-sequence fields in `tp_basicsize` and use that, along with `Py_SIZE()`, to compute the "real" size of a `PyStructSequence` in the dealloc function. This avoids the accesses to the type's dictionary during dealloc, which were unsafe.
| #define REAL_SIZE_TP(tp) \ | ||
| get_type_attr_as_size(tp, &_Py_ID(n_fields)) | ||
| #define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op)) | ||
| #define REAL_SIZE(op) get_real_size((PyObject *)op) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why not change also REAL_SIZE_TP?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The new calculation involves Py_SIZE(op), so we can't do it on the type alone.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| script_helper.assert_python_ok("-c", textwrap.dedent(r""" | ||
| import time | ||
| t = time.gmtime() | ||
| type(t).refcyle = t |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Typo: refcyle.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ythonGH-122577) The `PyStructSequence` destructor would crash if it was deallocated after its type's dictionary was cleared by the GC, because it couldn't compute the "real size" of the instance. This could occur with relatively straightforward code in the free-threaded build or with a reference cycle involving the type in the default build, due to differing orders in which `tp_clear()` was called. Account for the non-sequence fields in `tp_basicsize` and use that, along with `Py_SIZE()`, to compute the "real" size of a `PyStructSequence` in the dealloc function. This avoids the accesses to the type's dictionary during dealloc, which were unsafe.
…H-122577) (#122625) gh-122527: Fix a crash on deallocation of `PyStructSequence` (GH-122577) The `PyStructSequence` destructor would crash if it was deallocated after its type's dictionary was cleared by the GC, because it couldn't compute the "real size" of the instance. This could occur with relatively straightforward code in the free-threaded build or with a reference cycle involving the type in the default build, due to differing orders in which `tp_clear()` was called. Account for the non-sequence fields in `tp_basicsize` and use that, along with `Py_SIZE()`, to compute the "real" size of a `PyStructSequence` in the dealloc function. This avoids the accesses to the type's dictionary during dealloc, which were unsafe. (cherry picked from commit 4b63cd1) Co-authored-by: Sam Gross <[email protected]>
…H-122577) (#122626) The `PyStructSequence` destructor would crash if it was deallocated after its type's dictionary was cleared by the GC, because it couldn't compute the "real size" of the instance. This could occur with relatively straightforward code in the free-threaded build or with a reference cycle involving the type in the default build, due to differing orders in which `tp_clear()` was called. Account for the non-sequence fields in `tp_basicsize` and use that, along with `Py_SIZE()`, to compute the "real" size of a `PyStructSequence` in the dealloc function. This avoids the accesses to the type's dictionary during dealloc, which were unsafe. (cherry picked from commit 4b63cd1)
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.