From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 6A46E469710 for ; Wed, 13 May 2020 02:45:42 +0300 (MSK) From: "Timur Safin" References: <4a2553507fcf643e1e5bae0753d95ee4ff7d4253.1589325991.git.v.shpilevoy@tarantool.org> In-Reply-To: <4a2553507fcf643e1e5bae0753d95ee4ff7d4253.1589325991.git.v.shpilevoy@tarantool.org> Date: Wed, 13 May 2020 02:45:40 +0300 Message-ID: <1bc101d628b7$723747c0$56a5d740$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: ru Subject: Re: [Tarantool-patches] [PATCH small 1/1] rlist: use built-in offsetof() when possible List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: 'Vladislav Shpilevoy' , tarantool-patches@dev.tarantool.org, gorcunov@gmail.com LGTM : -----Original Message----- : From: Vladislav Shpilevoy : Sent: Wednesday, May 13, 2020 2:27 AM : To: tarantool-patches@dev.tarantool.org; tsafin@tarantool.org; : gorcunov@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)