bpo-40609: Remove _Py_hashtable_t.key_size (GH-20060)

Rewrite _Py_hashtable_t type to always store the key as
a "const void *" pointer. Add an explicit "key" member to
_Py_hashtable_entry_t.

Remove _Py_hashtable_t.key_size member.

hash and compare functions drop their hash table parameter, and their
'key' parameter type becomes "const void *".
This commit is contained in:
Victor Stinner 2020-05-13 02:26:02 +02:00 committed by GitHub
parent 9e2ca17420
commit f9b3b582b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 188 deletions

View file

@ -549,7 +549,7 @@ static int
w_init_refs(WFILE *wf, int version)
{
if (version >= 3) {
wf->hashtable = _Py_hashtable_new(sizeof(PyObject *), sizeof(int),
wf->hashtable = _Py_hashtable_new(sizeof(int),
_Py_hashtable_hash_ptr,
_Py_hashtable_compare_direct);
if (wf->hashtable == NULL) {
@ -564,9 +564,7 @@ static int
w_decref_entry(_Py_hashtable_t *ht, _Py_hashtable_entry_t *entry,
void *Py_UNUSED(data))
{
PyObject *entry_key;
_Py_HASHTABLE_ENTRY_READ_KEY(ht, entry, entry_key);
PyObject *entry_key = (PyObject *)entry->key;
Py_XDECREF(entry_key);
return 0;
}