mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #18408: Fix _PyUnicodeWriter_Finish(): clear writer->buffer,
so _PyUnicodeWriter_Dealloc() can be called on the writer after finish.
This commit is contained in:
parent
064bbdc79b
commit
15a0bd3965
1 changed files with 5 additions and 2 deletions
|
@ -13157,6 +13157,7 @@ _PyUnicodeWriter_WriteCstr(_PyUnicodeWriter *writer, const char *str, Py_ssize_t
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
|
_PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
|
||||||
{
|
{
|
||||||
|
PyObject *str;
|
||||||
if (writer->pos == 0) {
|
if (writer->pos == 0) {
|
||||||
Py_XDECREF(writer->buffer);
|
Py_XDECREF(writer->buffer);
|
||||||
_Py_RETURN_UNICODE_EMPTY();
|
_Py_RETURN_UNICODE_EMPTY();
|
||||||
|
@ -13174,8 +13175,10 @@ _PyUnicodeWriter_Finish(_PyUnicodeWriter *writer)
|
||||||
}
|
}
|
||||||
writer->buffer = newbuffer;
|
writer->buffer = newbuffer;
|
||||||
}
|
}
|
||||||
assert(_PyUnicode_CheckConsistency(writer->buffer, 1));
|
str = writer->buffer;
|
||||||
return unicode_result_ready(writer->buffer);
|
writer->buffer = NULL;
|
||||||
|
assert(_PyUnicode_CheckConsistency(str, 1));
|
||||||
|
return unicode_result_ready(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue