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 9C3296EFDA; Wed, 18 May 2022 12:01:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9C3296EFDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1652864498; bh=ROeqaqK2uLMX0GPUT0RKhu1hjSD1/wAOWA0XA9sWcIA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RvcU/pghzPtrpJmiaDhhkGIeDJiEc2XWmORSdOquJQyuj3qJAn7/Un8qDsOH/yCGS 2Tt6BM4J/K3gBCLmE4B3UADPP1lqyS72BpI9lOyGH3VKJP7se5FvbZBbUO3lg7CbcM wWKmsW5MmT7e3+tB/1+7szDdvlHS7ECOHvETtlGs= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 424856E0F4 for ; Wed, 18 May 2022 12:00:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 424856E0F4 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1nrFXq-0002l1-9z; Wed, 18 May 2022 12:00:38 +0300 To: Sergey Ostanevich , Igor Munkin Date: Wed, 18 May 2022 11:58:17 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AB830312DE1E2EF840ED3EC08FE9F7DDCA8C99313F8A8872182A05F538085040A617103C7612DBA5F2AC4DB7E67224C5580C5694578BD9587164F7DCE5CAE9DA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7811C3E343B302E2EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D071468F2F69688EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BEBC5CAB6D411FFA6D0557222547B5D8754121F07EF6B281DCC7F00164DA146DAFE8445B8C89999728AA50765F79006370B730A9793D99025389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC882B967D547A19D2FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B56969FF77163EA2B75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44671AA518CC42EA90C912BAED7AAC53FB6E27BBFAAA129DCC35AD8E7B684C087B9C2B6934AE262D3EE7EAB7254005DCED1C39E39C5FB3188C4EAF44D9B582CE87C8A4C02DF684249C2E763F503762DF5017A45118377F5F9E8E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A246DFF68F0EE19EF87077CA11DEABE9EB16277108BDB907D96F343462904BAC8955A8B90A575C301D7E09C32AA3244C1E8552F4A1B69283448A730C4EFA87188580396430872480927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtNJAk7CcUJ0c4AS/aYGJMQ== X-Mailru-Sender: 689FA8AB762F739339CABD9B3CA9A7D6B706F2E7E84ED7CEF4CB67C0D4E420140FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/2] Fix io.close() error message. 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Reported by François Perrad. When `io.close()` is called without arguments on already closed default output the error message is `LJ_ERR_IOSTDCL` ("standard file is closed") instead of `LJ_ERR_IOCLFL` ("attempt to use a closed file"). It is never a "real" standard file, because trying to close a standard throws an error ("cannot close standard file"). Also, this is inconsistent with PUC Lua. This patch adds the corresponding check and code branch for this corner case. Sergey Kaplun: * added the description and the test for the problem --- src/lib_io.c | 10 ++++++++-- .../lj-735-io-close-on-closed-file.test.lua | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib_io.c b/src/lib_io.c index d9028938..f0108227 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -288,8 +288,14 @@ static int io_file_lines(lua_State *L) LJLIB_CF(io_method_close) { - IOFileUD *iof = L->base < L->top ? io_tofile(L) : - io_stdfile(L, GCROOT_IO_OUTPUT); + IOFileUD *iof; + if (L->base < L->top) { + iof = io_tofile(L); + } else { + iof = IOSTDF_IOF(L, GCROOT_IO_OUTPUT); + if (iof->fp == NULL) + lj_err_caller(L, LJ_ERR_IOCLFL); + } return io_file_close(L, iof); } diff --git a/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua b/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua index 795dad6c..5e031c48 100644 --- a/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua +++ b/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua @@ -1,7 +1,7 @@ local tap = require('tap') local test = tap.test('lj-735-io-close-on-closed-file') -test:plan(1) +test:plan(2) local TEST_FILE = 'lj-735-io-close-on-closed-file.tmp' @@ -11,11 +11,12 @@ io.output(TEST_FILE) local status, err = io.close() assert(status, err) -status = pcall(io.close) +status, err = pcall(io.close) io.output(oldstdout) test:ok(not status, 'close already closed file') +test:ok(err:match('attempt to use a closed file'), 'correct error message') assert(os.remove(TEST_FILE)) -- 2.34.1