]> git.ipfire.org Git - thirdparty/git.git/commit - hashmap.h
OFFSETOF_VAR macro to simplify hashmap iterators
authorEric Wong <e@80x24.org>
Sun, 6 Oct 2019 23:30:41 +0000 (23:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2019 01:20:11 +0000 (10:20 +0900)
commit23dee69f53cf5024ca79e0b707dcb03c63f33bef
treee99f2fd2a4e1fe622451eeaafa8c37b40413ec10
parentc8e424c9c94d97b18cd335be17f32a8ce94a5b7f
OFFSETOF_VAR macro to simplify hashmap iterators

While we cannot rely on a `__typeof__' operator being portable
to use with `offsetof'; we can calculate the pointer offset
using an existing pointer and the address of a member using
pointer arithmetic for compilers without `__typeof__'.

This allows us to simplify usage of hashmap iterator macros
by not having to specify a type when a pointer of that type
is already given.

In the future, list iterator macros (e.g. list_for_each_entry)
may also be implemented using OFFSETOF_VAR to save hackers the
trouble of using container_of/list_entry macros and without
relying on non-portable `__typeof__'.

v3: use `__typeof__' to avoid clang warnings

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 files changed:
attr.c
blame.c
builtin/describe.c
builtin/difftool.c
config.c
diff.c
diffcore-rename.c
git-compat-util.h
hashmap.h
merge-recursive.c
name-hash.c
revision.c
submodule-config.c
t/helper/test-hashmap.c
t/helper/test-lazy-init-name-hash.c