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-150865: Allow immortalizing objects as long as thread owns it by seberg · Pull Request #150956 · python/cpython Conversation
Contributor
As discussed in gh-150865, it seems unnecessary to enforce a unique reference. Rather, an object can be immortalized (even accidentally by overflowing the local reference count) unless it is owned by the current thread. Allowing immortalizing more generally simplifies immortalization of objects with complex ceration (in the example, new types may be created with multiple references from the start). This may mean that the I made the function idempotent (even for unicode on this one) just for the sake of it. Closes gh-150865 (Not sure this needs a blurp, I guess I can add myself to the existing one, but I don't mind either way.) (once merged, I guess this should also be ported to pythoncapi-compat)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsAs discussed in pythongh-150865, it seems unnecessary to enforce a unique reference. Rather, an object can be immortalized (even accidentally by overflowing the local reference count) unless it is owned by the current thread. Allowing immortalizing more generally simplifies immortalization of objects with complex ceration (in the example, new types may be created with multiple references from the start). This may mean that the `ref_shared` reference count can be nonzero after immortalization, but that should be safe (as it also happens for accidental immortalization). I made the function idempotent (even for unicode on this one) just for the sake of it.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the PR. I'm going to temporarily apply
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+819
to
+820
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should note that it's intended for highly-specific cases where either:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+817
to
+818
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should document that some objects may not support immortalization in the future and that some objects will break when immortalized. (The second part should be in a
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems kind of arbitrary, can you add a comment explaining why 3 is used?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the shared refcount being changed?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+2893
to
+2894
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to also check that
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's expose Here's an outline: static PyObject * pyobject_set_immortal(PyObject *self, PyObject *op) { return PyLong_FromLong(PyUnstable_SetImmortal(op)); } import _testcapi class TestWhatever(TestCase): def test_set_immortal(self): for obj, expected_result in [(module_object, 1), (shared_module_object, 0), ...]: self.assertEqual(_testcapi.pyobject_enable_deferred_refcount(module), expected_result)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
ZeroIntensity
requested changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, looking at my version, we need to do a few other things here:
This also furthers my suspicion that accidental immortalization does not work correctly. Note that my implementation was also designed to eventually deallocate the immortal object, so there are some things in my
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 90 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I guess I'll close this if @ZeroIntensity is picking it up. (I never became sure what the, to me it seems this should be pretty close with some things, like the debug refcount, being at least OK to be off when there are multiple threads accessing the object at the time of immortalization.) Not like the changes here are tricky, this was more of a nudging request :). |
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.
RelaxPyUnstable_SetImmortal to objects allocated in that thread?
There was an error while loading. Please reload this page.