From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (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 DB3424696C4 for ; Sat, 15 Feb 2020 21:08:48 +0300 (MSK) From: Vladislav Shpilevoy Date: Sat, 15 Feb 2020 19:08:45 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/2] tuple: make box.tuple.is() public List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, babinoleg@mail.ru, alexander.turenko@tarantool.org, imun@tarantool.org In #4684 it was found that box.tuple.* contained some private functions: bless(), encode(), and is(). Bless() and encode() didn't make any sense for a user, so they were hidden into box.internal.tuple.*. But box.tuple.is() is actually a useful thing. It is harnessed in the tests a lot, and is likely to be already used by customers, because it is available in box.tuple.* for a long time. It is a matter of time when someone will open a doc ticket saying that box.tuple.is() is not documented. So the patch makes it legally public. Follow-up #4684 @TarantoolBot document Title: box.tuple.is() A function to check whether a given object is a tuple cdata object. Returns true or false. Never raises nor returns an error. --- src/box/lua/tuple.lua | 7 ++++--- test/box/tuple.result | 40 ++++++++++++++++++++++++++++++++++++++++ test/box/tuple.test.lua | 14 ++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index eb3946a0f..f97aa1579 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -352,7 +352,8 @@ internal.tuple.tostring = nil internal.tuple.bless = tuple_bless internal.tuple.encode = tuple_encode --- The function is internal in a sense that it is not documented. --- But it is safe and widely used in the tests. Keep it here at --- least for test code. +-- Public API, additional to implemented in C. + +-- is() is implemented in Lua, because then it is +-- easy to be JITed. box.tuple.is = is_tuple diff --git a/test/box/tuple.result b/test/box/tuple.result index 78f919deb..a499aa43a 100644 --- a/test/box/tuple.result +++ b/test/box/tuple.result @@ -1450,6 +1450,46 @@ level == max_depth + 5 or {level, max_depth} --- - true ... +-- gh-4684: some box.tuple.* methods were private and could be +-- used by customers to shoot in their own legs. Some of them +-- were moved to a more secret place. box.tuple.is() was moved to +-- the public API, legally. +box.tuple.is() +--- +- false +... +box.tuple.is(nil) +--- +- false +... +box.tuple.is(box.NULL) +--- +- false +... +box.tuple.is({}) +--- +- false +... +box.tuple.is(ffi.new('char[1]')) +--- +- false +... +box.tuple.is(1) +--- +- false +... +box.tuple.is('1') +--- +- false +... +box.tuple.is(box.tuple.new()) +--- +- true +... +box.tuple.is(box.tuple.new({1})) +--- +- true +... msgpack.cfg({encode_max_depth = max_depth, encode_deep_as_nil = deep_as_nil}) --- ... diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua index baf2f22d5..b83fca5cd 100644 --- a/test/box/tuple.test.lua +++ b/test/box/tuple.test.lua @@ -496,4 +496,18 @@ while tuple ~= nil do level = level + 1 tuple = tuple[1] end -- serializer allows deeper tables. level == max_depth + 5 or {level, max_depth} +-- gh-4684: some box.tuple.* methods were private and could be +-- used by customers to shoot in their own legs. Some of them +-- were moved to a more secret place. box.tuple.is() was moved to +-- the public API, legally. +box.tuple.is() +box.tuple.is(nil) +box.tuple.is(box.NULL) +box.tuple.is({}) +box.tuple.is(ffi.new('char[1]')) +box.tuple.is(1) +box.tuple.is('1') +box.tuple.is(box.tuple.new()) +box.tuple.is(box.tuple.new({1})) + msgpack.cfg({encode_max_depth = max_depth, encode_deep_as_nil = deep_as_nil}) -- 2.21.1 (Apple Git-122.3)