summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-21 21:00:58 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-21 21:00:58 (GMT)
commit285cf0a6014af147b82a3446d9e088ad0332720d (patch)
tree829fa2b00f39bf7ff31496cca47ddd127b135e4f /Python/marshal.c
parent928bff0b26adb643a7078575c9075b4b709c1b16 (diff)
downloadcpython-285cf0a6014af147b82a3446d9e088ad0332720d.zip
cpython-285cf0a6014af147b82a3446d9e088ad0332720d.tar.gz
cpython-285cf0a6014af147b82a3446d9e088ad0332720d.tar.bz2
hashtable.h now supports keys of any size
Issue #26588: hashtable.h now supports keys of any size, not only sizeof(void*). It allows to support key larger than sizeof(void*), but also to use less memory for key smaller than sizeof(void*).
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 7a4b9d2..83a1885 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -263,10 +263,10 @@ w_ref(PyObject *v, char *flag, WFILE *p)
if (Py_REFCNT(v) == 1)
return 0;
- entry = _Py_hashtable_get_entry(p->hashtable, v);
+ entry = _Py_HASHTABLE_GET_ENTRY(p->hashtable, v);
if (entry != NULL) {
/* write the reference index to the stream */
- _Py_HASHTABLE_ENTRY_READ_DATA(p->hashtable, &w, sizeof(w), entry);
+ _Py_HASHTABLE_ENTRY_READ_DATA(p->hashtable, entry, sizeof(w), &w);
/* we don't store "long" indices in the dict */
assert(0 <= w && w <= 0x7fffffff);
w_byte(TYPE_REF, p);
@@ -571,7 +571,8 @@ static int
w_init_refs(WFILE *wf, int version)
{
if (version >= 3) {
- wf->hashtable = _Py_hashtable_new(sizeof(int), _Py_hashtable_hash_ptr,
+ wf->hashtable = _Py_hashtable_new(sizeof(PyObject *), sizeof(int),
+ _Py_hashtable_hash_ptr,
_Py_hashtable_compare_direct);
if (wf->hashtable == NULL) {
PyErr_NoMemory();
@@ -582,9 +583,13 @@ w_init_refs(WFILE *wf, int version)
}
static int
-w_decref_entry(_Py_hashtable_entry_t *entry, void *Py_UNUSED(data))
+w_decref_entry(_Py_hashtable_t *ht, _Py_hashtable_entry_t *entry,
+ void *Py_UNUSED(data))
{
- Py_XDECREF(entry->key);
+ PyObject *entry_key;
+
+ _Py_HASHTABLE_ENTRY_READ_KEY(ht->key_size, entry, entry_key);
+ Py_XDECREF(entry_key);
return 0;
}