diff options
author | Victor Stinner <vstinner@python.org> | 2020-05-14 20:44:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 20:44:32 (GMT) |
commit | d2dc827d16479d99927a6923a0347199d7c694fb (patch) | |
tree | 04e608b4ff6bd534797a480e934217252059e82f /Modules/_testinternalcapi.c | |
parent | ce21cfca7bb2d18921bc4ac27cb064726996c519 (diff) | |
download | cpython-d2dc827d16479d99927a6923a0347199d7c694fb.zip cpython-d2dc827d16479d99927a6923a0347199d7c694fb.tar.gz cpython-d2dc827d16479d99927a6923a0347199d7c694fb.tar.bz2 |
bpo-40602: _Py_hashtable_set() reports rehash failure (GH-20077)
If _Py_hashtable_set() fails to grow the hash table (rehash), it now
fails rather than ignoring the error.
Diffstat (limited to 'Modules/_testinternalcapi.c')
-rw-r--r-- | Modules/_testinternalcapi.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 3ae387d..5f217dc 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -98,6 +98,11 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args)) return PyErr_NoMemory(); } + // Using an newly allocated table must not crash + assert(table->nentries == 0); + assert(table->nbuckets > 0); + assert(_Py_hashtable_get(table, TO_PTR('x')) == NULL); + // Test _Py_hashtable_set() char key; for (key='a'; key <= 'z'; key++) { @@ -121,17 +126,15 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args)) // Test _Py_hashtable_get() for (key='a'; key <= 'z'; key++) { void *value_ptr = _Py_hashtable_get(table, TO_PTR(key)); - int value = (int)FROM_PTR(value_ptr); - assert(value == VALUE(key)); + assert((int)FROM_PTR(value_ptr) == VALUE(key)); } // Test _Py_hashtable_steal() key = 'p'; void *value_ptr = _Py_hashtable_steal(table, TO_PTR(key)); - int value = (int)FROM_PTR(value_ptr); - assert(value == VALUE(key)); - + assert((int)FROM_PTR(value_ptr) == VALUE(key)); assert(table->nentries == 25); + assert(_Py_hashtable_get_entry(table, TO_PTR(key)) == NULL); // Test _Py_hashtable_foreach() int count = 0; @@ -142,6 +145,7 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args)) // Test _Py_hashtable_clear() _Py_hashtable_clear(table); assert(table->nentries == 0); + assert(table->nbuckets > 0); assert(_Py_hashtable_get(table, TO_PTR('x')) == NULL); _Py_hashtable_destroy(table); |