[Tarantool-patches] [PATCH v6 05/25] Fix luacheck warnings in src/lua/
sergeyb at tarantool.org
sergeyb at tarantool.org
Fri May 29 18:09:02 MSK 2020
From: Sergey Bronnikov <sergeyb at tarantool.org>
Part of #4681
Reviewed-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Reviewed-by: Igor Munkin <imun at tarantool.org>
Co-authored-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Co-authored-by: Igor Munkin <imun at tarantool.org>
---
.luacheckrc | 4 +++
src/lua/argparse.lua | 6 ++--
src/lua/buffer.lua | 4 +--
src/lua/clock.lua | 2 +-
src/lua/crypto.lua | 4 +--
src/lua/csv.lua | 5 ++-
src/lua/digest.lua | 2 +-
src/lua/env.lua | 2 +-
src/lua/fiber.lua | 4 +--
src/lua/fio.lua | 37 +++++++++++----------
src/lua/help.lua | 7 ++--
src/lua/httpc.lua | 3 --
src/lua/init.lua | 7 ++--
src/lua/msgpackffi.lua | 22 +++++--------
src/lua/socket.lua | 65 ++++++++++++++++++-------------------
src/lua/string.lua | 1 -
src/lua/swim.lua | 10 +++---
src/lua/tap.lua | 74 ++++++++++++++++++++----------------------
src/lua/trigger.lua | 3 --
19 files changed, 124 insertions(+), 138 deletions(-)
diff --git a/.luacheckrc b/.luacheckrc
index e10d73476..4d95f2729 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -28,3 +28,7 @@ files["extra/dist/tarantoolctl.in"] = {
globals = {"box", "_TARANTOOL"},
ignore = {"212/self", "122", "431"}
}
+files["src/lua/*.lua"] = {ignore = {"212/self"}}
+files["src/lua/help.lua"] = {globals = {"help", "tutorial"}}
+files["src/lua/init.lua"] = {globals = {"dostring", "os", "package"}}
+files["src/lua/swim.lua"] = {ignore = {"431"}}
diff --git a/src/lua/argparse.lua b/src/lua/argparse.lua
index faa0ae130..3cde005ea 100644
--- a/src/lua/argparse.lua
+++ b/src/lua/argparse.lua
@@ -90,8 +90,8 @@ local function convert_parameter(name, convert_from, convert_to)
return convert_from
end
-local function parameters_parse(t_in, options)
- local t_out, t_in = {}, t_in or {}
+local function parameters_parse(param, options)
+ local t_out, t_in = {}, param or {}
-- Prepare a lookup table for options. An option name -> a
-- type name to convert a parameter into or true (which means
@@ -145,7 +145,7 @@ local function parameters_parse(t_in, options)
if parameter_has_value(lookup[command]) then
-- in case next argument is value of this key (not --arg)
local next_arg = t_in[i + 1]
- local is_long, is_short, is_dash = parse_param_prefix(next_arg)
+ is_long, is_short, is_dash = parse_param_prefix(next_arg)
if is_dash then
skip_param = true
elseif is_long == false and not is_short and not is_dash then
diff --git a/src/lua/buffer.lua b/src/lua/buffer.lua
index 9aac82b39..43c7e1170 100644
--- a/src/lua/buffer.lua
+++ b/src/lua/buffer.lua
@@ -182,7 +182,7 @@ local ibuf_methods = {
unused = ibuf_unused;
}
-local function ibuf_tostring(ibuf)
+local function ibuf_tostring()
return '<ibuf>'
end
local ibuf_mt = {
@@ -193,7 +193,7 @@ local ibuf_mt = {
ffi.metatype(ibuf_t, ibuf_mt);
-local function ibuf_new(arg, arg2)
+local function ibuf_new(arg)
local buf = ffi.new(ibuf_t)
local slabc = builtin.tarantool_lua_slab_cache()
builtin.ibuf_create(buf, slabc, READAHEAD)
diff --git a/src/lua/clock.lua b/src/lua/clock.lua
index 60c78663c..fee43ccde 100644
--- a/src/lua/clock.lua
+++ b/src/lua/clock.lua
@@ -33,7 +33,7 @@ clock.bench = function(fun, ...)
overhead = clock.proc() - overhead
local start_time = clock.proc()
local res = {0, fun(...)}
- res[1] = clock.proc() - start_time - overhead, res
+ res[1] = clock.proc() - start_time - overhead
return res
end
diff --git a/src/lua/crypto.lua b/src/lua/crypto.lua
index bf3064c70..c0eb0d303 100644
--- a/src/lua/crypto.lua
+++ b/src/lua/crypto.lua
@@ -75,7 +75,7 @@ local function openssl_err_str()
end
local digests = {}
-for class, name in pairs({
+for class, _ in pairs({
md2 = 'MD2', md4 = 'MD4', md5 = 'MD5',
sha1 = 'SHA1', sha224 = 'SHA224',
sha256 = 'SHA256', sha384 = 'SHA384', sha512 = 'SHA512',
@@ -428,7 +428,7 @@ local public_methods = {
}
local module_mt = {
- __serialize = function(s)
+ __serialize = function()
return public_methods
end,
__index = public_methods
diff --git a/src/lua/csv.lua b/src/lua/csv.lua
index 7dff2f213..de6726bb7 100644
--- a/src/lua/csv.lua
+++ b/src/lua/csv.lua
@@ -188,10 +188,10 @@ module.dump = function(t, opts, writable)
if type(writable) == 'nil' then
result_table = {}
end
- for k, line in pairs(t) do
+ for _, line in pairs(t) do
local first = true
local output_tuple = {}
- for k2, field in pairs(line) do
+ for _, field in pairs(line) do
local strf = tostring(field)
local buf_new_size = (strf:len() + 1) * 2
if buf_new_size > bufsz then
@@ -214,7 +214,6 @@ module.dump = function(t, opts, writable)
else
writable:write(table.concat(output_tuple))
end
- output_tuple = {}
end
ffi.C.csv_destroy(csv)
csv.realloc(buf, 0)
diff --git a/src/lua/digest.lua b/src/lua/digest.lua
index 6ed91cfa2..7f1aea8d0 100644
--- a/src/lua/digest.lua
+++ b/src/lua/digest.lua
@@ -246,7 +246,7 @@ local m = {
end
}
-for digest, name in pairs(digest_shortcuts) do
+for digest, _ in pairs(digest_shortcuts) do
m[digest] = function (str)
return crypto.digest[digest](str)
end
diff --git a/src/lua/env.lua b/src/lua/env.lua
index dd1616a84..a31b7098f 100644
--- a/src/lua/env.lua
+++ b/src/lua/env.lua
@@ -28,7 +28,7 @@ os.environ = function()
end
os.setenv = function(key, value)
- local rv = nil
+ local rv
if value ~= nil then
rv = ffi.C.setenv(key, value, 1)
else
diff --git a/src/lua/fiber.lua b/src/lua/fiber.lua
index 89c17f63d..b14117714 100644
--- a/src/lua/fiber.lua
+++ b/src/lua/fiber.lua
@@ -39,8 +39,8 @@ local stall = fiber.stall
fiber.stall = nil
local worker_next_task = nil
-local worker_last_task = nil
-local worker_fiber = nil
+local worker_last_task
+local worker_fiber
--
-- Worker is a singleton fiber for not urgent delayed execution of
diff --git a/src/lua/fio.lua b/src/lua/fio.lua
index 83fddaa0a..cf770c661 100644
--- a/src/lua/fio.lua
+++ b/src/lua/fio.lua
@@ -329,7 +329,7 @@ fio.abspath = function(path)
error("Usage: fio.abspath(path)")
end
path = path
- local joined_path = ''
+ local joined_path
local path_tab = {}
if string.sub(path, 1, 1) == '/' then
joined_path = path
@@ -366,7 +366,7 @@ fio.listdir = function(path)
return t
end
local names = string.split(str, "\n")
- for i, name in ipairs(names) do
+ for _, name in ipairs(names) do
table.insert(t, name)
end
return t
@@ -378,15 +378,15 @@ fio.mktree = function(path, mode)
end
path = fio.abspath(path)
- local path = string.gsub(path, '^/', '')
+ path = string.gsub(path, '^/', '')
local dirs = string.split(path, "/")
local current_dir = "/"
- for i, dir in ipairs(dirs) do
+ for _, dir in ipairs(dirs) do
current_dir = fio.pathjoin(current_dir, dir)
local stat = fio.stat(current_dir)
if stat == nil then
- local st, err = fio.mkdir(current_dir, mode)
+ local _, err = fio.mkdir(current_dir, mode)
-- fio.stat() and fio.mkdir() above are separate calls
-- and a file system may be changed between them. So
-- if the error here is due to an existing directory,
@@ -407,27 +407,27 @@ fio.rmtree = function(path)
if type(path) ~= 'string' then
error("Usage: fio.rmtree(path)")
end
- local status, err
path = fio.abspath(path)
local ls, err = fio.listdir(path)
if err ~= nil then
return nil, err
end
- for i, f in ipairs(ls) do
+ for _, f in ipairs(ls) do
local tmppath = fio.pathjoin(path, f)
local st = fio.lstat(tmppath)
if st then
if st:is_dir() then
- st, err = fio.rmtree(tmppath)
+ _, err = fio.rmtree(tmppath)
else
- st, err = fio.unlink(tmppath)
+ _, err = fio.unlink(tmppath)
end
if err ~= nil then
return nil, err
end
end
end
- status, err = fio.rmdir(path)
+ local _
+ _, err = fio.rmdir(path)
if err ~= nil then
return false, string.format("failed to remove %s: %s", path, err)
end
@@ -453,7 +453,7 @@ fio.copytree = function(from, to)
if type(from) ~= 'string' or type(to) ~= 'string' then
error('Usage: fio.copytree(from, to)')
end
- local status, reason
+ local reason, _
local st = fio.stat(from)
if not st then
return false, string.format("Directory %s does not exist", from)
@@ -467,32 +467,33 @@ fio.copytree = function(from, to)
end
-- create tree of destination
- status, reason = fio.mktree(to)
+ _, reason = fio.mktree(to)
if reason ~= nil then
return false, reason
end
- for i, f in ipairs(ls) do
+ for _, f in ipairs(ls) do
local ffrom = fio.pathjoin(from, f)
local fto = fio.pathjoin(to, f)
- local st = fio.lstat(ffrom)
+ st = fio.lstat(ffrom)
if st and st:is_dir() then
- status, reason = fio.copytree(ffrom, fto)
+ _, reason = fio.copytree(ffrom, fto)
if reason ~= nil then
return false, reason
end
end
if st:is_reg() then
- status, reason = fio.copyfile(ffrom, fto)
+ _, reason = fio.copyfile(ffrom, fto)
if reason ~= nil then
return false, reason
end
end
if st:is_link() then
- local link_to, reason = fio.readlink(ffrom)
+ local link_to
+ link_to, reason = fio.readlink(ffrom)
if reason ~= nil then
return false, reason
end
- status, reason = fio.symlink(link_to, fto)
+ _, reason = fio.symlink(link_to, fto)
if reason ~= nil then
return false, "can't create symlink in place of existing file "..fto
end
diff --git a/src/lua/help.lua b/src/lua/help.lua
index 54ff1b5d0..4f024832d 100644
--- a/src/lua/help.lua
+++ b/src/lua/help.lua
@@ -11,10 +11,7 @@ help = { doc.help }
tutorial = {}
tutorial[1] = help[1]
-local help_function_data = {};
-local help_object_data = {}
-
-local function help_call(table, param)
+local function help_call()
return help
end
@@ -22,7 +19,7 @@ setmetatable(help, { __call = help_call })
local screen_id = 1;
-local function tutorial_call(table, action)
+local function tutorial_call(self, action)
if action == 'start' then
screen_id = 1;
elseif action == 'next' or action == 'more' then
diff --git a/src/lua/httpc.lua b/src/lua/httpc.lua
index 6381c6a1a..9336dcee0 100644
--- a/src/lua/httpc.lua
+++ b/src/lua/httpc.lua
@@ -29,8 +29,6 @@
-- SUCH DAMAGE.
--
-local fiber = require('fiber')
-
local driver = package.loaded.http.client
package.loaded.http = nil
@@ -112,7 +110,6 @@ local special_characters = {
[']'] = true,
['<'] = true,
['>'] = true,
- ['>'] = true,
['@'] = true,
[','] = true,
[';'] = true,
diff --git a/src/lua/init.lua b/src/lua/init.lua
index ff3e74c3c..a831549d1 100644
--- a/src/lua/init.lua
+++ b/src/lua/init.lua
@@ -144,9 +144,9 @@ local function gen_search_func(path_fn, templates, need_traverse)
local searchpaths = {}
- for _, path in ipairs(paths) do
+ for _, p in ipairs(paths) do
for _, template in pairs(templates) do
- table.insert(searchpaths, fio.pathjoin(path, template))
+ table.insert(searchpaths, fio.pathjoin(p, template))
end
end
@@ -176,7 +176,8 @@ local function gen_loader_func(search_fn, load_fn)
if not file then
return err
end
- local loaded, err = load_fn(file, name)
+ local loaded
+ loaded, err = load_fn(file, name)
if err == nil then
return loaded
else
diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua
index f01ffaef0..793f47854 100644
--- a/src/lua/msgpackffi.lua
+++ b/src/lua/msgpackffi.lua
@@ -302,10 +302,6 @@ local function encode(obj)
return r
end
-local function encode_ibuf(obj, ibuf)
- encode_r(ibuf, obj, 0)
-end
-
on_encode(ffi.typeof('uint8_t'), encode_int)
on_encode(ffi.typeof('uint16_t'), encode_int)
on_encode(ffi.typeof('uint32_t'), encode_int)
@@ -332,7 +328,6 @@ local decode_r
-- See similar constants in utils.cc
local DBL_INT_MAX = 1e14 - 1
-local DBL_INT_MIN = -1e14 + 1
local function decode_u8(data)
local num = ffi.cast(uint8_ptr_t, data[0])[0]
@@ -477,8 +472,7 @@ end
local function decode_array(data, size)
assert (type(size) == "number")
local arr = {}
- local i
- for i=1,size,1 do
+ for _ = 1, size do
table.insert(arr, decode_r(data))
end
if not msgpack.cfg.decode_save_metatables then
@@ -490,8 +484,7 @@ end
local function decode_map(data, size)
assert (type(size) == "number")
local map = {}
- local i
- for i=1,size,1 do
+ for _ = 1, size do
local key = decode_r(data);
local val = decode_r(data);
map[key] = val
@@ -504,11 +497,15 @@ end
local ext_decoder = {
-- MP_UNKNOWN_EXTENSION
- [0] = function(data, len) error("unsupported extension type") end,
+ [0] = function() error("unsupported extension type") end,
-- MP_DECIMAL
[1] = function(data, len) local num = ffi.new("decimal_t") builtin.decimal_unpack(data, len, num) return num end,
-- MP_UUID
- [2] = function(data, len) local uuid = ffi.new("struct tt_uuid") builtin.uuid_unpack(data, len, uuid) return uuid end,
+ [2] = function(data, len)
+ local uuid = ffi.new("struct tt_uuid")
+ builtin.uuid_unpack(data, len, uuid)
+ return uuid
+ end,
}
local function decode_ext(data)
@@ -516,7 +513,6 @@ local function decode_ext(data)
-- mp_decode_extl and mp_decode_decimal
-- need type code
data[0] = data[0] - 1
- local old_data = data[0]
local len = builtin.mp_decode_extl(data, t)
local fun = ext_decoder[t[0]]
if type(fun) == 'function' then
@@ -603,7 +599,7 @@ local function check_offset(offset, len)
if offset == nil then
return 1
end
- local offset = ffi.cast('ptrdiff_t', offset)
+ offset = ffi.cast('ptrdiff_t', offset)
if offset < 1 or offset > len then
error(string.format("offset = %d is out of bounds [1..%d]",
tonumber(offset), len))
diff --git a/src/lua/socket.lua b/src/lua/socket.lua
index a334ad45b..317acfe8e 100644
--- a/src/lua/socket.lua
+++ b/src/lua/socket.lua
@@ -172,7 +172,7 @@ local function get_iflags(table, flags)
if type(flags) ~= 'table' then
flags = { flags }
end
- for i, f in pairs(flags) do
+ for _, f in pairs(flags) do
if table[f] == nil then
return nil
end
@@ -660,7 +660,7 @@ local function check_delimiter(self, limit, eols)
end
local shortest
- for i, eol in ipairs(eols) do
+ for _, eol in ipairs(eols) do
local data = ffi.C.memmem(rbuf.rpos, rbuf:size(), eol, #eol)
if data ~= nil then
local len = ffi.cast('char *', data) - rbuf.rpos + #eol
@@ -706,16 +706,16 @@ local function read(self, limit, timeout, check, ...)
local res = sysread(self, data, rbuf:unused())
if res == 0 then -- eof
self._errno = nil
- local len = rbuf:size()
- local data = ffi.string(rbuf.rpos, len)
+ len = rbuf:size()
+ data = ffi.string(rbuf.rpos, len)
rbuf.rpos = rbuf.rpos + len
return data
elseif res ~= nil then
rbuf.wpos = rbuf.wpos + res
- local len = check(self, limit, ...)
+ len = check(self, limit, ...)
if len ~= nil then
self._errno = nil
- local data = ffi.string(rbuf.rpos, len)
+ data = ffi.string(rbuf.rpos, len)
rbuf.rpos = rbuf.rpos + len
return data
end
@@ -1039,7 +1039,7 @@ local function tcp_connect(host, port, timeout)
boxerrno(0)
return s
end
- local timeout = timeout or TIMEOUT_INFINITY
+ timeout = timeout or TIMEOUT_INFINITY
local stop = fiber.clock() + timeout
local dns = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM',
protocol = 'tcp' })
@@ -1047,7 +1047,7 @@ local function tcp_connect(host, port, timeout)
boxerrno(boxerrno.EINVAL)
return nil
end
- for i, remote in pairs(dns) do
+ for _, remote in pairs(dns) do
timeout = stop - fiber.clock()
if timeout <= 0 then
boxerrno(boxerrno.ETIMEDOUT)
@@ -1078,8 +1078,8 @@ local function tcp_server_handler(server, sc, from)
end
end
-local function tcp_server_loop(server, s, addr)
- fiber.name(format("%s/%s:%s", server.name, addr.host, addr.port), {truncate = true})
+local function tcp_server_loop(server, s, address)
+ fiber.name(format("%s/%s:%s", server.name, address.host, address.port), {truncate = true})
log.info("started")
while socket_readable(s) do
local sc, from = socket_accept(s)
@@ -1104,15 +1104,15 @@ local function tcp_server_usage()
error('Usage: socket.tcp_server(host, port, handler | opts)')
end
-local function tcp_server_do_bind(s, addr)
- if socket_bind(s, addr.host, addr.port) then
- if addr.family == 'AF_UNIX' then
+local function tcp_server_do_bind(s, address)
+ if socket_bind(s, address.host, address.port) then
+ if address.family == 'AF_UNIX' then
-- Make close() remove the unix socket file created
-- by bind(). Note, this must be done before closing
-- the socket fd so that no other tcp server can
-- reuse the same path before we remove the file.
s.close = function(self)
- fio.unlink(addr.port)
+ fio.unlink(address.port)
return socket_close(self)
end
end
@@ -1121,12 +1121,12 @@ local function tcp_server_do_bind(s, addr)
return false
end
-local function tcp_server_bind_addr(s, addr)
- if tcp_server_do_bind(s, addr) then
+local function tcp_server_bind_addr(s, address)
+ if tcp_server_do_bind(s, address) then
return true
end
- if addr.family ~= 'AF_UNIX' then
+ if address.family ~= 'AF_UNIX' then
return false
end
@@ -1136,7 +1136,7 @@ local function tcp_server_bind_addr(s, addr)
local save_errno = boxerrno()
- local sc = tcp_connect(addr.host, addr.port)
+ local sc = tcp_connect(address.host, address.port)
if sc ~= nil then
sc:close()
boxerrno(save_errno)
@@ -1148,13 +1148,13 @@ local function tcp_server_bind_addr(s, addr)
return false
end
- log.info("tcp_server: remove dead UNIX socket: %s", addr.port)
- if not fio.unlink(addr.port) then
+ log.info("tcp_server: remove dead UNIX socket: %s", address.port)
+ if not fio.unlink(address.port) then
log.warn("tcp_server: %s", boxerrno.strerror())
boxerrno(save_errno)
return false
end
- return tcp_server_do_bind(s, addr)
+ return tcp_server_do_bind(s, address)
end
@@ -1172,8 +1172,8 @@ local function tcp_server_bind(host, port, prepare, timeout)
end
end
- for _, addr in ipairs(dns) do
- local s = socket_new(addr.family, addr.type, addr.protocol)
+ for _, address in ipairs(dns) do
+ local s = socket_new(address.family, address.type, address.protocol)
if s ~= nil then
local backlog
if prepare then
@@ -1181,13 +1181,13 @@ local function tcp_server_bind(host, port, prepare, timeout)
else
socket_setsockopt(s, 'SOL_SOCKET', 'SO_REUSEADDR', 1) -- ignore error
end
- if not tcp_server_bind_addr(s, addr) or not s:listen(backlog) then
+ if not tcp_server_bind_addr(s, address) or not s:listen(backlog) then
local save_errno = boxerrno()
socket_close(s)
boxerrno(save_errno)
return nil
end
- return s, addr
+ return s, address
end
end
-- DNS resolved successfully, but addresss family is not supported
@@ -1211,12 +1211,12 @@ local function tcp_server(host, port, opts, timeout)
tcp_server_usage()
end
server.name = server.name or 'server'
- local s, addr = tcp_server_bind(host, port, server.prepare, timeout)
+ local s, address = tcp_server_bind(host, port, server.prepare, timeout)
if not s then
return nil
end
- fiber.create(tcp_server_loop, server, s, addr)
- return s, addr
+ fiber.create(tcp_server_loop, server, s, address)
+ return s, address
end
socket_mt = {
@@ -1311,10 +1311,9 @@ local function lsocket_tcp_getpeername(self)
return peer.host, tostring(peer.port), peer.family:match("AF_(.*)"):lower()
end
-local function lsocket_tcp_settimeout(self, value, mode)
+local function lsocket_tcp_settimeout(self, value)
check_socket(self)
self.timeout = value
- -- mode is effectively ignored
return 1
end
@@ -1467,7 +1466,7 @@ local function lsocket_tcp_receive(self, pattern, prefix)
local result = { prefix }
local deadline = fiber.clock() + (self.timeout or TIMEOUT_INFINITY)
repeat
- local data = read(self, LIMIT_INFINITY, timeout, check_infinity)
+ data = read(self, LIMIT_INFINITY, timeout, check_infinity)
if data == nil then
if not errno_is_transient[self._errno] then
return nil, socket_error(self)
@@ -1535,7 +1534,7 @@ lsocket_tcp_mt.__index.send = lsocket_tcp_send;
-- TCP Constructor and Shortcuts
--
-local function lsocket_tcp()
+local function lsocket_tcp(self)
local s = socket_new('AF_INET', 'SOCK_STREAM', 'tcp')
if not s then
return nil, socket_error(self)
@@ -1559,7 +1558,7 @@ local function lsocket_bind(host, port, backlog)
if host == nil or port == nil then
error("Usage: luasocket.bind(host, port [, backlog])")
end
- local function prepare(s) return backlog end
+ local function prepare() return backlog end
local s = tcp_server_bind(host, port, prepare)
if not s then
return nil, boxerrno.strerror()
diff --git a/src/lua/string.lua b/src/lua/string.lua
index 6e12c59ae..d3a846645 100644
--- a/src/lua/string.lua
+++ b/src/lua/string.lua
@@ -233,7 +233,6 @@ local function string_startswith(inp, head, _start, _end)
return false
end
_start = _start - 1
- _end = _start + head_len - 1
return memcmp(c_char_ptr(inp) + _start, c_char_ptr(head), head_len) == 0
end
diff --git a/src/lua/swim.lua b/src/lua/swim.lua
index 0859915c9..8e3b0ab13 100644
--- a/src/lua/swim.lua
+++ b/src/lua/swim.lua
@@ -371,7 +371,7 @@ end
--
local function swim_member_payload_str(m)
local ptr = swim_check_member(m, 'member:payload_str()')
- local cdata, size = swim_member_payload_raw(ptr)
+ local _, size = swim_member_payload_raw(ptr)
if size > 0 then
return ffi.string(swim_member_payload_raw(ptr))
end
@@ -462,7 +462,7 @@ local swim_member_mt = {
is_dropped = swim_member_is_dropped,
},
__serialize = swim_member_serialize,
- __newindex = function(m)
+ __newindex = function()
return error('swim_member is a read-only object')
end
}
@@ -793,9 +793,9 @@ local function swim_on_member_event_new(s, callback, ctx)
-- trigger will never be GC-ed.
s = setmetatable({s}, {__mode = 'v'})
return function(member_ptr, event_mask)
- local s = s[1]
- if s then
- local m = swim_wrap_member(s, member_ptr)
+ local si = s[1]
+ if si then
+ local m = swim_wrap_member(si, member_ptr)
local event = setmetatable({event_mask}, swim_member_event_mt)
return callback(m, event, ctx)
end
diff --git a/src/lua/tap.lua b/src/lua/tap.lua
index 94b080d5a..094eb883f 100644
--- a/src/lua/tap.lua
+++ b/src/lua/tap.lua
@@ -53,7 +53,6 @@ local function ok(test, cond, message, extra)
io.write(string.format("not ok - %s\n", message))
extra = extra or {}
if test.trace then
- local frame = debug.getinfo(3, "Sl")
extra.trace = traceback()
extra.filename = extra.trace[#extra.trace].filename
extra.line = extra.trace[#extra.trace].line
@@ -76,9 +75,6 @@ local function skip(test, message, extra)
ok(test, true, message.." # skip", extra)
end
-
-local nan = 0/0
-
local function cmpdeeply(got, expected, extra)
if type(expected) == "number" or type(got) == "number" then
extra.got = got
@@ -190,38 +186,38 @@ local function isboolean(test, v, message, extra)
return is(test, type(v), 'boolean', message, extra)
end
-local function isfunction(test, v, message, extra)
- return is(test, type(v), 'function', message, extra)
+local function isfunction(testcase, v, message, extra)
+ return is(testcase, type(v), 'function', message, extra)
end
-local function isudata(test, v, utype, message, extra)
+local function isudata(testcase, v, utype, message, extra)
extra = extra or {}
extra.expected = 'userdata<'..utype..'>'
if type(v) == 'userdata' then
extra.got = 'userdata<'..getmetatable(v)..'>'
- return ok(test, getmetatable(v) == utype, message, extra)
+ return ok(testcase, getmetatable(v) == utype, message, extra)
else
extra.got = type(v)
- return fail(test, message, extra)
+ return fail(testcase, message, extra)
end
end
-local function iscdata(test, v, ctype, message, extra)
+local function iscdata(testcase, v, ctype, message, extra)
extra = extra or {}
extra.expected = ffi.typeof(ctype)
if type(v) == 'cdata' then
extra.got = ffi.typeof(v)
- return ok(test, ffi.istype(ctype, v), message, extra)
+ return ok(testcase, ffi.istype(ctype, v), message, extra)
else
extra.got = type(v)
- return fail(test, message, extra)
+ return fail(testcase, message, extra)
end
end
local test_mt
local function test(parent, name, fun, ...)
local level = parent ~= nil and parent.level + 1 or 0
- local test = setmetatable({
+ local testcase = setmetatable({
parent = parent;
name = name;
level = level;
@@ -232,48 +228,48 @@ local function test(parent, name, fun, ...)
strict = false;
}, test_mt)
if fun ~= nil then
- test:diag('%s', test.name)
- fun(test, ...)
- test:diag('%s: end', test.name)
- return test:check()
+ testcase:diag('%s', testcase.name)
+ fun(testcase, ...)
+ testcase:diag('%s: end', testcase.name)
+ return testcase:check()
else
- return test
+ return testcase
end
end
-local function plan(test, planned)
- test.planned = planned
- io.write(string.rep(' ', 4 * test.level), string.format("1..%d\n", planned))
+local function plan(testcase, planned)
+ testcase.planned = planned
+ io.write(string.rep(' ', 4 * testcase.level), string.format("1..%d\n", planned))
end
-local function check(test)
- if test.checked then
+local function check(testcase)
+ if testcase.checked then
error('check called twice')
end
- test.checked = true
- if test.planned ~= test.total then
- if test.parent ~= nil then
- ok(test.parent, false, "bad plan", { planned = test.planned;
- run = test.total})
+ testcase.checked = true
+ if testcase.planned ~= testcase.total then
+ if testcase.parent ~= nil then
+ ok(testcase.parent, false, "bad plan", { planned = testcase.planned;
+ run = testcase.total})
else
- diag(test, string.format("bad plan: planned %d run %d",
- test.planned, test.total))
+ diag(testcase, string.format("bad plan: planned %d run %d",
+ testcase.planned, testcase.total))
end
- elseif test.failed > 0 then
- if test.parent ~= nil then
- ok(test.parent, false, "failed subtests", {
- failed = test.failed;
- planned = test.planned;
+ elseif testcase.failed > 0 then
+ if testcase.parent ~= nil then
+ ok(testcase.parent, false, "failed subtests", {
+ failed = testcase.failed;
+ planned = testcase.planned;
})
else
- diag(test, "failed subtest: %d", test.failed)
+ diag(testcase, "failed subtest: %d", testcase.failed)
end
else
- if test.parent ~= nil then
- ok(test.parent, true, test.name)
+ if testcase.parent ~= nil then
+ ok(testcase.parent, true, testcase.name)
end
end
- return test.planned == test.total and test.failed == 0
+ return testcase.planned == testcase.total and testcase.failed == 0
end
test_mt = {
diff --git a/src/lua/trigger.lua b/src/lua/trigger.lua
index 76a582c47..1330ecdd4 100644
--- a/src/lua/trigger.lua
+++ b/src/lua/trigger.lua
@@ -1,7 +1,4 @@
local fun = require('fun')
-local log = require('log')
-
-local table_clear = require('table.clear')
--
-- Checks that argument is a callable, i.e. a function or a table
--
2.23.0
More information about the Tarantool-patches
mailing list