Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 luajit 16/30] test: adapt PUC Lua test for %q in fmt for LuaJIT
Date: Thu, 8 Apr 2021 11:51:52 +0300	[thread overview]
Message-ID: <YG7EKCG0aXV9LG0V@root> (raw)
In-Reply-To: <20210407163113.GO29703@tarantool.org>

Igor,

On 07.04.21, Igor Munkin wrote:
> Sergey,
> 
> On 07.04.21, Sergey Kaplun wrote:
> > Igor,
> > 
> 
> <snipped>
> 
> > > > > > string.format(): %q reversible.
> > > > > > See also https://luajit.org/extensions.html#lua52.
> > > > > > 
> > > > > > In Lua 5.1 string.format() does not accept string values containing
> > > > > > embedded zeros, except as arguments to the '%q' option.
> > > > > > In Lua 5.2 '\0' is not handled differently from other
> > > > > > control chars in string.format('%q', ...).
> > > > > > See commit 7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d
> > > > > > (string.format("%q", str) is now fully reversible
> > > > > > (from Lua 5.2).).
> > > > > 
> > > > > Well, I honestly don't understand what is changed in *semantics*. I've
> > > > > tried the following command with Lua 5.2, Lua 5.1 and LuaJIT 2.0.5 as an
> > > > > interpreter being tested
> > > > > | <interp> -e 'print(string.format("%q", "\0"))'
> > > > > 
> > > > > I understand the semantics of "%q", but was it just a bug in Lua 5.1?
> > > > 
> > > > A bug with the test for it???
> > > 
> > > Well, I can remind you the bug with <tonumber> we fixed the last year.
> > > There might be no test for it though, but all in all it has not been
> > > fixed in Lua 5.1.
> > 
> > I mean that this behaviour is verificated by the test. When behaviour is
> > changed the test is changed too.
> > 
> > > 
> > > > 
> > > > > What does "fully reversible" mean in this context?
> > > 
> > > This question is left unaddressed.
> > 
> > I don't know what does Mike mean by these.
> 
> Then it would be great to describe the changes on your own. I can hardly
> split the comment into yours words and ones taked from Lua Reference
> manual or git log, but you are writing that "In Lua 5.2 '\0' is not
> handled differently from other control chars". Could you please clarify
> the difference you are talking about? Or provide the links describing
> it? May be some parts from PIL?
> 
> > 
> > > 
> > > > > 
> > > > > I understand only the fact the behaviour differs and you reimplemented
> > > > > the test assertion according to Lua 5.2 testing suite. That's all.
> > > > > 
> > > > > I found not a single word regarding this issue in Lua bugs[1] page,
> > > > > except invalid handling of \r[2]. Is there any issue/page with a more
> > > > 
> > > > It looks unrelated to these changes.
> > > > 
> > > > > verbose explanation what has been changed in 7cc981c?
> > > > 
> > > > I just read these lines in Lua 5.1 reference manual :):
> > > > | This function does not accept string values containing embedded
> > > > | zeros, except as arguments to the q option.
> > > 
> > > So what? This means literally nothing to me... BTW, I can pass such
> > > string to the function and it can yield any bullshit the developer
> > > wanted to. That's why we decided to comment such places in a clear and
> > > verbose way, didn't we?
> > 
> > Don't get you point here. AFAIU it means that `%q` is the only one
> > option that can contain embeded zeros, so it handles it in the special
> > way.
> 
> My point relates to the fact, nobody except you can understand the
> comment near the change. Hence one need to make the similar
> investigation you made. Then what is the sense of commenting the changes
> in suite?
> 
> > 
> > > 
> > > > 
> > > > As for me, it is just new behaviour of Lua 5.2 -- patterns now accept
> > > > '\0' as a reqular character (see
> > > > 4541243355a299a9b75042d207feb87295872c3a (patterns now accept '\0' as a
> > > > regular character) from Lua repository). So, according to commit
> > > > 658ea8752b979102627e2fede7b7ddfbb67ba6c9 (no need to handle '\0'
> > > > differently from other control chars in format '%q')) from Lua
> > > > repository, this behaviour is excess.
> > > > 
> > > > Also, it is mentioned here [2].
> > > 
> > > I see nothing regarding this change there.
> > 
> > I am talking about this part:
> > 
> > | Character class %z in patterns is deprecated, as now patterns may
> > | contain '\0' as a regular character.
> 
> Patterns, not options, right?
> 
> > 
> 
> <snipped>

