[Tarantool-patches] [PATCH small 1/1] rlist: use built-in offsetof() when possible
Timur Safin
tsafin at tarantool.org
Wed May 13 02:45:40 MSK 2020
LGTM
: -----Original Message-----
: From: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
: Sent: Wednesday, May 13, 2020 2:27 AM
: To: tarantool-patches at dev.tarantool.org; tsafin at tarantool.org;
: gorcunov at gmail.com
: Subject: [PATCH small 1/1] rlist: use built-in offsetof() when possible
:
: Rlist implemented its own offsetof() as a classic NULL
: pointer cast to the target type with taking address of
: the member. So it turned into NULL + member offset.
:
: But appeared undefined behaviour clang sanitizer is
: not friendly to this hack.
:
: The patch makes rlist define its own offsetof only as
: a last resort.
:
: Part of https://github.com/tarantool/tarantool/issues/4609
: ---
: Branch: http://github.com/tarantool/small/tree/gerold103/rlist-offsetof
: Issue: https://github.com/tarantool/tarantool/issues/4609
:
: small/rlist.h | 9 +++++++--
: 1 file changed, 7 insertions(+), 2 deletions(-)
:
: diff --git a/small/rlist.h b/small/rlist.h
: index 2b0bcb4..26edd2e 100644
: --- a/small/rlist.h
: +++ b/small/rlist.h
: @@ -40,6 +40,10 @@ extern "C" {
: #define typeof __typeof__
: #endif
:
: +#ifndef offsetof
: +#define offsetof(type, member) ((size_t) &((type *)0)->member)
: +#endif
: +
: /**
: * list entry and head structure
: */
: @@ -272,8 +276,9 @@ rlist_cut_before(struct rlist *head1, struct rlist
: *head2, struct rlist *item)
: * return entry by list item
: */
: #define rlist_entry(item, type, member) ({ \
: - const typeof( ((type *)0)->member ) *__mptr = (item); \
: - (type *)( (char *)__mptr - ((size_t) &((type *)0)->member) ); })
: + const typeof(((type *)0)->member) *__mptr = (item); \
: + (type *)( (char *)__mptr - offsetof(type,member)); \
: +})
:
: /**
: * return first entry
: --
: 2.21.1 (Apple Git-122.3)
More information about the Tarantool-patches
mailing list