STINNER Victor <vstin...@python.org> added the comment:
Modules/hashtable.c and Modules/hashtable.h use a different approach. The variable size data is *not* part of the structure: typedef struct { /* used by _Py_hashtable_t.buckets to link entries */ _Py_slist_item_t _Py_slist_item; Py_uhash_t key_hash; /* key (key_size bytes) and then data (data_size bytes) follows */ } _Py_hashtable_entry_t; In memory, we have: [_Py_slist_item, key_hash, key, data] where key size is table->key_size bytes (not stored in each table entry, only in the stable). Pointer to key and data is computed with these macros: #define _Py_HASHTABLE_ENTRY_PKEY(ENTRY) \ ((const void *)((char *)(ENTRY) \ + sizeof(_Py_hashtable_entry_t))) #define _Py_HASHTABLE_ENTRY_PDATA(TABLE, ENTRY) \ ((const void *)((char *)(ENTRY) \ + sizeof(_Py_hashtable_entry_t) \ + (TABLE)->key_size)) But this approach is more annoying to use, it requires to play with pointers and requires such ugly macros. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40120> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com