Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Timur Safin <tsafin@tarantool.org>,
	tarantool-patches@dev.tarantool.org, alyapunov@tarantool.org,
	korablev@tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 06/10] region: use aligned allocations where necessary
Date: Fri, 29 May 2020 01:07:02 +0200	[thread overview]
Message-ID: <c27ce78f-d60f-2084-8c63-4c6e39521d03@tarantool.org> (raw)
In-Reply-To: <049e01d6352f$96a7e950$c3f7bbf0$@tarantool.org>

Thanks for the review!

On 28/05/2020 22:35, Timur Safin wrote:
> 
> 
> : From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
> : Subject: [PATCH v2 06/10] region: use aligned allocations where necessary
> : 
> 
> 
> : diff --git a/src/box/alter.cc b/src/box/alter.cc
> : index dbbbcbc44..bb4254878 100644
> : --- a/src/box/alter.cc
> : +++ b/src/box/alter.cc
> : @@ -537,11 +537,13 @@ space_format_decode(const char *data, uint32_t
> : *out_count,
> :  		*fields = NULL;
> :  		return 0;
> :  	}
> : -	size_t size = count * sizeof(struct field_def);
> : +	size_t size;
> :  	struct field_def *region_defs =
> : -		(struct field_def *) region_alloc(region, size);
> : +		region_alloc_array(region, typeof(region_defs[0]), count,
> : +				   &size);
> 
> I'd say that `typeof(region_defs[0])` is very indirect way to write 
> `struct field_def` :) Why you've chosen this way (and not 
> simpler/clearer) way?

To avoid bugs like this:
https://github.com/tarantool/tarantool/commit/d1647590ec4263592d6408cd4c16c2c2d55a7847

Talking of simpler/clearer - I consider my way both simpler and clearer. And
safer. When type name is written only once, in variable declaration, there is
no chance in screwing it later, if you use sizeof(variable) and typeof(variable)
instead of duplicating type name.

> : @@ -2452,10 +2454,12 @@ on_replace_dd_space(struct trigger * /* trigger
> : */, void *event)
> :  		 * comparators must be updated.
> :  		 */
> :  		struct key_def **keys;
> : -		size_t bsize = old_space->index_count * sizeof(keys[0]);
> : -		keys = (struct key_def **) region_alloc(&fiber()->gc, bsize);
> : +		size_t bsize;
> : +		keys = region_alloc_array(&fiber()->gc, typeof(keys[0]),
> : +					  old_space->index_count, &bsize);
> 
> Oh, now I see - for copy-paste sake :)

No. I explained it above.

> And joking aside, putting aside all debatable complains about 
> simpler/clearer code which might be used (which you could ignore
> in general), here is real complain - this is gcc preprocessor
> extension, which might be not working under other C99/C11-compliant
> compilers. Which we would rather avoid in a longer run (if standard 
> C compatible code would not require much efforts from us, like in
> these cases)

We can't work without typeof(), because our generic data structures
heavily depend on it: rlist, stailq, heap. Tarantool uses them so
extensively, that it probably would be easier to implement them from
the scratch somehow, than get rid of them.

  reply	other threads:[~2020-05-28 23:07 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27 23:32 [Tarantool-patches] [PATCH v2 00/10] Sanitize unaligned access Vladislav Shpilevoy
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 01/10] small: sanitized rlist and new region API Vladislav Shpilevoy
2020-05-28 20:41   ` Timur Safin
2020-05-28 22:56     ` Vladislav Shpilevoy
2020-06-08 23:01   ` Vladislav Shpilevoy
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 10/10] xrow: use unaligned store operation in xrow_to_iovec() Vladislav Shpilevoy
2020-05-28 20:20   ` Timur Safin
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 02/10] cmake: ignore warnings on alignof() and offsetof() Vladislav Shpilevoy
2020-05-28 20:18   ` Timur Safin
2020-05-29  6:24   ` Kirill Yukhin
2020-05-29 22:34     ` Vladislav Shpilevoy
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 03/10] cmake: add option ENABLE_UB_SANITIZER Vladislav Shpilevoy
2020-05-28 20:42   ` Timur Safin
2020-05-29  8:53   ` Sergey Bronnikov
2020-05-29 22:36     ` Vladislav Shpilevoy
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 04/10] crc32: align memory access Vladislav Shpilevoy
2020-05-28 20:11   ` Timur Safin
2020-05-28 23:23     ` Vladislav Shpilevoy
2020-05-28 23:32       ` Timur Safin
2020-06-08 22:33       ` Vladislav Shpilevoy
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 05/10] sql: make BtCursor's memory aligned Vladislav Shpilevoy
2020-05-28 20:20   ` Timur Safin
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 06/10] region: use aligned allocations where necessary Vladislav Shpilevoy
2020-05-28 20:35   ` Timur Safin
2020-05-28 23:07     ` Vladislav Shpilevoy [this message]
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 07/10] vinyl: align statements and bps tree extents Vladislav Shpilevoy
2020-05-28 20:38   ` Timur Safin
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 08/10] tuple: use unaligned store-load for field map Vladislav Shpilevoy
2020-05-28 20:22   ` Timur Safin
2020-05-27 23:32 ` [Tarantool-patches] [PATCH v2 09/10] port: make port_c_entry not PACKED Vladislav Shpilevoy
2020-05-28 20:42   ` Timur Safin
2020-06-03 21:27 ` [Tarantool-patches] [PATCH v2 00/10] Sanitize unaligned access Vladislav Shpilevoy
2020-06-08 22:33 ` 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=c27ce78f-d60f-2084-8c63-4c6e39521d03@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=alyapunov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 06/10] region: use aligned allocations where necessary' \
    /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