diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 11:13:01 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-22 11:13:01 (GMT) |
commit | c9553876ae88b7f1494cff826c8f7a08c2ac5614 (patch) | |
tree | 63f4ec83ec78ca95db74b03bd033a4953d27d653 /Modules/hashtable.h | |
parent | 0b2d71bc70c32560853fa91f58dc37af8f08090c (diff) | |
download | cpython-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/hashtable.h')
-rw-r--r-- | Modules/hashtable.h | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/Modules/hashtable.h b/Modules/hashtable.h index 6eb5737..eede038 100644 --- a/Modules/hashtable.h +++ b/Modules/hashtable.h @@ -35,9 +35,6 @@ typedef struct { #define _Py_HASHTABLE_ENTRY_DATA(TABLE, ENTRY) \ ((char *)(ENTRY) + sizeof(_Py_hashtable_entry_t) + (TABLE)->key_size) -#define _Py_HASHTABLE_ENTRY_DATA_AS_VOID_P(TABLE, ENTRY) \ - (*(void **)_Py_HASHTABLE_ENTRY_DATA(TABLE, ENTRY)) - /* Get a key value from pkey: use memcpy() rather than a pointer dereference to avoid memory alignment issues. */ #define _Py_HASHTABLE_READ_KEY(KEY_SIZE, PKEY, DST_KEY) \ @@ -66,9 +63,6 @@ typedef Py_uhash_t (*_Py_hashtable_hash_func) (size_t key_size, typedef int (*_Py_hashtable_compare_func) (size_t key_size, const void *pkey, const _Py_hashtable_entry_t *he); -typedef void* (*_Py_hashtable_copy_data_func)(void *data); -typedef void (*_Py_hashtable_free_data_func)(void *data); -typedef size_t (*_Py_hashtable_get_data_size_func)(void *data); typedef struct { /* allocate a memory block */ @@ -90,9 +84,6 @@ typedef struct { _Py_hashtable_hash_func hash_func; _Py_hashtable_compare_func compare_func; - _Py_hashtable_copy_data_func copy_data_func; - _Py_hashtable_free_data_func free_data_func; - _Py_hashtable_get_data_size_func get_data_size_func; _Py_hashtable_allocator_t alloc; } _Py_hashtable_t; @@ -119,9 +110,6 @@ PyAPI_FUNC(_Py_hashtable_t *) _Py_hashtable_new_full( size_t init_size, _Py_hashtable_hash_func hash_func, _Py_hashtable_compare_func compare_func, - _Py_hashtable_copy_data_func copy_data_func, - _Py_hashtable_free_data_func free_data_func, - _Py_hashtable_get_data_size_func get_data_size_func, _Py_hashtable_allocator_t *allocator); PyAPI_FUNC(void) _Py_hashtable_destroy(_Py_hashtable_t *ht); @@ -155,7 +143,7 @@ PyAPI_FUNC(int) _Py_hashtable_set( size_t key_size, const void *pkey, size_t data_size, - void *data); + const void *data); #define _Py_HASHTABLE_SET(TABLE, KEY, DATA) \ _Py_hashtable_set(TABLE, sizeof(KEY), &KEY, sizeof(DATA), &(DATA)) |