Commit abc5c9d4 authored by Thaodan's avatar Thaodan

[sb2] Don't use deprecated table.maxn() in lua. Contributes to JB#52528

`table.maxn()` is deprecated with lua 5.2 and removed by lua 5.4.
parent 9cce77aa
......@@ -664,7 +664,7 @@ int exec_postprocess_native_executable(
* if (updated_args == 1) then
* -- Add components from original argv[]
* local i
* for i = first_argv_element_to_copy, table.maxn(argv) do
* for i = first_argv_element_to_copy, #argv do
* table.insert(new_argv, argv[i])
* end
*
......@@ -849,7 +849,7 @@ static int exec_postprocess_qemu(
* table.insert(new_argv, conf_cputransparency.cmd)
* new_filename = conf_cputransparency.cmd
* else
* for i = 1, table.maxn(conf_cputransparency.qemu_argv) do
* for i = 1, #conf_cputransparency.qemu_argv do
* table.insert(new_argv, conf_cputransparency.qemu_argv[i])
* end
* new_filename = conf_cputransparency.qemu_argv[1]
......@@ -884,7 +884,7 @@ static int exec_postprocess_qemu(
}
/* if conf_cputransparency.qemu_env ~= nil then
* for i = 1, table.maxn(conf_cputransparency.qemu_env) do
* for i = 1, #conf_cputransparency.qemu_env do
* table.insert(new_envp, conf_cputransparency.qemu_env[i])
* end
* end
......
......@@ -72,14 +72,14 @@ function get_rule_tree_offset_for_union_dir_list(union_dir_list)
local union_dir_rule_list_index = ruletree.objectlist_create(#union_dir_list)
for n=1,table.maxn(union_dir_list) do
for n=1,#union_dir_list do
local component_path = union_dir_list[n]
local new_str_index = ruletree.new_string(component_path)
ruletree.objectlist_set(union_dir_rule_list_index, n-1, new_str_index)
end
if debug_messages_enabled then
print("-- Added union dir to rule db: ",table.maxn(union_dir_list),
print("-- Added union dir to rule db: ",#union_dir_list,
"rules, idx=", union_dir_rule_list_index)
end
return union_dir_rule_list_index
......@@ -280,12 +280,12 @@ function add_list_of_rules(rules, modename)
local rule_list_index = 0
if rules ~= nil then
local num_rules = table.maxn(rules)
local num_rules = #rules
if num_rules > 0 then
rule_list_index = ruletree.objectlist_create(num_rules)
for n=1,table.maxn(rules) do
for n=1,#rules do
local rule = rules[n]
local new_rule_index
......@@ -293,7 +293,7 @@ function add_list_of_rules(rules, modename)
ruletree.objectlist_set(rule_list_index, n-1, new_rule_index)
end
if debug_messages_enabled then
print("-- Added to rule db: ",table.maxn(rules),"rules, idx=", rule_list_index)
print("-- Added to rule db: ",#rules,"rules, idx=", rule_list_index)
end
end
end
......@@ -354,7 +354,7 @@ end
function add_all_exec_policies(modename_in_ruletree)
if (all_exec_policies ~= nil) then
for i = 1, table.maxn(all_exec_policies) do
for i = 1, #all_exec_policies do
local ep_name = all_exec_policies[i].name
if ep_name then
sblib.log("debug", "Adding Exec policy "..ep_name)
......
......@@ -124,7 +124,7 @@ function add_cross_compiler(gccrule, version)
if require_version == false then
-- Compiler tools without version suffix
for i = 1, table.maxn(gcc_compilers) do
for i = 1, #gcc_compilers do
local tmp = {}
local compiler_name = gcc_compilers[i]
tmp.name = prefix .. compiler_name
......@@ -144,7 +144,7 @@ function add_cross_compiler(gccrule, version)
end
-- Compiler tools with version suffix
for i = 1, table.maxn(gcc_compilers_with_version) do
for i = 1, #gcc_compilers_with_version do
local tmp = {}
tmp.name = prefix .. gcc_compilers_with_version[i] .. "-" ..
gccrule.cross_gcc_shortversion
......@@ -157,7 +157,7 @@ function add_cross_compiler(gccrule, version)
if require_version == false then
-- just map the filename for linkers and tools
for i = 1, table.maxn(gcc_linkers) do
for i = 1, #gcc_linkers do
local tmp = {}
tmp.name = prefix .. gcc_linkers[i]
tmp.new_filename = gccrule.cross_gcc_dir .. "/" .. gccrule.cross_gcc_subst_prefix .. gcc_linkers[i]
......@@ -175,7 +175,7 @@ function add_cross_compiler(gccrule, version)
end
register_gcc_component_path(tmp, gccrule)
end
for i = 1, table.maxn(gcc_tools) do
for i = 1, #gcc_tools do
local tmp = {}
tmp.name = prefix .. gcc_tools[i]
tmp.new_filename = gccrule.cross_gcc_dir .. "/" .. gccrule.cross_gcc_subst_prefix .. gcc_tools[i]
......@@ -188,7 +188,7 @@ end
if (sbox_host_gcc_prefix_list and sbox_host_gcc_prefix_list ~= "") then
-- deal with host-gcc functionality, disables mapping
for prefix in string.gmatch(sbox_host_gcc_prefix_list, "[^:]+") do
for i = 1, table.maxn(gcc_compilers) do
for i = 1, #gcc_compilers do
local tmp = {}
tmp.name = prefix .. gcc_compilers[i]
tmp.new_filename = sbox_host_gcc_dir .. "/" .. sbox_host_gcc_subst_prefix .. gcc_compilers[i]
......@@ -209,14 +209,14 @@ if (sbox_host_gcc_prefix_list and sbox_host_gcc_prefix_list ~= "") then
end
-- just map the filename for linkers and tools
for i = 1, table.maxn(gcc_linkers) do
for i = 1, #gcc_linkers do
local tmp = {}
tmp.name = prefix .. gcc_linkers[i]
tmp.new_filename = sbox_host_gcc_dir .. "/" .. sbox_host_gcc_subst_prefix .. gcc_linkers[i]
tmp.disable_mapping = 1
register_gcc_component_path(tmp, nil)
end
for i = 1, table.maxn(gcc_tools) do
for i = 1, #gcc_tools do
local tmp = {}
tmp.name = prefix .. gcc_tools[i]
tmp.new_filename = sbox_host_gcc_dir .. "/" .. sbox_host_gcc_subst_prefix .. gcc_tools[i]
......
......@@ -16,7 +16,7 @@ local reversing_disabled_message = ""
-- Order of reverse rules is not necessarily the same as order of forward rules
function test_rev_rule_position(output_rules, d_path)
local n
for n=1,table.maxn(output_rules) do
for n=1,#output_rules do
local rule = output_rules[n]
local cmp_result
cmp_result = sblib.test_path_match(d_path,
......@@ -46,7 +46,7 @@ function reverse_conditional_actions(output_rules, rev_rule_name, rule, n, forwa
end
local a
for a = 1, table.maxn(actions) do
for a = 1, #actions do
-- actions are only partial rules; the "selector" is in
-- "rule", but we must copy it temporarily to action[a],
-- otherwise reverse_one_rule_xxxx() won't be able to
......@@ -239,7 +239,7 @@ end
function reverse_rules(ofile, output_rules, input_rules, modename)
local n
for n=1,table.maxn(input_rules) do
for n=1,#input_rules do
local rule = input_rules[n]
if rule.virtual_path then
......@@ -260,13 +260,13 @@ end
function print_rules(ofile, rules)
local n
for n=1,table.maxn(rules) do
for n=1,#rules do
local rule = rules[n]
ofile:write(string.format("\t{name=\"%s\",\n", rule.name))
local k
for k=1,table.maxn(rule.comments) do
for k=1,#rule.comments do
ofile:write(rule.comments[k].."\n")
end
......@@ -322,7 +322,7 @@ function print_rules(ofile, rules)
end
ofile:write("\t},\n")
end
ofile:write(string.format("-- Printed\t%d\trules\n",table.maxn(rules)))
ofile:write(string.format("-- Printed\t%d\trules\n",#rules))
end
for m_index,m_name in pairs(all_modes) do
......
......@@ -39,7 +39,7 @@ function add_to_cputr_config(configsetname, key, t, val)
key, ruletree.new_boolean(val))
elseif t == "table" then
local list_index = ruletree.objectlist_create(#val)
for i = 1, table.maxn(val) do
for i = 1, #val do
local t2 = type(val[i])
if t2 == "string" then
local new_str_index = ruletree.new_string(val[i])
......
......@@ -44,7 +44,7 @@ end
function stringlist_to_ruletree(stringlist)
local stringlist_index = ruletree.objectlist_create(#stringlist)
for k = 1, table.maxn(stringlist) do
for k = 1, #stringlist do
local string_index = ruletree.new_string(stringlist[k])
ruletree.objectlist_set(stringlist_index, k-1, string_index)
end
......
......@@ -29,7 +29,7 @@ function argvmods_to_mapping_rules(rule_file, prefix)
if process_now and not rule.argvmods_processed then
rule.argvmods_processed = true
local k
for k=1,table.maxn(rule.path_prefixes) do
for k=1,#rule.path_prefixes do
if rule.path_prefixes[k] == "/usr/bin/" and
rule.new_filename ~= nil then
-- this rule maps "n" from /usr/bin to
......
......@@ -19,8 +19,8 @@ for m_index,m_name in pairs(all_modes) do
-- Exec policy selection table
if exec_policy_selection ~= nil then
local epsrule_list_index = ruletree.objectlist_create(table.maxn(exec_policy_selection))
for i = 1, table.maxn(exec_policy_selection) do
local epsrule_list_index = ruletree.objectlist_create(#exec_policy_selection)
for i = 1, #exec_policy_selection do
local epsrule = exec_policy_selection[i]
local ruletype = 0
local selectorstr = 0
......
......@@ -155,12 +155,12 @@ function add_net_rule_chain(net_modename, chain_name, rules)
local rule_list_index = 0
if rules ~= nil then
local num_rules = table.maxn(rules)
local num_rules = #rules
if num_rules > 0 then
rule_list_index = ruletree.objectlist_create(num_rules)
for n=1,table.maxn(rules) do
for n=1,#rules do
local rule = rules[n]
local new_rule_index
......@@ -173,7 +173,7 @@ function add_net_rule_chain(net_modename, chain_name, rules)
net_modename, chain_name, n))
end
end
print("-- Added to rule db: ",table.maxn(rules),"rules, idx=", rule_list_index)
print("-- Added to rule db: ",#rules,"rules, idx=", rule_list_index)
else
io.stderr:write(string.format(
"empty net rule chain (%s,%s)\n",
......
......@@ -252,7 +252,7 @@ static ruletree_net_rule_t *find_net_rule(
__func__, addr_type, orig_dst_addr, orig_port, net_rule_list_offs);
/* Lua:
* for i = 1, table.maxn(netruletable) do
* for i = 1, table.#netruletable do
* local rule = netruletable[i]
*/
for (i = 0; i < rule_list_size; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment