[Tarantool-patches] [PATCH v2 3/4] fiber: refactor lua backtrace routines
Egor Elchinov
eelchinov at tarantool.org
Wed Jul 14 12:42:15 MSK 2021
On 12.07.2021 15:13, Cyrill Gorcunov via Tarantool-patches wrote:
> On Fri, Jul 09, 2021 at 02:03:52PM +0300, Egor Elchinov via Tarantool-patches wrote:
>> From: Egor Elchinov <elchinov.es at gmail.com>
>>
>> Lua backtrace with callback moved to new routine
>> `lua_backtrace_cb()` similar to the `backtrace_cb()`
>> for C backtrace.
>>
>> Needed for: #4002
>> #ifdef ENABLE_BACKTRACE
>> static void
>> -dump_lua_frame(struct lua_State *L, lua_Debug *ar, int tb_frame)
>> +dump_lua_frame(struct lua_State *L, const char *name, const char *src, int line,
>> + int tb_frame)
>> {
>> char buf[512];
>> snprintf(buf, sizeof(buf), "%s in %s at line %i",
>> - ar->name != NULL ? ar->name : "(unnamed)",
>> - ar->source, ar->currentline);
>> + name != NULL ? name : "(unnamed)", src, line);
>
> Please add explicit \0 here to the buffer
>
> buf[sizeof(buf)-1] = 0;
>
> and in other places of this patch as well.
>
Fixed.
>>
>> +static int
>> +dump_lua_frame_cb(lua_Debug *ar, int tb_frame, void *cb_ctx)
>> +{
>> + (void) tb_frame;
>> + struct lua_fiber_tb_ctx *tb_ctx = (struct lua_fiber_tb_ctx *)cb_ctx;
>
> Side note: for plain C you don't need to put explicit type conversion
> from void, iow
>
> struct lua_fiber_tb_ctx *tb_ctx = cb_ctx;
>
> ie enough, but up to you. The rest is ok to me, thanks!
>
Thanks for this observation. Although, it seems to me that in this case
it's better to make an explicit cast for consistency with other similar
cases and C++ rules.
More information about the Tarantool-patches
mailing list