[Tarantool-patches] [PATCH v2 1/1] fiber: extend max fiber name length to 255
Cyrill Gorcunov
gorcunov at gmail.com
Mon Mar 16 10:19:27 MSK 2020
On Sun, Mar 15, 2020 at 04:11:14PM +0100, Vladislav Shpilevoy wrote:
...
> diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c
> index ada7972cb..359ef1187 100644
> --- a/src/lib/core/fiber.c
> +++ b/src/lib/core/fiber.c
> @@ -912,8 +912,26 @@ fiber_loop(MAYBE_UNUSED void *data)
> void
> fiber_set_name(struct fiber *fiber, const char *name)
> {
> - assert(name != NULL);
> - snprintf(fiber->name, sizeof(fiber->name), "%s", name);
> + size_t len = strlen(name);
> + if (len <= FIBER_NAME_INLINE) {
> + if (fiber->name != fiber->inline_name) {
> + free(fiber->name);
> + fiber->name = fiber->inline_name;
> + }
> + } else {
> + if (len > FIBER_NAME_MAX)
> + len = FIBER_NAME_MAX;
> + char *new_name;
> + if (fiber->name != fiber->inline_name)
> + new_name = realloc(fiber->name, len + 1);
> + else
> + new_name = malloc(len + 1);
> + if (new_name == NULL)
> + panic("fiber_set_name() failed with OOM");
> + fiber->name = new_name;
> + }
> + memcpy(fiber->name, name, len);
> + fiber->name[len] = 0;
> }
Thank, Vlad! I like the patch. There is only one concern I have: for
some reason we has been defining faiber name as
char name[FIBER_NAME_MAX + 1];
where FIBER_NAME_MAX = 32 and finally this expands to "char name[33];"
I'm too lazy to find who exactly introduced this but it is bloody
wrong: compiler alings members to eliminate data access penalty, thus
_actually_ it will be defined as 8 multilier, ie 40 bytes.
Thus, if you don't mind I propose make FIBER_NAME_INLINE = 40
*including* string terminating zero.
Actually we can make it on top then. Up to you. Anyway
Reviewed-by: Cyrill Gorcunov <gorcunov at gmail.com>
More information about the Tarantool-patches
mailing list