| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c3706f4 commit d557d64
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1671,17 +1671,17 @@ _textiowrapper_writeflush(textio *self) | |||
| 1671 | 1671 | } | |
| 1672 | 1672 | else { | |
| 1673 | 1673 | assert(PyList_Check(pending)); | |
| 1674 | - b = PyBytes_FromStringAndSize(NULL, self->pending_bytes_count); | ||
| 1675 | - if (b == NULL) { | ||
| 1674 | + PyBytesWriter *writer = PyBytesWriter_Create(self->pending_bytes_count); | ||
| 1675 | + if (writer == NULL) { | ||
| 1676 | 1676 | return -1; | |
| 1677 | 1677 | } | |
| 1678 | 1678 | ||
| 1679 | - char *buf = PyBytes_AsString(b); | ||
| 1679 | + char *buf = PyBytesWriter_GetData(writer); | ||
| 1680 | 1680 | Py_ssize_t pos = 0; | |
| 1681 | 1681 | ||
| 1682 | 1682 | for (Py_ssize_t i = 0; i < PyList_GET_SIZE(pending); i++) { | |
| 1683 | 1683 | PyObject *obj = PyList_GET_ITEM(pending, i); | |
| 1684 | - char *src; | ||
| 1684 | + const char *src; | ||
| 1685 | 1685 | Py_ssize_t len; | |
| 1686 | 1686 | if (PyUnicode_Check(obj)) { | |
| 1687 | 1687 | assert(PyUnicode_IS_ASCII(obj)); | |
@@ -1690,15 +1690,18 @@ _textiowrapper_writeflush(textio *self) | |||
| 1690 | 1690 | } | |
| 1691 | 1691 | else { | |
| 1692 | 1692 | assert(PyBytes_Check(obj)); | |
| 1693 | - if (PyBytes_AsStringAndSize(obj, &src, &len) < 0) { | ||
| 1694 | - Py_DECREF(b); | ||
| 1695 | - return -1; | ||
| 1696 | - } | ||
| 1693 | + src = PyBytes_AS_STRING(obj); | ||
| 1694 | + len = PyBytes_GET_SIZE(obj); | ||
| 1697 | 1695 | } | |
| 1698 | 1696 | memcpy(buf + pos, src, len); | |
| 1699 | 1697 | pos += len; | |
| 1700 | 1698 | } | |
| 1701 | 1699 | assert(pos == self->pending_bytes_count); | |
| 1700 | + | ||
| 1701 | + b = PyBytesWriter_Finish(writer); | ||
| 1702 | + if (b == NULL) { | ||
| 1703 | + return -1; | ||
| 1704 | + } | ||
| 1702 | 1705 | } | |
| 1703 | 1706 | ||
| 1704 | 1707 | self->pending_bytes_count = 0; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments