| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ``PySequence_Tuple`` now creates the resulting tuple atomically, preventing | ||
| partially created tuples being visible to the garbage collector or through | ||
| ``gc.get_referrers()`` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -3174,6 +3174,25 @@ PyList_AsTuple(PyObject *v) | |
| return ret; | ||
| } | ||
|
|
||
| PyObject * | ||
| _PyList_AsTupleAndClear(PyListObject *self) | ||
| { | ||
| assert(self != NULL); | ||
| PyObject *ret; | ||
| if (self->ob_item == NULL) { | ||
| return PyTuple_New(0); | ||
| } | ||
| Py_BEGIN_CRITICAL_SECTION(self); | ||
| PyObject **items = self->ob_item; | ||
| Py_ssize_t size = Py_SIZE(self); | ||
| self->ob_item = NULL; | ||
| Py_SET_SIZE(self, 0); | ||
| ret = _PyTuple_FromArraySteal(items, size); | ||
| free_list_items(items, false); | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIf _PyTuple_FromArraySteal, do we still want to free the list items?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes. _PyTuple_FromArraySteal steals the references, but doesn't do anything with the memory
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityTypically it is passed a stack-allocated array, so it can't free it.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySorry, I meant if _PyTuple_FromArraySteal fails.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes. _PyTuple_FromArraySteal consumes the all references regardless of whether it succeeds or fails.
Sorry, something went wrong.
All reactions
|
||
| Py_END_CRITICAL_SECTION(); | ||
| return ret; | ||
| } | ||
|
|
||
| PyObject * | ||
| _PyList_FromStackRefSteal(const _PyStackRef *src, Py_ssize_t n) | ||
| { | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think the name _PyList_AsTupleAndClear might be confusing, because if you called Py_CLEAR on the list you wouldn't need to decref it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityBut if you called PyList_Clear on it, you would need to Py_DECREF it.
It is the list being cleared, not the variable holding a reference to it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.