From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (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 F1A73469719 for ; Mon, 12 Oct 2020 09:07:41 +0300 (MSK) Date: Mon, 12 Oct 2020 09:07:59 +0300 From: Alexander Turenko Message-ID: <20201012060759.u7w6b2xmptyswnwi@tkn_work_nb> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH v2 02/15] module api: expose box region List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org > > +/** > > + * Allocate size bytes from the box region. > > + * > > + * Don't use this function to allocate a memory block for a value > > + * or array of values of a type with alignment requirements. A > > + * violation of alignment requrements leads to undefined > > 1. requrements -> requirements. Thanks! > > +/** > > + * Allocate size bytes from the box region with given alignment. > > + * > > + * Alignment must be a power of 2. > > + */ > > +API_EXPORT void * > > +box_region_aligned_alloc(size_t size, size_t alignment); > > 2. Do you think we should add a protection against stupidness? > For example, validate that the alignment is actually a power of 2, > at runtime, in release build too? Or leave it on user's > conscience? I think that a build time check is enough, considering that the C standard requires alignment to be a power of 2. However the comment may be useful. I didn't check whether it is actually required to be a power of 2 and made attempt to pass an invalid value from in my test (got an assertion fail). So the comment may be useful. At least as the extra precaution against inadvertence. > > +#ifndef lengthof > > +#define lengthof(array) (sizeof (array) / sizeof ((array)[0])) > > +#endif > > 3. Extra whitespace after 'sizeof'. Thanks!