mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
bpo-36389: Fix _PyBytesWriter in release mode (GH-16624)
Fix _PyBytesWriter API when Python is built in release mode with assertions.
This commit is contained in:
parent
6876257eaa
commit
60ec6efd96
3 changed files with 48 additions and 47 deletions
|
@ -667,9 +667,6 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
Py_ssize_t len = 0;
|
||||
char onechar; /* For byte_converter() */
|
||||
Py_ssize_t alloc;
|
||||
#ifdef Py_DEBUG
|
||||
char *before;
|
||||
#endif
|
||||
|
||||
fmt++;
|
||||
if (*fmt == '%') {
|
||||
|
@ -981,8 +978,8 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
if (res == NULL)
|
||||
goto error;
|
||||
}
|
||||
#ifdef Py_DEBUG
|
||||
before = res;
|
||||
#ifndef NDEBUG
|
||||
char *before = res;
|
||||
#endif
|
||||
|
||||
/* Write the sign if needed */
|
||||
|
@ -1047,7 +1044,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
}
|
||||
Py_XDECREF(temp);
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
#ifndef NDEBUG
|
||||
/* check that we computed the exact size for this write */
|
||||
assert((res - before) == alloc);
|
||||
#endif
|
||||
|
@ -3168,8 +3165,9 @@ _PyBytesWriter_Init(_PyBytesWriter *writer)
|
|||
{
|
||||
/* Set all attributes before small_buffer to 0 */
|
||||
memset(writer, 0, offsetof(_PyBytesWriter, small_buffer));
|
||||
#ifdef Py_DEBUG
|
||||
memset(writer->small_buffer, 0xCB, sizeof(writer->small_buffer));
|
||||
#ifndef NDEBUG
|
||||
memset(writer->small_buffer, PYMEM_CLEANBYTE,
|
||||
sizeof(writer->small_buffer));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -3297,8 +3295,9 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size)
|
|||
}
|
||||
|
||||
writer->use_small_buffer = 0;
|
||||
#ifdef Py_DEBUG
|
||||
memset(writer->small_buffer, 0xDB, sizeof(writer->small_buffer));
|
||||
#ifndef NDEBUG
|
||||
memset(writer->small_buffer, PYMEM_CLEANBYTE,
|
||||
sizeof(writer->small_buffer));
|
||||
#endif
|
||||
}
|
||||
writer->allocated = allocated;
|
||||
|
@ -3350,7 +3349,7 @@ _PyBytesWriter_Alloc(_PyBytesWriter *writer, Py_ssize_t size)
|
|||
assert(size >= 0);
|
||||
|
||||
writer->use_small_buffer = 1;
|
||||
#ifdef Py_DEBUG
|
||||
#ifndef NDEBUG
|
||||
writer->allocated = sizeof(writer->small_buffer) - 1;
|
||||
/* In debug mode, don't use the full small buffer because it is less
|
||||
efficient than bytes and bytearray objects to detect buffer underflow
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue