[Tarantool-patches] [PATCH v2 3/4] fiber: refactor lua backtrace routines

Cyrill Gorcunov gorcunov at gmail.com
Mon Jul 12 15:13:08 MSK 2021


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.

>  
> +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!


More information about the Tarantool-patches mailing list