bpo-36389: Fix _PyBytesWriter in release mode (GH-16624)
Fix _PyBytesWriter API when Python is built in release mode with
assertions.
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 4223dc9..f9823f1 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -667,9 +667,6 @@
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 @@
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 @@
}
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 @@
{
/* 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 @@
}
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 @@
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