summaryrefslogtreecommitdiffstats
path: root/Include
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 /Include
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 'Include')
-rw-r--r--Include/cpython/unicodeobject.h4
-rw-r--r--Include/internal/pycore_object.h1
-rw-r--r--Include/internal/pycore_pymem.h11
-rw-r--r--Include/unicodeobject.h10
4 files changed, 11 insertions, 15 deletions
diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h
index c11503d..54a13e3 100644
--- a/Include/cpython/unicodeobject.h
+++ b/Include/cpython/unicodeobject.h
@@ -246,6 +246,10 @@ typedef struct {
} data; /* Canonical, smallest-form Unicode buffer */
} PyUnicodeObject;
+PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
+ PyObject *op,
+ int check_content);
+
/* Fast access macros */
#define PyUnicode_WSTR_LENGTH(op) \
(PyUnicode_IS_COMPACT_ASCII(op) ? \
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 500078d..0ae5995 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -11,7 +11,6 @@ extern "C" {
#include "pycore_pystate.h" /* _PyRuntime.gc */
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
-PyAPI_FUNC(int) _PyUnicode_CheckConsistency(PyObject *op, int check_content);
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
/* Tell the GC to track this object.
diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h
index cba4b23..5be2d33 100644
--- a/Include/internal/pycore_pymem.h
+++ b/Include/internal/pycore_pymem.h
@@ -155,8 +155,9 @@ PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
PyMemAllocatorEx *old_alloc);
/* Heuristic checking if a pointer value is newly allocated
- (uninitialized) or newly freed. The pointer is not dereferenced, only the
- pointer value is checked.
+ (uninitialized), newly freed or NULL (is equal to zero).
+
+ The pointer is not dereferenced, only the pointer value is checked.
The heuristic relies on the debug hooks on Python memory allocators which
fills newly allocated memory with CLEANBYTE (0xCD) and newly freed memory
@@ -166,11 +167,13 @@ static inline int _PyMem_IsPtrFreed(void *ptr)
{
uintptr_t value = (uintptr_t)ptr;
#if SIZEOF_VOID_P == 8
- return (value == (uintptr_t)0xCDCDCDCDCDCDCDCD
+ return (value == 0
+ || value == (uintptr_t)0xCDCDCDCDCDCDCDCD
|| value == (uintptr_t)0xDDDDDDDDDDDDDDDD
|| value == (uintptr_t)0xFDFDFDFDFDFDFDFD);
#elif SIZEOF_VOID_P == 4
- return (value == (uintptr_t)0xCDCDCDCD
+ return (value == 0
+ || value == (uintptr_t)0xCDCDCDCD
|| value == (uintptr_t)0xDDDDDDDD
|| value == (uintptr_t)0xFDFDFDFD);
#else
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 6d141b3..97d8cd1 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -1032,16 +1032,6 @@ PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s);
/* === Characters Type APIs =============================================== */
-#if defined(Py_DEBUG) && !defined(Py_LIMITED_API)
-PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
- PyObject *op,
- int check_content);
-#elif !defined(NDEBUG)
-/* For asserts that call _PyUnicode_CheckConsistency(), which would
- * otherwise be a problem when building with asserts but without Py_DEBUG. */
-#define _PyUnicode_CheckConsistency(op, check_content) PyUnicode_Check(op)
-#endif
-
#ifndef Py_LIMITED_API
# define Py_CPYTHON_UNICODEOBJECT_H
# include "cpython/unicodeobject.h"