gh-87193: Support bytes objects with refcount > 1 in _PyBytes_Resize() (GH-117160)

Create a new bytes object and destroy the old one if it has refcount > 1.
This commit is contained in:
Serhiy Storchaka 2024-03-25 17:32:11 +02:00 committed by GitHub
parent 01e7405da4
commit 0c1a42cf9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 123 additions and 30 deletions

View file

@ -191,10 +191,10 @@ called with a non-bytes parameter.
.. c:function:: int _PyBytes_Resize(PyObject **bytes, Py_ssize_t newsize)
A way to resize a bytes object even though it is "immutable". Only use this
to build up a brand new bytes object; don't use this if the bytes may already
be known in other parts of the code. It is an error to call this function if
the refcount on the input bytes object is not one. Pass the address of an
Resize a bytes object. *newsize* will be the new length of the bytes object.
You can think of it as creating a new bytes object and destroying the old
one, only more efficiently.
Pass the address of an
existing bytes object as an lvalue (it may be written into), and the new size
desired. On success, *\*bytes* holds the resized bytes object and ``0`` is
returned; the address in *\*bytes* may differ from its input value. If the