From: Oleg Babin <olegrok@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 1/2] uuid: support comparison of uuid values in Lua
Date: Tue, 24 Nov 2020 08:57:17 +0300 [thread overview]
Message-ID: <7e7582d6-6b55-4051-a640-880008e839d3@tarantool.org> (raw)
In-Reply-To: <c6ba37d8-3189-48c6-5f88-eb5a9c4ab80f@tarantool.org>
Hi! Thanks for comments!
On 24/11/2020 00:58, Vladislav Shpilevoy wrote:
> Hi! Thanks for the fixes!
>
>> diff --git a/src/lua/uuid.lua b/src/lua/uuid.lua
>> index 08991cfeb..275f4e5c5 100644
>> --- a/src/lua/uuid.lua
>> +++ b/src/lua/uuid.lua
>> @@ -93,13 +93,20 @@ local uuid_isnil = function(uu)
>> return builtin.tt_uuid_is_nil(uu)
>> end
>>
>> +local check_uuid = function(value, index)
>> + if is_uuid(value) then
>> + return value
>> + end
>> +
>> + local err_fmt = 'incorrect value to compare with uuid as %d argument'
>> + error(err_fmt:format(index), 4)
>> +end
>> +
>> local uuid_eq = function(lhs, rhs)
>> if not is_uuid(rhs) then
>> return false
>> end
>> - if not is_uuid(lhs) then
>> - return error('Usage: uuid == var')
>> - end
>> + lhs = check_uuid(lhs, 1)
> Check_uuid() here uses incorrect error index. check_uuid()
> raises error(..., 4). So check_uuid() itself is level 1.
> uuid_eq() is level 2. And the calling code is level 3. You
> will raise one level beyond the caller code.
>
> For uuid_lt and uuid_le it works, because check_uuid() is
> level 1, uuid_cmp() is level 2, uuid_lt/le() is level 3, and
> the calling code is level 4.
Good catch! Thanks. Fixed in the following way:
diff --git a/src/lua/uuid.lua b/src/lua/uuid.lua
index 275f4e5c5..1171dfcc4 100644
--- a/src/lua/uuid.lua
+++ b/src/lua/uuid.lua
@@ -93,20 +93,20 @@ local uuid_isnil = function(uu)
return builtin.tt_uuid_is_nil(uu)
end
-local check_uuid = function(value, index)
+local check_uuid = function(value, index, err_lvl)
if is_uuid(value) then
return value
end
local err_fmt = 'incorrect value to compare with uuid as %d argument'
- error(err_fmt:format(index), 4)
+ error(err_fmt:format(index), err_lvl)
end
local uuid_eq = function(lhs, rhs)
if not is_uuid(rhs) then
return false
end
- lhs = check_uuid(lhs, 1)
+ lhs = check_uuid(lhs, 1, 3)
return builtin.tt_uuid_is_equal(lhs, rhs)
end
@@ -128,8 +128,8 @@ local uuid_new_str = function()
end
local uuid_cmp = function(lhs, rhs)
- lhs = check_uuid(lhs, 1)
- rhs = check_uuid(rhs, 2)
+ lhs = check_uuid(lhs, 1, 4)
+ rhs = check_uuid(rhs, 2, 4)
return builtin.tt_uuid_compare(lhs, rhs)
end
local uuid_lt = function(lhs, rhs)
> But I can't give you a test, since I have no idea how to provide
> lhs with non-uuid type. Igor said we can give metatable of uuid to
> some non-uuid value, but I failed to assign uuid metatable to
> anything else.
It's possible but I don't think it's really needed. I put small snippet
below:
uuid = require('uuid')
eq = debug.getmetatable(uuid()).__eq
eq('', uuid()) -- error: incorrect value to compare with uuid as 1 argument
proxy = newproxy()
debug.setmetatable(proxy, {__eq = eq})
proxy == uuid() -- error: '[string "return proxy == uuid()"]:1:
incorrect value to compare with uuid as 1 argument'
I can add it to our test suite but it looks really strange
> After you fix this (but I don't insist on adding a test, because
> I don't know how), I suggest you to get a second review from Igor.
Ok. I add Igor to CC.
Igor, could you provide the second review?
next prev parent reply other threads:[~2020-11-24 5:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 7:56 [Tarantool-patches] [PATCH v2 0/2] Make uuid values comparable olegrok
2020-11-18 7:56 ` [Tarantool-patches] [PATCH v2 1/2] uuid: support comparison of uuid values in Lua olegrok
2020-11-21 15:17 ` Vladislav Shpilevoy
2020-11-21 19:07 ` Oleg Babin
2020-11-23 21:58 ` Vladislav Shpilevoy
2020-11-24 5:57 ` Oleg Babin [this message]
2020-11-24 13:06 ` Igor Munkin
2020-11-27 15:17 ` Oleg Babin
2020-11-24 15:20 ` Igor Munkin
2020-11-24 19:23 ` Oleg Babin
2020-11-18 7:56 ` [Tarantool-patches] [PATCH v2 2/2] uuid: support uuid comparison with strings olegrok
2020-11-21 15:17 ` Vladislav Shpilevoy
2020-11-21 19:07 ` Oleg Babin
2020-11-24 15:20 ` Igor Munkin
2020-11-24 19:23 ` Oleg Babin
2020-11-18 8:02 ` [Tarantool-patches] [PATCH v2 0/2] Make uuid values comparable Oleg Babin
2020-11-27 22:39 ` Vladislav Shpilevoy
2020-11-27 22:40 ` Vladislav Shpilevoy
2020-12-04 8:13 ` Oleg Babin
2020-12-07 23:04 ` Alexander V. Tikhonov
2020-12-07 23:24 ` Vladislav Shpilevoy
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=7e7582d6-6b55-4051-a640-880008e839d3@tarantool.org \
--to=olegrok@tarantool.org \
--cc=imun@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2 1/2] uuid: support comparison of uuid values in Lua' \
/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