[Tarantool-patches] [PATCH luajit v2 2/2] Fix last commit.

Sergey Bronnikov sergeyb at tarantool.org
Thu Nov 9 15:08:48 MSK 2023


Hi, Max

Thanks for the patch! LGTM


On 11/8/23 00:06, Maksim Kokryashkin wrote:
> From: Mike Pall <mike>
>
> Reported by PluMGMK.
>
> (cherry-picked from commit 224129a8e64bfa219d35cd03055bf03952f167f6)
>
> The `_VMEVENTS` table, where the error handler for GC finalizers
> is set, was not cleared from the stack after the initialization.
> This commit adds stack cleanup.
>
> Maxim Kokryashkin:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#9145
> ---
>   src/lib_aux.c                                 |  2 ++
>   ...91-fix-finalizer-error-handler-init.test.c | 30 +++++++++++++++++++
>   2 files changed, 32 insertions(+)
>   create mode 100644 test/tarantool-c-tests/lj-991-fix-finalizer-error-handler-init.test.c
>
> diff --git a/src/lib_aux.c b/src/lib_aux.c
> index d532a12f..ecdc67f9 100644
> --- a/src/lib_aux.c
> +++ b/src/lib_aux.c
> @@ -352,6 +352,7 @@ LUALIB_API lua_State *luaL_newstate(void)
>       lua_pushcfunction(L, error_finalizer);
>       lua_rawseti(L, -2, VMEVENT_HASH(LJ_VMEVENT_ERRFIN));
>       G(L)->vmevmask = VMEVENT_MASK(LJ_VMEVENT_ERRFIN);
> +    L->top--;
>   #endif
>     }
>     return L;
> @@ -378,6 +379,7 @@ LUALIB_API lua_State *luaL_newstate(void)
>       lua_pushcfunction(L, error_finalizer);
>       lua_rawseti(L, -2, VMEVENT_HASH(LJ_VMEVENT_ERRFIN));
>       G(L)->vmevmask = VMEVENT_MASK(LJ_VMEVENT_ERRFIN);
> +    L->top--;
>   #endif
>     }
>     return L;
> diff --git a/test/tarantool-c-tests/lj-991-fix-finalizer-error-handler-init.test.c b/test/tarantool-c-tests/lj-991-fix-finalizer-error-handler-init.test.c
> new file mode 100644
> index 00000000..49befc29
> --- /dev/null
> +++ b/test/tarantool-c-tests/lj-991-fix-finalizer-error-handler-init.test.c
> @@ -0,0 +1,30 @@
> +#include "lua.h"
> +#include "test.h"
> +#include "utils.h"
> +
> +/*
> + * This test demonstrates an uncleared Lua stack after the
> + * initialization of the error handler for GC finalizers.
> + * See https://github.com/luajit/luajit/issues/991 for
> + * details.
> + */
> +
> +static int stack_is_clean(void *test_state)
> +{
> +	lua_State *L = test_state;
> +  assert_true(lua_gettop(L) == 0);
> +	return TEST_EXIT_SUCCESS;
> +}
> +
> +int main(void)
> +{
> +	lua_State *L = utils_lua_init();
> +
> +	const struct test_unit tgroup[] = {
> +		test_unit_def(stack_is_clean)
> +	};
> +
> +	const int test_result = test_run_group(tgroup, L);
> +	utils_lua_close(L);
> +	return test_result;
> +}


More information about the Tarantool-patches mailing list