From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 DEB19446439 for ; Sun, 11 Oct 2020 18:27:00 +0300 (MSK) References: From: Vladislav Shpilevoy Message-ID: Date: Sun, 11 Oct 2020 17:26:59 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Alexander Turenko Cc: tarantool-patches@dev.tarantool.org Thanks for the patch! See 3 comments below. > diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h > index 16ee9f414..11ca278e5 100644 > --- a/src/lib/core/fiber.h > +++ b/src/lib/core/fiber.h > @@ -386,6 +386,82 @@ struct slab_cache; > +/** > + * 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. > + * behaviour. > + */ > +API_EXPORT void * > +box_region_alloc(size_t size); > + > +/** > + * 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? > + > +/** > + * Truncate the box region to the given size. > + */ > +void > +box_region_truncate(size_t size); > + > /** \endcond public */ > > /** > diff --git a/test/app-tap/module_api.c b/test/app-tap/module_api.c > index a79fbed0d..b5949cde4 100644 > --- a/test/app-tap/module_api.c > +++ b/test/app-tap/module_api.c > @@ -15,6 +15,10 @@ > #define STR2(x) #x > #define STR(x) STR2(x) > > +#ifndef lengthof > +#define lengthof(array) (sizeof (array) / sizeof ((array)[0])) > +#endif 3. Extra whitespace after 'sizeof'.