Tarantool development patches archive
 help / color / mirror / Atom feed
From: "Timur Safin" <tsafin@tarantool.org>
To: 'Vladislav Shpilevoy' <v.shpilevoy@tarantool.org>,
	tarantool-patches@dev.tarantool.org, gorcunov@gmail.com
Subject: Re: [Tarantool-patches] [PATCH small 1/1] rlist: use built-in offsetof() when possible
Date: Wed, 13 May 2020 02:45:40 +0300	[thread overview]
Message-ID: <1bc101d628b7$723747c0$56a5d740$@tarantool.org> (raw)
In-Reply-To: <4a2553507fcf643e1e5bae0753d95ee4ff7d4253.1589325991.git.v.shpilevoy@tarantool.org>

LGTM

: -----Original Message-----
: From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
: 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)

  reply	other threads:[~2020-05-12 23:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 23:27 Vladislav Shpilevoy
2020-05-12 23:45 ` Timur Safin [this message]
2020-05-13  7:39 ` Cyrill Gorcunov
2020-05-13 22:21 ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1bc101d628b7$723747c0$56a5d740$@tarantool.org' \
    --to=tsafin@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH small 1/1] rlist: use built-in offsetof() when possible' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox