Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
Thaodan committed Feb 11, 2021
1 parent 9cce77a commit abc5c9d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions scratchbox2/execs/exec_postprocess.c
Expand Up @@ -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
*
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scratchbox2/lua_scripts/add_rules_to_rule_tree.lua
Expand Up @@ -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
Expand Down Expand Up @@ -280,20 +280,20 @@ 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

new_rule_index = add_one_rule_to_rule_tree(rule, 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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions scratchbox2/lua_scripts/argvenvp_gcc.lua
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions scratchbox2/lua_scripts/create_reverse_rules.lua
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scratchbox2/lua_scripts/init2.lua
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion scratchbox2/lua_scripts/init_argvmods_rules.lua
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scratchbox2/lua_scripts/init_autogen_usr_bin_rules.lua
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scratchbox2/lua_scripts/init_modeconfig.lua
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scratchbox2/lua_scripts/init_net_modes.lua
Expand Up @@ -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

Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scratchbox2/network/net_rules.c
Expand Up @@ -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++) {
Expand Down

0 comments on commit abc5c9d

Please sign in to comment.