mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #18408: _PyUnicodeWriter_Finish() now clears its buffer attribute in all
cases, so _PyUnicodeWriter_Dealloc() can be called after finish.
This commit is contained in:
parent
7979926616
commit
9e6b4d715c
1 changed files with 6 additions and 3 deletions
|
@ -13159,18 +13159,21 @@ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
|
|||
{
|
||||
PyObject *str;
|
||||
if (writer->pos == 0) {
|
||||
Py_XDECREF(writer->buffer);
|
||||
Py_CLEAR(writer->buffer);
|
||||
_Py_RETURN_UNICODE_EMPTY();
|
||||
}
|
||||
if (writer->readonly) {
|
||||
assert(PyUnicode_GET_LENGTH(writer->buffer) == writer->pos);
|
||||
return writer->buffer;
|
||||
str = writer->buffer;
|
||||
writer->buffer = NULL;
|
||||
assert(PyUnicode_GET_LENGTH(str) == writer->pos);
|
||||
return str;
|
||||
}
|
||||
if (PyUnicode_GET_LENGTH(writer->buffer) != writer->pos) {
|
||||
PyObject *newbuffer;
|
||||
newbuffer = resize_compact(writer->buffer, writer->pos);
|
||||
if (newbuffer == NULL) {
|
||||
Py_DECREF(writer->buffer);
|
||||
writer->buffer = NULL;
|
||||
return NULL;
|
||||
}
|
||||
writer->buffer = newbuffer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue