summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-10-15 01:06:16 (GMT)
committerGitHub <noreply@github.com>2019-10-15 01:06:16 (GMT)
commitf82ce5b1b12873b65927149a016be6a7c65e979d (patch)
treed2db47408daada0a4e49835871fda6e15d6050dc /Objects/typeobject.c
parent42308e8b27c8023e3f9d037f5e4a8892f2dcbc48 (diff)
downloadcpython-f82ce5b1b12873b65927149a016be6a7c65e979d.zip
cpython-f82ce5b1b12873b65927149a016be6a7c65e979d.tar.gz
cpython-f82ce5b1b12873b65927149a016be6a7c65e979d.tar.bz2
[3.8] bpo-36389: Backport debug enhancements from master (GH-16796)
* 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. (cherry picked from commit 6876257eaabdb30f27ebcbd7d2557278ce2e5705) * bpo-36389: Fix _PyBytesWriter in release mode (GH-16624) Fix _PyBytesWriter API when Python is built in release mode with assertions. (cherry picked from commit 60ec6efd96d95476fe5e38c491491add04f026e5) * bpo-38070: Enhance visit_decref() debug trace (GH-16631) subtract_refs() now pass the parent object to visit_decref() which pass it to _PyObject_ASSERT(). So if the "is freed" assertion fails, the parent is used in debug trace, rather than the freed object. The parent object is more likely to contain useful information. Freed objects cannot be inspected are are displayed as "<object at xxx is freed>" with no other detail. (cherry picked from commit 4d5f94b8cd20f804c7868c5395a15aa6032f874c) * Fix also a typo in PYMEM_DEADBYTE macro comment * bpo-36389: Add newline to _PyObject_AssertFailed() (GH-16629) Add a newline between the verbose object dump and the Py_FatalError() logs for readability. (cherry picked from commit 7775349895088a7ae68cecf0c74cf817f15e2c74)
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index e635b71..5df1217 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -137,22 +137,24 @@ skip_signature(const char *doc)
int
_PyType_CheckConsistency(PyTypeObject *type)
{
-#define ASSERT(expr) _PyObject_ASSERT((PyObject *)type, (expr))
+#define CHECK(expr) \
+ do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG((PyObject *)type, Py_STRINGIFY(expr)); } } while (0)
+
+ CHECK(!_PyObject_IsFreed((PyObject *)type));
if (!(type->tp_flags & Py_TPFLAGS_READY)) {
- /* don't check types before PyType_Ready() */
+ /* don't check static types before PyType_Ready() */
return 1;
}
- ASSERT(!_PyObject_IsFreed((PyObject *)type));
- ASSERT(Py_REFCNT(type) >= 1);
- ASSERT(PyType_Check(type));
+ CHECK(Py_REFCNT(type) >= 1);
+ CHECK(PyType_Check(type));
- ASSERT(!(type->tp_flags & Py_TPFLAGS_READYING));
- ASSERT(type->tp_dict != NULL);
+ CHECK(!(type->tp_flags & Py_TPFLAGS_READYING));
+ CHECK(type->tp_dict != NULL);
return 1;
-#undef ASSERT
+#undef CHECK
}
static const char *