Skip to content

Commit 80a522b

Browse files
committed
Update
1 parent 0146025 commit 80a522b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

peps/pep-0782.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ Create, Finish, Discard
8080
8181
Create a :c:type:`PyBytesWriter` to write *size* bytes.
8282
83-
If *size* is greater than zero, allocate *size* bytes for the
84-
returned buffer, and set the writer size to *size*.
83+
If *size* is greater than zero, allocate *size* bytes, and set the
84+
writer size to *size*. The caller is responsible to write *size*
85+
bytes using :c:func:`PyBytesWriter_GetData`.
8586
8687
On error, set an exception and return NULL.
8788
@@ -128,8 +129,9 @@ High-level API
128129
129130
.. c:function:: int PyBytesWriter_WriteBytes(PyBytesWriter *writer, const void *bytes, Py_ssize_t size)
130131
131-
Write *size* bytes of *bytes* at the *writer* end,
132-
and add *size* to the writer size.
132+
Grow the *writer* internal buffer by *size* bytes,
133+
write *size* bytes of *bytes* at the *writer* end,
134+
and add *size* to the *writer* size.
133135
134136
If *size* is equal to ``-1``, call ``strlen(bytes)`` to get the
135137
string length.
@@ -140,7 +142,8 @@ High-level API
140142
.. c:function:: int PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...)
141143
142144
Similar to ``PyBytes_FromFormat()``, but write the output directly at
143-
the writer end. Then add the written size to the writer size.
145+
the writer end. Grow the writer internal buffer on demand.
146+
Then add the written size to the writer size.
144147
145148
On success, return ``0``.
146149
On error, set an exception and return ``-1``.
@@ -191,7 +194,8 @@ Low-level API
191194
pointer.
192195
193196
The *buf* pointer is moved if the internal buffer is moved in memory.
194-
The *buf* position inside the internal buffer is left unchanged.
197+
The *buf* relative position within the internal buffer is left
198+
unchanged.
195199
196200
On error, set an exception and return ``NULL``.
197201
@@ -330,7 +334,7 @@ Example of code using the soft deprecated
330334
if (result == NULL) {
331335
return NULL;
332336
}
333-
if (safe_memcpy(PyBytes_AS_STRING(result), start, num_bytes) < 0) {
337+
if (copy_bytes(PyBytes_AS_STRING(result), start, num_bytes) < 0) {
334338
Py_CLEAR(result);
335339
}
336340
return result;
@@ -341,7 +345,7 @@ It can now be updated to::
341345
if (writer == NULL) {
342346
return NULL;
343347
}
344-
if (safe_memcpy(PyBytesWriter_GetData(writer), start, num_bytes) < 0) {
348+
if (copy_bytes(PyBytesWriter_GetData(writer), start, num_bytes) < 0) {
345349
PyBytesWriter_Discard(writer);
346350
return NULL;
347351
}

0 commit comments

Comments
 (0)