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 EB081678410; Wed, 8 Nov 2023 00:07:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EB081678410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1699391244; bh=KE4jClsRPKkIJ7bdVSneF2O+DwSRSz5yPgdYI8ztR4A=; 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=YiPEVajm+WaYvlr7BznwydEOYTZ/uYmEpWUUNrYOFLgRzQMQa5HMfnxil/2t/YCB0 4udb3FTw6L0mg2sl/h0hZTlYS+bfyRafkExKVKT8Batlw+DabvPnbTiXXvTMfI+gL8 ZUz1bsh5C5s3JMS7SjjwkyqQEOskCHP1D8DteM24= Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 CA16A67840D for ; Wed, 8 Nov 2023 00:06:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CA16A67840D Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2c50fbc218bso76427801fa.3 for ; Tue, 07 Nov 2023 13:06:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699391190; x=1699995990; 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=LVpyucKJTeayWREjQ7iqAXflTy+XtSv0p8djI913/5Q=; b=shpPp8sa8efelVWPXPEaJEiYPiRk8vfrnSzg5wy+FmF8fhi8fVzWPdR5ZvoJslnbWD pmanS7cO4sPSONHD8f3rkHFun4lUsVyrkEDj6Ho4Pw4w5SINcLLpRd6dNCqselv/TUYf vkKuNxQQ3T6JrLqQXV6ib3umM4F00UHtpgH/AJ3kSzfxoHWBAq099NVslgMe4K2J0qX+ +hSrsJE2BguUT+HHYTT0ozZPpgVRYaQV1dJk+o4Gn/tSa0zORWk25lIUk+PTMJQJab7C uvcbP/VMv3N2ogbqKVdzPFfX9YG6c4/tH6pkMXEqjmiH6kFRmrGUIffZgkb+8UAq5xqX soqQ== X-Gm-Message-State: AOJu0YzlPl8fv7FpyioSFB/rT3iR+blXRBSSdGmSiOyRIW3zRrBXPehC b8KPsupk9oEf+R8/1NLZPDrKwWLnfhGJhg== X-Google-Smtp-Source: AGHT+IHIo2IXW+TQUlk1dG5BHjZiuRJKJvnlXSgdAmHC4a+0wPkZqJIWQeRGKE6R58Atb3BbidW8Ng== X-Received: by 2002:a05:651c:221c:b0:2c5:6c7:9e73 with SMTP id y28-20020a05651c221c00b002c506c79e73mr147669ljq.48.1699391190329; Tue, 07 Nov 2023 13:06:30 -0800 (PST) Received: from localhost.localdomain (95-24-0-215.broadband.corbina.ru. [95.24.0.215]) by smtp.gmail.com with ESMTPSA id g6-20020a2e9e46000000b002bfb71c076asm1586106ljk.43.2023.11.07.13.06.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Nov 2023 13:06:30 -0800 (PST) To: tarantool-patches@dev.tarantool.org, sergeyb@tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Date: Wed, 8 Nov 2023 00:06:16 +0300 Message-Id: <20231107210616.53138-3-max.kokryashkin@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231107210616.53138-1-max.kokryashkin@gmail.com> References: <20231107210616.53138-1-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v2 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 `_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; +} -- 2.39.3 (Apple Git-145)