I haven't found no more verbose descriptions about %q specifier
neither in the PIL, nor in the Lua Reference Manual, nor in the Lua
mailing list, nor in the LuaJIT mailing list.
So, I am appealing to the commits in the Lua repository.

Going back to the definition of specifier %q from Lua 5.1 Reference
manual:
| The q option formats a string in a form suitable to be safely read
| back by the Lua interpreter: ...

Answering your previous question -- "reversible" means (in my
understanding now) that `string.format("% q", binary)` should return
the same-looking `binary` string that was presented to the
interpreter and `string.format()` first (perhaps, it can expand
control characters like '\r', '\n', and turn symbol "\65" into "A").
This is why I was referencing zero-bytes in patterns (unfortunately,
wrongly).

Historically, in Lua 5.2, control characters are written as \nnn
when needed, see d62a21b9d379a576bae7426c80039ca1a4d2bb07 ("when
formatting with '%q', all control characters are coded as \nnn.") [1].
In this patch, %q specifier starts writing control characters
to a new string in the same way through \n, instead of their binary
representation as it is. If the control character is followed by a
digit, then for the correct work of the parser, it is necessary to
extend the escape sequence to 3 significant characters (otherwise,
the transition "\0002" -> "\02" corrupts string).
For this patch, the expansion is performed unconditionally (the check
for the next symbol is not performed) if this first symbol is a zero
byte. You may notice that the additional check for '\0' is
unnecessary - if after it comes a digit, then a branch with expanding
the format to 3 significant characters will be selected. Consistent
work with the zero byte processing was added in the commit
658ea8752b979102627e2fede7b7ddfbb67ba6c9 ("no need to handle '\0'
differently from other control chars in format '%q'") [2]. Note that
this patch does not change the semantics of %q specifier - the new
string can still be "safely read back by the Lua interpreter".

As we know, in Lua 5.1, '\0' was converted to "\000" unconditionally.
This was partly done to avoid unnecessary logic, as I suppose, since
before the d62a21b commit, all other characters were transmitted
as-is in the new string, and there was no inconsistency.

Is it worth mentioning the first commit clarifying the cause of the
inconsistency, because it does not directly relate to changes? The
initial comment, in my opinion, reflects the reason for the failing
test -- '\0' began to be processed in the same way as other
controlled characters in Lua 5.2. LuaJIT has adopted this practice in
a related commit. The curious reader can independently search the
commit history for these changes. Please let me know, if you think
these clarifications are necessary to describe the problem.

> 
> > > > > [1]: https://www.lua.org/bugs.html#5.1
> > > > > [2]: https://www.lua.org/bugs.html#5.1-4
> > > > > 
> > > > > -- 
> > > > > Best regards,
> > > > > IM
> > > > 
> > > > [1]: https://www.lua.org/manual/5.1/manual.html#pdf-string.format
> > > > [2]: https://www.lua.org/manual/5.2/manual.html#8.2
> 
> <snipped>
> 
> > 
> > -- 
> > Best regards,
> > Sergey Kaplun
> 
> -- 
> Best regards,
> IM

[1]: https://github.com/lua/lua/commit/d62a21b9d379a576bae7426c80039ca1a4d2bb07
[2]: https://github.com/lua/lua/commit/658ea8752b979102627e2fede7b7ddfbb67ba6c9

-- 
Best regards,
Sergey Kaplun

  reply	other threads:[~2021-04-08  8:52 UTC|newest]

Thread overview: 153+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26  7:42 [Tarantool-patches] [PATCH v2 luajit 00/30] Adapt PUC-Rio Lua 5.1 test suite Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 01/30] test: add " Sergey Kaplun via Tarantool-patches
2021-03-26 10:14   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:13   ` Igor Munkin via Tarantool-patches
2021-04-01  8:11     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 02/30] test: add compiling for C libs from PUC-Rio-Lua5.1 Sergey Kaplun via Tarantool-patches
2021-03-26 11:01   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:14   ` Igor Munkin via Tarantool-patches
2021-04-01  8:21     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 03/30] test: adapt Lua 5.1 suite for out-of-source build Sergey Kaplun via Tarantool-patches
2021-03-26 11:07   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 14:25     ` Sergey Kaplun via Tarantool-patches
2021-03-31 22:58       ` Igor Munkin via Tarantool-patches
2021-04-01  8:43         ` Sergey Kaplun via Tarantool-patches
2021-03-31 22:58   ` Igor Munkin via Tarantool-patches
2021-04-01  8:40     ` Sergey Kaplun via Tarantool-patches
2021-04-06 16:56       ` Igor Munkin via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 04/30] test: remove quotes in progname from <main.lua> Sergey Kaplun via Tarantool-patches
2021-03-26 11:12   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 22:58   ` Igor Munkin via Tarantool-patches
2021-04-01  8:50     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 05/30] test: adapt arg availability test from Lua suite Sergey Kaplun via Tarantool-patches
2021-03-26 11:22   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 22:58   ` Igor Munkin via Tarantool-patches
2021-04-01  9:37     ` Sergey Kaplun via Tarantool-patches
2021-04-06 15:24       ` Igor Munkin via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 06/30] test: disable PUC Lua tests confused by -v output Sergey Kaplun via Tarantool-patches
2021-03-26 11:26   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 14:31     ` Sergey Kaplun via Tarantool-patches
2021-03-31 22:58   ` Igor Munkin via Tarantool-patches
2021-04-01  9:56     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 07/30] test: disable Lua tests for bytecode with header Sergey Kaplun via Tarantool-patches
2021-03-26 11:30   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 22:59   ` Igor Munkin via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 08/30] test: disable JIT for GC step counting tests Sergey Kaplun via Tarantool-patches
2021-03-26 11:32   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:14   ` Igor Munkin via Tarantool-patches
2021-04-01 10:10     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 09/30] test: disable Lua suite tests for line hook Sergey Kaplun via Tarantool-patches
2021-03-26 11:35   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 14:33     ` Sergey Kaplun via Tarantool-patches
2021-03-31 22:59   ` Igor Munkin via Tarantool-patches
2021-04-01 10:06     ` Sergey Kaplun via Tarantool-patches
2021-04-06 19:45       ` Igor Munkin via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 10/30] test: adapt test for debug.setlocal in Lua suite Sergey Kaplun via Tarantool-patches
2021-03-26 11:44   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 14:45     ` Sergey Kaplun via Tarantool-patches
2021-03-30 22:14   ` Igor Munkin via Tarantool-patches
2021-04-01 10:16     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 11/30] test: adapt getlocal PUC test for vararg func Sergey Kaplun via Tarantool-patches
2021-03-26 11:47   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 14:52     ` Sergey Kaplun via Tarantool-patches
2021-03-30 22:15   ` Igor Munkin via Tarantool-patches
2021-04-01 11:37     ` Sergey Kaplun via Tarantool-patches
2021-04-06 20:09       ` Igor Munkin via Tarantool-patches
2021-04-06 20:40         ` Igor Munkin via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 12/30] test: adapt PUC Lua test with count hooks Sergey Kaplun via Tarantool-patches
2021-03-26 11:49   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:15   ` Igor Munkin via Tarantool-patches
2021-04-01 11:42     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 13/30] test: disable PUC Lua test for tail call info Sergey Kaplun via Tarantool-patches
2021-03-26 14:43   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:15   ` Igor Munkin via Tarantool-patches
2021-04-01 11:52     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 14/30] test: adapt activeline check in the PUC Lua test Sergey Kaplun via Tarantool-patches
2021-03-26 14:50   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:15   ` Igor Munkin via Tarantool-patches
2021-04-01 11:58     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 15/30] test: disable PUC-Lua test for per-coroutine hooks Sergey Kaplun via Tarantool-patches
2021-03-26 14:54   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:16   ` Igor Munkin via Tarantool-patches
2021-04-01 12:03     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:42 ` [Tarantool-patches] [PATCH v2 luajit 16/30] test: adapt PUC Lua test for %q in fmt for LuaJIT Sergey Kaplun via Tarantool-patches
2021-03-26 14:56   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:16   ` Igor Munkin via Tarantool-patches
2021-04-01 12:33     ` Sergey Kaplun via Tarantool-patches
2021-04-06 21:37       ` Igor Munkin via Tarantool-patches
2021-04-07 15:50         ` Sergey Kaplun via Tarantool-patches
2021-04-07 16:31           ` Igor Munkin via Tarantool-patches
2021-04-08  8:51             ` Sergey Kaplun via Tarantool-patches [this message]
2021-04-12 10:26               ` Igor Munkin via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 17/30] test: disable locale-depended tests for Lua suite Sergey Kaplun via Tarantool-patches
2021-03-26 14:58   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:16   ` Igor Munkin via Tarantool-patches
2021-04-01 19:12     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 18/30] test: replace math.mod to math.fmod for Lua tests Sergey Kaplun via Tarantool-patches
2021-03-26 15:12   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:17     ` Igor Munkin via Tarantool-patches
2021-03-26 15:16   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:16   ` Igor Munkin via Tarantool-patches
2021-04-01 19:36     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 19/30] test: remove assert for string.gfind check Sergey Kaplun via Tarantool-patches
2021-03-26 15:14   ` Sergey Ostanevich via Tarantool-patches
2021-03-30 22:17   ` Igor Munkin via Tarantool-patches
2021-04-02  7:05     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 20/30] test: adapt PUC Lua test for args in vararg func Sergey Kaplun via Tarantool-patches
2021-03-26 14:54   ` Sergey Kaplun via Tarantool-patches
2021-03-26 15:22     ` Sergey Ostanevich via Tarantool-patches
2021-03-31  9:51   ` Igor Munkin via Tarantool-patches
2021-04-02  7:21     ` Sergey Kaplun via Tarantool-patches
2021-04-06 20:45       ` Igor Munkin via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 21/30] test: disable test for getfenv in closure tailcall Sergey Kaplun via Tarantool-patches
2021-03-26 15:41   ` Sergey Ostanevich via Tarantool-patches
2021-03-31  9:51   ` Igor Munkin via Tarantool-patches
2021-04-02  7:40     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 22/30] test: disable PUC Lua test for var names in error Sergey Kaplun via Tarantool-patches
2021-03-26 15:44   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 16:01     ` Sergey Kaplun via Tarantool-patches
2021-03-31 19:23   ` Igor Munkin via Tarantool-patches
2021-04-02  7:48     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 23/30] test: disable PUC Lua test for fast function name Sergey Kaplun via Tarantool-patches
2021-03-26 15:45   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:23   ` Igor Munkin via Tarantool-patches
2021-04-02  8:14     ` Sergey Kaplun via Tarantool-patches
2021-04-06 21:37       ` Igor Munkin via Tarantool-patches
2021-04-07 16:06         ` Sergey Kaplun via Tarantool-patches
2021-04-07 16:11           ` Igor Munkin via Tarantool-patches
2021-04-07 19:57             ` Sergey Kaplun via Tarantool-patches
2021-04-12  9:36               ` Igor Munkin via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 24/30] test: disable PUC Lua test for non-asci identifier Sergey Kaplun via Tarantool-patches
2021-03-26 15:46   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:23   ` Igor Munkin via Tarantool-patches
2021-04-02  8:20     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 25/30] test: disable PUC Lua error test for syntax level Sergey Kaplun via Tarantool-patches
2021-03-26 15:52   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:24   ` Igor Munkin via Tarantool-patches
2021-04-02  8:30     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 26/30] test: disable tests with multiple -l options Sergey Kaplun via Tarantool-patches
2021-03-26 15:56   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:24   ` Igor Munkin via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 27/30] test: disable PUC Lua test for checking arg layout Sergey Kaplun via Tarantool-patches
2021-03-26 15:58   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:24   ` Igor Munkin via Tarantool-patches
2021-04-02  8:35     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 28/30] test: disable PUC Lua test checking -h option Sergey Kaplun via Tarantool-patches
2021-03-26 15:58   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:24   ` Igor Munkin via Tarantool-patches
2021-04-02  8:39     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 29/30] test: disable PUC Lua hanging GC test Sergey Kaplun via Tarantool-patches
2021-03-26 16:03   ` Sergey Ostanevich via Tarantool-patches
2021-03-31 19:24     ` Igor Munkin via Tarantool-patches
2021-03-31 19:24   ` Igor Munkin via Tarantool-patches
2021-04-02  8:45     ` Sergey Kaplun via Tarantool-patches
2021-03-26  7:43 ` [Tarantool-patches] [PATCH v2 luajit 30/30] test: disable too depth recursive PUC Lua test Sergey Kaplun via Tarantool-patches
2021-03-26 16:28   ` Sergey Ostanevich via Tarantool-patches
2021-03-26 16:45     ` Sergey Kaplun via Tarantool-patches
2021-03-31 19:24   ` Igor Munkin via Tarantool-patches
2021-04-02  8:47     ` Sergey Kaplun via Tarantool-patches
2021-03-26 11:09 ` [Tarantool-patches] [PATCH v2 luajit 00/30] Adapt PUC-Rio Lua 5.1 test suite Sergey Ostanevich via Tarantool-patches
2021-03-26 14:12   ` Sergey Kaplun via Tarantool-patches
2021-03-30 22:17 ` Igor Munkin via Tarantool-patches
2021-03-31  9:41   ` Sergey Kaplun via Tarantool-patches
2021-03-31 10:49     ` 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=YG7EKCG0aXV9LG0V@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 luajit 16/30] test: adapt PUC Lua test for %q in fmt for LuaJIT' \
    /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