GH-127058: Make PySequence_Tuple safer and probably faster.#127758
Conversation
|
Did you run refleak tests? |
Sorry, something went wrong.
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
|
🤖 New build scheduled with the buildbot fleet by @markshannon for commit 8badf7b 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
Sorry, something went wrong.
…ython#127758) * Use a small buffer, then list when constructing a tuple from an arbitrary sequence.
|
note that this pull request modifies the behavior of the following code import time
class A:
def __len__(self):
raise NotImplementedError("infinite sequence")
def __iter__(self):
while True:
time.sleep(1)
yield 0
tuple(A())before this change, the above raises an error. Now it enters an infinite loop. by itself it isn't a problem because the fact that the same thing can be said about |
Sorry, something went wrong.
Instead of allocating a tuple, then running arbitrary code with an incomplete tuple, this PR:
_PyList_AsTupleAndClearfunction which creates a tuple from a list while clearing the list. This avoids unnecessary reference count manipulation.Since the vast majority of tuples are small,
PySequence_Tuplenow only does one allocation and no resizing in the common case.