[New-bugs-announce] [issue28127] Add _PyDict_CheckConsistency()

STINNER Victor report at bugs.python.org
Tue Sep 13 10:52:49 EDT 2016


New submission from STINNER Victor:

Attached patch adds a function to check the consistency of a Python dictionary after each modification.

The current implementation does really simple checks, but more advanced checks might be added later.

I tried to check also the dictionary content, but it really makes Python too slow. Maybe we can add such checks, but using a special compilation flag when we test a new patch on dictobject.c.

+    assert(0 <= mp->ma_used && mp->ma_used <= keys->dk_size);
+    assert(0 <= keys->dk_usable
+           && keys->dk_usable <= keys->dk_size);
+    assert(0 <= keys->dk_nentries
+           && keys->dk_nentries <= keys->dk_size);

These checks are coarse. We may use more strict checks, but since I don't know well the implementation of dict, I chose to use safe bounds :-)

I wrote a function similar to _PyDict_CheckConsistency() in Objects/unicodeobject.c to help me to understand the new complex structure of a Unicode string, to detect bugs and to somehow document the implementation (it helps me to write many comments in unicodeobject.h on the different structures).

----------
files: dict_check_consistency.patch
keywords: patch
messages: 276281
nosy: haypo, methane, xiang.zhang
priority: normal
severity: normal
status: open
title: Add _PyDict_CheckConsistency()
versions: Python 3.6, Python 3.7
Added file: http://bugs.python.org/file44635/dict_check_consistency.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28127>
_______________________________________


More information about the New-bugs-announce mailing list