summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-13 00:50:18 (GMT)
committerGitHub <noreply@github.com>2020-05-13 00:50:18 (GMT)
commit2d0a3d682f699cce8db6e30981d41d9125318726 (patch)
treeb4ea6653c7448deaea0f366c163426a1f5490bb7 /Python/marshal.c
parentf9b3b582b86b9cce8d69ec7d03d716ec81c8264a (diff)
downloadcpython-2d0a3d682f699cce8db6e30981d41d9125318726.zip
cpython-2d0a3d682f699cce8db6e30981d41d9125318726.tar.gz
cpython-2d0a3d682f699cce8db6e30981d41d9125318726.tar.bz2
bpo-40609: Add destroy functions to _Py_hashtable (GH-20062)
Add key_destroy_func and value_destroy_func parameters to _Py_hashtable_new_full(). marshal.c and _tracemalloc.c use these destroy functions.
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 1e901ae..7c99c1e 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -545,13 +545,21 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
}
}
+static void
+w_decref_entry(void *key)
+{
+ PyObject *entry_key = (PyObject *)key;
+ Py_XDECREF(entry_key);
+}
+
static int
w_init_refs(WFILE *wf, int version)
{
if (version >= 3) {
- wf->hashtable = _Py_hashtable_new(sizeof(int),
- _Py_hashtable_hash_ptr,
- _Py_hashtable_compare_direct);
+ wf->hashtable = _Py_hashtable_new_full(sizeof(int), 0,
+ _Py_hashtable_hash_ptr,
+ _Py_hashtable_compare_direct,
+ w_decref_entry, NULL, NULL);
if (wf->hashtable == NULL) {
PyErr_NoMemory();
return -1;
@@ -560,20 +568,10 @@ w_init_refs(WFILE *wf, int version)
return 0;
}
-static int
-w_decref_entry(_Py_hashtable_t *ht, _Py_hashtable_entry_t *entry,
- void *Py_UNUSED(data))
-{
- PyObject *entry_key = (PyObject *)entry->key;
- Py_XDECREF(entry_key);
- return 0;
-}
-
static void
w_clear_refs(WFILE *wf)
{
if (wf->hashtable != NULL) {
- _Py_hashtable_foreach(wf->hashtable, w_decref_entry, NULL);
_Py_hashtable_destroy(wf->hashtable);
}
}