summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-10-07 16:42:01 (GMT)
committerGitHub <noreply@github.com>2019-10-07 16:42:01 (GMT)
commit6876257eaabdb30f27ebcbd7d2557278ce2e5705 (patch)
tree05597a0310d1e330c0c156c97f0fbc8a6386675e /Objects/bytesobject.c
parent321def805abc5b7c92c7e90ca90cb2434fdab855 (diff)
downloadcpython-6876257eaabdb30f27ebcbd7d2557278ce2e5705.zip
cpython-6876257eaabdb30f27ebcbd7d2557278ce2e5705.tar.gz
cpython-6876257eaabdb30f27ebcbd7d2557278ce2e5705.tar.bz2
bpo-36389: _PyObject_CheckConsistency() available in release mode (GH-16612)
bpo-36389, bpo-38376: The _PyObject_CheckConsistency() function is now also available in release mode. For example, it can be used to debug a crash in the visit_decref() function of the GC. Modify the following functions to also work in release mode: * _PyDict_CheckConsistency() * _PyObject_CheckConsistency() * _PyType_CheckConsistency() * _PyUnicode_CheckConsistency() Other changes: * _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL (equals to 0). * _PyBytesWriter_CheckConsistency() now returns 1 and is only used with assert(). * Reorder _PyObject_Dump() to write safe fields first, and only attempt to render repr() at the end.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 7df9344..4223dc9 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3206,10 +3206,10 @@ _PyBytesWriter_GetSize(_PyBytesWriter *writer, char *str)
return str - start;
}
-Py_LOCAL_INLINE(void)
+#ifndef NDEBUG
+Py_LOCAL_INLINE(int)
_PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
{
-#ifdef Py_DEBUG
char *start, *end;
if (writer->use_small_buffer) {
@@ -3239,15 +3239,16 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
end = start + writer->allocated;
assert(str != NULL);
assert(start <= str && str <= end);
-#endif
+ return 1;
}
+#endif
void*
_PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size)
{
Py_ssize_t allocated, pos;
- _PyBytesWriter_CheckConsistency(writer, str);
+ assert(_PyBytesWriter_CheckConsistency(writer, str));
assert(writer->allocated < size);
allocated = size;
@@ -3303,7 +3304,7 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size)
writer->allocated = allocated;
str = _PyBytesWriter_AsString(writer) + pos;
- _PyBytesWriter_CheckConsistency(writer, str);
+ assert(_PyBytesWriter_CheckConsistency(writer, str));
return str;
error:
@@ -3316,7 +3317,7 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, void *str, Py_ssize_t size)
{
Py_ssize_t new_min_size;
- _PyBytesWriter_CheckConsistency(writer, str);
+ assert(_PyBytesWriter_CheckConsistency(writer, str));
assert(size >= 0);
if (size == 0) {
@@ -3377,7 +3378,7 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str)
Py_ssize_t size;
PyObject *result;
- _PyBytesWriter_CheckConsistency(writer, str);
+ assert(_PyBytesWriter_CheckConsistency(writer, str));
size = _PyBytesWriter_GetSize(writer, str);
if (size == 0 && !writer->use_bytearray) {