BUG: Fix move_into_mutable_buffer for python 3.6. #14695
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In python 3.6, the CALL_FUNCTION handling was updated. One change is
that when calling a C function from a python function python now counts
the reference owned by the argument tuple. This means that move was
always seeing objects with two references instead of the expected
one.
Python 3.6 also removed a copy in the argument tuple when *unpacking
functions. This means that if a user does:
tuple = (create_string(),)
move_into_mutable_buffer(*tuple)
where create_string() creates a string object with one reference then we
will fail to raise a BadMove even though the user could later retrieve
that string with tuple[0]. There is no way to detect this case so this
patch adds a warning to the docstring advising against star unpacking.
xref: #14679
I played around with removing the extra reference that was added in 3.6 but it looks like playing with borrowed refs everywhere will be a bit tricky. This change should clear things up for 3.6 while continuing to work for older versions. In 3.6 you could get a shared mutable string from this but you need to try pretty hard for it.