[issue28127] Add _PyDict_CheckConsistency()

2016-09-13 Thread STINNER Victor

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28127] Add _PyDict_CheckConsistency()

2016-09-13 Thread STINNER Victor

STINNER Victor added the comment:

Ok, here is a more complete _PyDict_CheckConsistency() with an optional 
DEBUG_PYDICT (disabled by default).

--
Added file: http://bugs.python.org/file44640/dict_check_consistency-2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28127] Add _PyDict_CheckConsistency()

2016-09-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ee44c971b3af by Victor Stinner in branch '3.6':
Add _PyDict_CheckConsistency()
https://hg.python.org/cpython/rev/ee44c971b3af

New changeset 070cc3b9d5cc by Victor Stinner in branch 'default':
Merge 3.6
https://hg.python.org/cpython/rev/070cc3b9d5cc

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28127] Add _PyDict_CheckConsistency()

2016-09-14 Thread STINNER Victor

STINNER Victor added the comment:

Ok, I pushed my new function. Expensive checks are disabled by default: define 
DEBUG_PYDICT to enable them (ex: gcc -D DEBUG_PYDICT).

Thanks for the review Eric, Naoki & Xiang!

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com