FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-129813: Fix PyBytesWriter tests by vstinner · Pull Request #139892 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Doc/c-api/bytes.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Create, Finish, Discard
writer size to *size*. The caller is responsible to write *size*
bytes using :c:func:`PyBytesWriter_GetData`.

On error, set an exception and return NULL.
On error, set an exception and return ``NULL``.

*size* must be positive or zero.

Expand Down
9 changes: 4 additions & 5 deletions Modules/_testcapi/bytes.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ writer_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
static int
writer_init(PyObject *self_raw, PyObject *args, PyObject *kwargs)
{
WriterObject *self = (WriterObject *)self_raw;
if (self->writer) {
PyBytesWriter_Discard(self->writer);
}

if (kwargs && PyDict_GET_SIZE(kwargs)) {
PyErr_Format(PyExc_TypeError,
"PyBytesWriter() takes exactly no keyword arguments");
Expand All @@ -99,6 +94,10 @@ writer_init(PyObject *self_raw, PyObject *args, PyObject *kwargs)
return -1;
}

WriterObject *self = (WriterObject *)self_raw;
if (self->writer) {
PyBytesWriter_Discard(self->writer);
}
if (use_bytearray) {
self->writer = _PyBytesWriter_CreateByteArray(alloc);
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL