[Tarantool-patches] [PATCH v2 02/15] module api: expose box region

Alexander Turenko alexander.turenko at tarantool.org
Mon Oct 12 09:07:59 MSK 2020


> > +/**
> > + * 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!


More information about the Tarantool-patches mailing list