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 26B64469719 for ; Sat, 15 Feb 2020 21:08:48 +0300 (MSK) From: Vladislav Shpilevoy Date: Sat, 15 Feb 2020 19:08:44 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/2] tuple: hide internal functions from box.tuple.* 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 box.tuple.bless, .encode, and .is are internal. Their behaviour is not documented, and they may omit some checks for the sake of speed, and can crash if used without thinking. Nonetheless, despite they are not documented, curious users could notice them in box.tuple.* output via autocompletion, for example. And they could try to use them. This is not ok. box.tuple.bless() being called by a user leads either to a crash, or to a leak (because it is basically tuple reference counter increment). box.tuple.encode() is kind of a wrapper around msgpack, and users should not touch it. It may change, may be removed. And is just makes no sense except some rare cases in schema.lua. bless() and encode() were used in schema.lua only, so the patch simply moves them to box.internal.tuple. box.tuple.is() is kept as is, because - this is used in the tests a lot; - it is totally safe; - that function actually makes sense, and some users could have already started using it. There is no a test, since nothing to test - bless() is not available for users anymore (assuming no one is brave enough to rely on box.internal). Closes #4684 --- src/box/lua/schema.lua | 4 ++-- src/box/lua/tuple.lua | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 50c96a335..0d28edbe6 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -17,8 +17,8 @@ end local builtin = ffi.C -- performance fixup for hot functions -local tuple_encode = box.tuple.encode -local tuple_bless = box.tuple.bless +local tuple_encode = box.internal.tuple.encode +local tuple_bless = box.internal.tuple.bless local is_tuple = box.tuple.is assert(tuple_encode ~= nil and tuple_bless ~= nil and is_tuple ~= nil) diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index a25a28987..eb3946a0f 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -342,7 +342,17 @@ ffi.metatype(tuple_iterator_t, { __tostring = function(it) return "" end; }) +-- Free methods, which are not needed anymore. +internal.tuple.slice = nil +internal.tuple.transform = nil +internal.tuple.tuple_to_map = nil +internal.tuple.tostring = nil + -- internal api for box.select and iterators -box.tuple.bless = tuple_bless -box.tuple.encode = tuple_encode +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. box.tuple.is = is_tuple -- 2.21.1 (Apple Git-122.3)