[Tarantool-patches] [PATCH 2.X v3] module api: box_ibuf_* wrappers

Alexander Turenko alexander.turenko at tarantool.org
Tue Oct 13 21:21:45 MSK 2020


>  create mode 100644 src/box/box_ibuf.c
>  create mode 100644 src/box/box_ibuf.h

I would name it just src/box/ibuf.[ch].

> +void
> +box_ibuf_read_range(box_ibuf_t *ibuf, char ***rpos, char ***wpos)
> +{
> +	if (!ibuf)
> +		return;

I would assert on this.

> +	if (rpos)
> +		*rpos = &ibuf->rpos;
> +	if (wpos)
> +		*wpos = &ibuf->wpos;

We use explicit == 0 / == NULL checks across our code.

> index 000000000..235b87560
> --- /dev/null
> +++ b/src/box/box_ibuf.h
> @@ -0,0 +1,68 @@
> +#pragma once
> +/*
> <...>
> +
> +#include <stddef.h>

It defines NULL and size_t as well as stdlib.h, but you include stdlib.h
in the .c file, so I would use the same header in both. Not sure which
one should be preferred.

> +
> +#include <trivia/util.h>
> +#include <small/ibuf.h>

How about just define an opaque structure?

 | struct ibuf;

But include small/ibuf.h explicitly in the .c file?

> +static int
> +test_box_ibuf(lua_State *L)
> +{
> +	(void)L;

There is usage of L at end of the function.

> +	struct slab_cache *slabc = cord_slab_cache();
> +	assert(slabc != NULL);
> +	box_ibuf_t ibuf;
> +
> +	ibuf_create(&ibuf, slabc, 16320);
> +	assert(ibuf_used(&ibuf) == 0);
> +	box_ibuf_reserve(&ibuf, 65536);
> +	char **rpos;
> +	char **wpos;
> +	box_ibuf_read_range(&ibuf, &rpos, &wpos);
> +
> +	void *ptr = ibuf_alloc(&ibuf, 10);
> +	assert(ptr != NULL);
> +
> +	assert(ibuf_used(&ibuf) == 10);
> +	assert((*wpos - *rpos) == 10);

Now box_ibuf_read_range() should give the updated wpos.

> +
> +	ptr = ibuf_alloc(&ibuf, 10000);
> +	assert(ptr);
> +	assert(ibuf_used(&ibuf) == 10010);
> +	assert((*wpos - *rpos) == 10010);

Same here.

> +
> +	ibuf_reset(&ibuf);
> +	assert(ibuf_used(&ibuf) == 0);

I would test box_ibuf_write_range() as well.

The test per se is more like how internal ibuf operations are
interoperate with the public API rathen than a unit test of the public
API. However it is okay, it'll also do the work and I would not bother
much now.


More information about the Tarantool-patches mailing list