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 BE76B6ECE3; Wed, 13 Jul 2022 14:59:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BE76B6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1657713580; bh=167n3vXXxYZM7s45x+otNitefz7uY19PGNfs0Sm9nBs=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DqVRpNU3PFKmyzRCnui58sp6axwqi4ZrtumFmIs4mwd8hTotg0TUtEcpJ3jIbdyHn n43Uf3ca8Rx2cPG8szWlg9IB7qm7KKbOMDFWrMBzPEP3cxSGG9kWwKqZx3lIrScvcG 6fI2S9G8jPk5MLdYhAWViPQgNutnheABGne3iyME= Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (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 43F5A6ECE4 for ; Wed, 13 Jul 2022 14:58:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 43F5A6ECE4 Received: by smtp56.i.mail.ru with esmtpa (envelope-from ) id 1oBb0u-000327-OM; Wed, 13 Jul 2022 14:58:45 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) In-Reply-To: Date: Wed, 13 Jul 2022 14:58:44 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.100.31) X-Mailru-Src: smtp X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9BCA415BD413502569E541C1996C98B1DBA6EA8F7F66FC3C4182A05F5380850405A32C722045805A22C190947C6B6E95772BD09D0875CEDA934F7720A6C979FC6 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0C22C572F31DE52E4EEDD2DF4914E7A12A4D0B26F5F6462B2645A02DEBB2C54349C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D341ADA1A41A420E9B2DD79EE7BC597B41AA91E98EDFEFCEFC293E39F0B94BA03B85BF95D9C93DBC49B1D7E09C32AA3244C70E816E7DD4A76889CEE3F7C463AA748853296C06374E602FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojpV6+aF9js38V6A3KIKe63g== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE40735B3D4DBD378F919CE9BD56F4E55053CF61CF14E6140F52D19381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: OK Subject: Re: [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: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! Just minor comments. LGTM Sergos > On 18 May 2022, at 11:58, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Reported by Fran=C3=A7ois Perrad. >=20 > When `io.close()` is called without arguments on already closed = default an an=20 > output the error message is `LJ_ERR_IOSTDCL` ("standard file is = closed=E2=80=9D) returned > 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. >=20 > This patch adds the corresponding check and code branch for this = corner a > case. >=20 > 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(-) >=20 > 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) >=20 > LJLIB_CF(io_method_close) > { > - IOFileUD *iof =3D L->base < L->top ? io_tofile(L) : > - io_stdfile(L, GCROOT_IO_OUTPUT); > + IOFileUD *iof; > + if (L->base < L->top) { > + iof =3D io_tofile(L); > + } else { > + iof =3D IOSTDF_IOF(L, GCROOT_IO_OUTPUT); > + if (iof->fp =3D=3D NULL) > + lj_err_caller(L, LJ_ERR_IOCLFL); > + } > return io_file_close(L, iof); > } >=20 > 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 =3D require('tap') >=20 > local test =3D tap.test('lj-735-io-close-on-closed-file') > -test:plan(1) > +test:plan(2) >=20 > local TEST_FILE =3D 'lj-735-io-close-on-closed-file.tmp' >=20 > @@ -11,11 +11,12 @@ io.output(TEST_FILE) > local status, err =3D io.close() > assert(status, err) >=20 > -status =3D pcall(io.close) > +status, err =3D pcall(io.close) >=20 > io.output(oldstdout) >=20 > test:ok(not status, 'close already closed file') > +test:ok(err:match('attempt to use a closed file'), 'correct error = message') >=20 > assert(os.remove(TEST_FILE)) >=20 > --=20 > 2.34.1 >=20