[Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup
Alexander Turenko
alexander.turenko at tarantool.org
Fri Oct 16 01:30:50 MSK 2020
> +static int
> +test_key_def_dup(lua_State *L)
> +{
> + box_key_def_t *key_def = NULL;
> + box_key_part_def_t part;
> + box_key_part_def_t *dump = NULL;
> + uint32_t dump_part_count = 0;
> +
> + key_part_def_set_nondefault(&part);
> + key_def = box_key_def_new_v2(&part, 1);
> + assert(key_def != NULL);
> + box_key_def_t *key_def_dup = box_key_def_dup(key_def);
> + assert(key_def_dup != NULL);
> +
> + dump = box_key_def_dump_parts(key_def_dup, &dump_part_count);
> + assert(dump != NULL);
> + assert(dump_part_count == 1);
> +
> + key_part_def_check_equal(&part, &dump[0]);
> + key_part_def_check_zeros(&dump[0]);
key_part_def_check_zeros() is to verify how _dump_parts() works per se.
It has no any connection with the duplicated key_def content.
So I would left just key_part_def_check_equal() here.
> +
> + box_key_def_delete(key_def_dup);
> + box_key_def_delete(key_def);
The dumped parts are allocated on the box region. I would truncate the
region at the end:
| size_t region_svp = box_region_used();
| <...>
| box_region_truncate(region_svp);
May be ignored in a test, but I would do so just to highlight the proper
usage of the API. If not us, who?
> +
> + lua_pushboolean(L, 1);
> + return 1;
> +}
> +
More information about the Tarantool-patches
mailing list