summaryrefslogtreecommitdiffstats
path: root/Modules/hashtable.h
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-23 08:25:01 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-23 08:25:01 (GMT)
commite8c6b2fd1bb75c6a3865745de30f26e235d3f12f (patch)
treea7687e057d730dfb732aaf145fad35025172a3cf /Modules/hashtable.h
parent42bcf37fcffa65592e401c43aa8c0190452b28b0 (diff)
downloadcpython-e8c6b2fd1bb75c6a3865745de30f26e235d3f12f.zip
cpython-e8c6b2fd1bb75c6a3865745de30f26e235d3f12f.tar.gz
cpython-e8c6b2fd1bb75c6a3865745de30f26e235d3f12f.tar.bz2
Issue #26588:
* _Py_HASHTABLE_ENTRY_DATA: change type from "char *" to "const void *" * Add _Py_HASHTABLE_ENTRY_WRITE_PKEY() macro * Rename _Py_HASHTABLE_ENTRY_WRITE_DATA() macro to _Py_HASHTABLE_ENTRY_WRITE_PDATA() * Add _Py_HASHTABLE_ENTRY_WRITE_DATA() macro
Diffstat (limited to 'Modules/hashtable.h')
-rw-r--r--Modules/hashtable.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/Modules/hashtable.h b/Modules/hashtable.h
index 4199aab..9c3fbdd 100644
--- a/Modules/hashtable.h
+++ b/Modules/hashtable.h
@@ -30,10 +30,13 @@ typedef struct {
} _Py_hashtable_entry_t;
#define _Py_HASHTABLE_ENTRY_KEY(ENTRY) \
- ((const void *)((char *)(ENTRY) + sizeof(_Py_hashtable_entry_t)))
+ ((const void *)((char *)(ENTRY) \
+ + sizeof(_Py_hashtable_entry_t)))
#define _Py_HASHTABLE_ENTRY_DATA(TABLE, ENTRY) \
- ((char *)(ENTRY) + sizeof(_Py_hashtable_entry_t) + (TABLE)->key_size)
+ ((const void *)((char *)(ENTRY) \
+ + sizeof(_Py_hashtable_entry_t) \
+ + (TABLE)->key_size))
/* Get a key value from pkey: use memcpy() rather than a pointer dereference
to avoid memory alignment issues. */
@@ -49,10 +52,26 @@ typedef struct {
memcpy(&(KEY), _Py_HASHTABLE_ENTRY_KEY(ENTRY), sizeof(KEY)); \
} while (0)
-#define _Py_HASHTABLE_ENTRY_READ_DATA(TABLE, ENTRY, DATA_SIZE, DATA) \
+#define _Py_HASHTABLE_ENTRY_WRITE_PKEY(KEY_SIZE, ENTRY, PKEY) \
+ do { \
+ memcpy((void *)_Py_HASHTABLE_ENTRY_KEY(ENTRY), (PKEY), (KEY_SIZE)); \
+ } while (0)
+
+#define _Py_HASHTABLE_ENTRY_READ_PDATA(TABLE, ENTRY, DATA_SIZE, PDATA) \
+ do { \
+ assert((DATA_SIZE) == (TABLE)->data_size); \
+ memcpy((PDATA), _Py_HASHTABLE_ENTRY_DATA(TABLE, (ENTRY)), \
+ (DATA_SIZE)); \
+ } while (0)
+
+#define _Py_HASHTABLE_ENTRY_READ_DATA(TABLE, ENTRY, DATA) \
+ _Py_HASHTABLE_ENTRY_READ_PDATA((TABLE), (ENTRY), sizeof(DATA), &(DATA))
+
+#define _Py_HASHTABLE_ENTRY_WRITE_PDATA(TABLE, ENTRY, DATA_SIZE, PDATA) \
do { \
assert((DATA_SIZE) == (TABLE)->data_size); \
- memcpy(DATA, _Py_HASHTABLE_ENTRY_DATA(TABLE, ENTRY), DATA_SIZE); \
+ memcpy((void *)_Py_HASHTABLE_ENTRY_DATA((TABLE), (ENTRY)), \
+ (PDATA), (DATA_SIZE)); \
} while (0)