From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 8FF686BEC2E; Fri, 27 Oct 2023 15:59:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8FF686BEC2E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1698411548; bh=RPcwcjwO++Fje0pd9EV2IVCknVgNGZI6lyWcit98YRM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=i7JXkbMrMnJB/8l2rO+AjmNCqBynLeUu60YIvecu8vqhGXDqLibRMoh/iQpZzcFp+ qCDXKDe0pbCaVbwTBLl1BXSF7kmfE2bzJ0UmXQoz9Rh6eTcA2q8kNgUKskQq+T70sp mpc2wHoK3M5f8XHeZV0VrFQWCe0rM5YWrnoeXH5A= Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D32546BEC2E for ; Fri, 27 Oct 2023 15:57:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D32546BEC2E Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-507c1936fd5so3594835e87.1 for ; Fri, 27 Oct 2023 05:57:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698411474; x=1699016274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gTPZaus7Im7qb5PU8tPazUXRreuYICSHgqDjWY+//SY=; b=GYuZmNWQyHGaUgWmotZgn438puXuyCE7Z9WGpmEkmjOaaE/J+JlI667v08lwnEZJAB lnYZCo95LtAMt0ugWqEKr8a3OoDBZX7aA0sDAlGrGA8DGhXmWi4QK+n+4lhgUxiPAZKW YQ0HMgol82ESN69MoA3QVF/Ab8wOJYAsl568TwQTJeunafmd22ACvkQMrCEajw5QJ71U qAyobVWpHJt43+jlo7MPBM/FdOv+RKiXPbo1nbrJ6GfksSrA2GB2LJniiWBLY3KKeXZs 5fX3Ie847VddYtP/JSdhkHD2/M3V2YJZ/KfHuDvORqha839CtBaWJdIAQ13A3xMbyptR GJOg== X-Gm-Message-State: AOJu0Yy5cm61pVlxNJ6PPbhppAnFQbhMaysgRgh0ApL/5ehyn8+tXM0P 4FFFrVMAe6w8fXXVcMTC6u75CGLkFHYf8Q== X-Google-Smtp-Source: AGHT+IFA8MQ67oiVjDd0yVTylw0VYhVUMKomWTM9B8YGv4pCsmWBKW3V8z6Lb5n1RUEaWTc8MKZg4Q== X-Received: by 2002:a05:6512:692:b0:4fe:2815:8ba7 with SMTP id t18-20020a056512069200b004fe28158ba7mr1994012lfe.25.1698411473799; Fri, 27 Oct 2023 05:57:53 -0700 (PDT) Received: from localhost.localdomain ([185.205.79.42]) by smtp.gmail.com with ESMTPSA id g3-20020a19e043000000b004ff8cd27a61sm270510lfj.213.2023.10.27.05.57.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Oct 2023 05:57:53 -0700 (PDT) To: tarantool-patches@dev.tarantool.org, sergeyb@tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Date: Fri, 27 Oct 2023 15:57:38 +0300 Message-Id: <20231027125738.29527-3-max.kokryashkin@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231027125738.29527-1-max.kokryashkin@gmail.com> References: <20231027125738.29527-1-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 2/2] Fix last commit. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Maksim Kokryashkin via Tarantool-patches Reply-To: Maksim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Reported by PluMGMK. (cherry-picked from commit 224129a8e64bfa219d35cd03055bf03952f167f6) The error handler for GC finalizers 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 ++ .../fix-finalizer-error-handler-init.test.c | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/tarantool-c-tests/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/fix-finalizer-error-handler-init.test.c b/test/tarantool-c-tests/fix-finalizer-error-handler-init.test.c new file mode 100644 index 00000000..44c1d96b --- /dev/null +++ b/test/tarantool-c-tests/fix-finalizer-error-handler-init.test.c @@ -0,0 +1,30 @@ +#include "lua.h" +#include "test.h" +#include "utils.h" + +#include "lj_obj.h" + +/* + * This test demonstrates an uncleared Lua stack after the + * initialization of the error handler for GC finalizers. + */ + +static int stack_is_clean(void *test_state) +{ + lua_State *L = test_state; + assert_ptr_equal(L->top, L->base); + 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; +} -- 2.39.3 (Apple Git-145)