summaryrefslogtreecommitdiffstats
path: root/Modules/_tracemalloc.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-22 11:13:01 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-22 11:13:01 (GMT)
commitc9553876ae88b7f1494cff826c8f7a08c2ac5614 (patch)
tree63f4ec83ec78ca95db74b03bd033a4953d27d653 /Modules/_tracemalloc.c
parent0b2d71bc70c32560853fa91f58dc37af8f08090c (diff)
downloadcpython-c9553876ae88b7f1494cff826c8f7a08c2ac5614.zip
cpython-c9553876ae88b7f1494cff826c8f7a08c2ac5614.tar.gz
cpython-c9553876ae88b7f1494cff826c8f7a08c2ac5614.tar.bz2
Simplify implementation of hashtable.c
Issue #26588: Remove copy_data, free_data and get_data_size callbacks from hashtable.h. These callbacks are not used in Python and makes the code more complex. Remove also the _Py_HASHTABLE_ENTRY_DATA_AS_VOID_P() macro which uses an unsafe pointer dereference (can cause memory alignment issue). Replace the macro usage with _Py_HASHTABLE_ENTRY_READ_DATA() which is implemented with the safe memcpy() function.
Diffstat (limited to 'Modules/_tracemalloc.c')
-rw-r--r--Modules/_tracemalloc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 3c5319b..c48dd08 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -220,16 +220,15 @@ hashtable_compare_unicode(size_t key_size, const void *pkey,
return key == entry_key;
}
-static _Py_hashtable_allocator_t hashtable_alloc = {malloc, free};
-
static _Py_hashtable_t *
hashtable_new(size_t key_size, size_t data_size,
_Py_hashtable_hash_func hash_func,
_Py_hashtable_compare_func compare_func)
{
+ _Py_hashtable_allocator_t hashtable_alloc = {malloc, free};
return _Py_hashtable_new_full(key_size, data_size, 0,
hash_func, compare_func,
- NULL, NULL, NULL, &hashtable_alloc);
+ &hashtable_alloc);
}
static void*
@@ -1120,7 +1119,8 @@ tracemalloc_pyobject_decref_cb(_Py_hashtable_t *tracebacks,
_Py_hashtable_entry_t *entry,
void *user_data)
{
- PyObject *obj = (PyObject *)_Py_HASHTABLE_ENTRY_DATA_AS_VOID_P(tracebacks, entry);
+ PyObject *obj;
+ _Py_HASHTABLE_ENTRY_READ_DATA(tracebacks, entry, sizeof(obj), &obj);
Py_DECREF(obj);
return 0;
}
@@ -1151,7 +1151,8 @@ py_tracemalloc_get_traces(PyObject *self, PyObject *obj)
/* the traceback hash table is used temporarily to intern traceback tuple
of (filename, lineno) tuples */
- get_traces.tracebacks = hashtable_new(sizeof(traceback_t *), sizeof(PyObject *),
+ get_traces.tracebacks = hashtable_new(sizeof(traceback_t *),
+ sizeof(PyObject *),
_Py_hashtable_hash_ptr,
_Py_hashtable_compare_direct);
if (get_traces.tracebacks == NULL) {
@@ -1186,8 +1187,9 @@ finally:
tracemalloc_pyobject_decref_cb, NULL);
_Py_hashtable_destroy(get_traces.tracebacks);
}
- if (get_traces.traces != NULL)
+ if (get_traces.traces != NULL) {
_Py_hashtable_destroy(get_traces.traces);
+ }
return get_traces.list;
}