[Tarantool-patches] [PATCH v3 00/10] fix say_x format and rework fibers

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Thu May 13 14:17:15 MSK 2021


On 13.05.2021 10:17, Cyrill Gorcunov wrote:
> On Wed, May 12, 2021 at 08:41:42PM +0200, Vladislav Shpilevoy wrote:
>>>
>>> static int
>>> lbox_fiber_top_entry(struct fiber *f, void *cb_ctx)
>>> {
>>> 	struct lua_State *L = (struct lua_State *) cb_ctx;
>>>
>>> -->	lua_pushfstring(L, "%f/%s", (lua_Number)f->fid, f->name);
>>>
>>> why do we use float formate here at all?!
>>
>> Because lua_pushfstring() does not support %llu.
> 
> What about the idea below? float is 4 byte len and won't cover the
> 8 byte integer so we will have a rounding error.

Looks good. But also this is strange how did it work before? lua_Number
is double, if I am not mistaken. Which means it should have %lf format,
and it should be fine for all the reachable fiber IDs.

Anyway, the solution below looks good too.

> ---
> [cyrill at grain tarantool.git] git diff
> diff --git a/src/lua/fiber.c b/src/lua/fiber.c
> index 02ec3d158..753b9aa16 100644
> --- a/src/lua/fiber.c
> +++ b/src/lua/fiber.c
> @@ -337,7 +337,10 @@ lbox_fiber_top_entry(struct fiber *f, void *cb_ctx)
>  {
>         struct lua_State *L = (struct lua_State *) cb_ctx;
>  
> -       lua_pushfstring(L, "%f/%s", (lua_Number)f->fid, f->name);
> +       char sbuf[FIBER_NAME_MAX + 32];
> +       snprintf(sbuf, sizeof(sbuf), "%llu/%s",
> +                (long long)f->fid, f->name);
> +       lua_pushstring(L, sbuf);
>  
>         lua_newtable(L);
>  
> 


More information about the Tarantool-patches mailing list