summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-10-26 16:47:15 (GMT)
committerGitHub <noreply@github.com>2018-10-26 16:47:15 (GMT)
commit50fe3f8913c503e63f4cfb8ddcf8641ef7ad0722 (patch)
tree371e51f8230246106bf5a3cacd47c4fb747f505c /Objects/dictobject.c
parent0862505a0377c12e8004b2eb8de0555f26ce9530 (diff)
downloadcpython-50fe3f8913c503e63f4cfb8ddcf8641ef7ad0722.zip
cpython-50fe3f8913c503e63f4cfb8ddcf8641ef7ad0722.tar.gz
cpython-50fe3f8913c503e63f4cfb8ddcf8641ef7ad0722.tar.bz2
bpo-9263: _PyXXX_CheckConsistency() use _PyObject_ASSERT() (GH-10108)
Use _PyObject_ASSERT() in: * _PyDict_CheckConsistency() * _PyType_CheckConsistency() * _PyUnicode_CheckConsistency() _PyObject_ASSERT() dumps the faulty object if the assertion fails to help debugging.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 370895d..ee65695 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -439,6 +439,8 @@ static PyObject *empty_values[1] = { NULL };
static int
_PyDict_CheckConsistency(PyDictObject *mp)
{
+#define ASSERT(expr) _PyObject_ASSERT((PyObject *)mp, (expr))
+
PyDictKeysObject *keys = mp->ma_keys;
int splitted = _PyDict_HasSplitTable(mp);
Py_ssize_t usable = USABLE_FRACTION(keys->dk_size);
@@ -447,23 +449,23 @@ _PyDict_CheckConsistency(PyDictObject *mp)
Py_ssize_t i;
#endif
- assert(0 <= mp->ma_used && mp->ma_used <= usable);
- assert(IS_POWER_OF_2(keys->dk_size));
- assert(0 <= keys->dk_usable
+ ASSERT(0 <= mp->ma_used && mp->ma_used <= usable);
+ ASSERT(IS_POWER_OF_2(keys->dk_size));
+ ASSERT(0 <= keys->dk_usable
&& keys->dk_usable <= usable);
- assert(0 <= keys->dk_nentries
+ ASSERT(0 <= keys->dk_nentries
&& keys->dk_nentries <= usable);
- assert(keys->dk_usable + keys->dk_nentries <= usable);
+ ASSERT(keys->dk_usable + keys->dk_nentries <= usable);
if (!splitted) {
/* combined table */
- assert(keys->dk_refcnt == 1);
+ ASSERT(keys->dk_refcnt == 1);
}
#ifdef DEBUG_PYDICT
for (i=0; i < keys->dk_size; i++) {
Py_ssize_t ix = dk_get_index(keys, i);
- assert(DKIX_DUMMY <= ix && ix <= usable);
+ ASSERT(DKIX_DUMMY <= ix && ix <= usable);
}
for (i=0; i < usable; i++) {
@@ -473,32 +475,34 @@ _PyDict_CheckConsistency(PyDictObject *mp)
if (key != NULL) {
if (PyUnicode_CheckExact(key)) {
Py_hash_t hash = ((PyASCIIObject *)key)->hash;
- assert(hash != -1);
- assert(entry->me_hash == hash);
+ ASSERT(hash != -1);
+ ASSERT(entry->me_hash == hash);
}
else {
/* test_dict fails if PyObject_Hash() is called again */
- assert(entry->me_hash != -1);
+ ASSERT(entry->me_hash != -1);
}
if (!splitted) {
- assert(entry->me_value != NULL);
+ ASSERT(entry->me_value != NULL);
}
}
if (splitted) {
- assert(entry->me_value == NULL);
+ ASSERT(entry->me_value == NULL);
}
}
if (splitted) {
/* splitted table */
for (i=0; i < mp->ma_used; i++) {
- assert(mp->ma_values[i] != NULL);
+ ASSERT(mp->ma_values[i] != NULL);
}
}
#endif
return 1;
+
+#undef ASSERT
}
#endif