From: sergos via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Kaplun <skaplun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] Fix io.close() error message. Date: Wed, 13 Jul 2022 14:58:44 +0300 [thread overview] Message-ID: <E3C3EE44-1FE7-49D9-9DE2-AA0B194747CC@tarantool.org> (raw) In-Reply-To: <e3484b689c2ca98c8a6bf64316d160ed9e14efbe.1652863494.git.skaplun@tarantool.org> Hi! Thanks for the patch! Just minor comments. LGTM Sergos > On 18 May 2022, at 11:58, Sergey Kaplun <skaplun@tarantool.org> wrote: > > From: Mike Pall <mike> > > Reported by François Perrad. > > When `io.close()` is called without arguments on already closed default an an > output the error message is `LJ_ERR_IOSTDCL` ("standard file is closed”) 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. > > This patch adds the corresponding check and code branch for this corner a > 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 >
next prev parent reply other threads:[~2022-07-13 11:59 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-18 8:58 [Tarantool-patches] [PATCH luajit 0/2] Fix io.close() Sergey Kaplun via Tarantool-patches 2022-05-18 8:58 ` [Tarantool-patches] [PATCH luajit 1/2] " Sergey Kaplun via Tarantool-patches 2022-07-13 11:58 ` sergos via Tarantool-patches 2022-07-14 8:04 ` Sergey Kaplun via Tarantool-patches 2022-05-18 8:58 ` [Tarantool-patches] [PATCH luajit 2/2] Fix io.close() error message Sergey Kaplun via Tarantool-patches 2022-07-13 11:58 ` sergos via Tarantool-patches [this message] 2022-07-14 7:54 ` Sergey Kaplun via Tarantool-patches 2022-07-13 11:58 ` [Tarantool-patches] [PATCH luajit 0/2] Fix io.close() sergos via Tarantool-patches 2022-07-13 17:45 ` Sergey Kaplun via Tarantool-patches 2022-11-23 7:50 ` Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=E3C3EE44-1FE7-49D9-9DE2-AA0B194747CC@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=sergos@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 2/2] Fix io.close() error message.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox