From 410d18ef5c24a325f4d63c9b01991015199194c2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 3 Jan 2017 08:46:44 +0300 Subject: [PATCH 1/5] unittest: Allow multiple indirect includes Works by saving all preprocessor defines and reusing them on each run. This also saves NVIM_HEADER_H defines. Saving other defines is needed for defines like `Map(foo, bar)` which are sometimes used to declare types or functions. Saving types or function declarations is not needed because they are recorded as luajit state. Fixes #5857 --- test/functional/helpers.lua | 41 +++-------------------------------- test/helpers.lua | 40 ++++++++++++++++++++++++++++++++++ test/unit/formatc.lua | 6 ++---- test/unit/helpers.lua | 6 ++---- test/unit/preprocess.lua | 43 ++++++++++++++++++++++++++++--------- 5 files changed, 80 insertions(+), 56 deletions(-) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index f3332cff4f..d67f225ed1 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -21,6 +21,9 @@ local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', local mpack = require('mpack') +local tmpname = global_helpers.tmpname +local uname = global_helpers.uname + -- Formulate a path to the directory containing nvim. We use this to -- help run test executables. It helps to keep the tests working, even -- when the build is not in the default location. @@ -334,44 +337,6 @@ local function write_file(name, text, dont_dedent) file:close() end --- Tries to get platform name from $SYSTEM_NAME, uname; fallback is "Windows". -local uname = (function() - local platform = nil - return (function() - if platform then - return platform - end - - platform = os.getenv("SYSTEM_NAME") - if platform then - return platform - end - - local status, f = pcall(io.popen, "uname -s") - if status then - platform = f:read("*l") - else - platform = 'Windows' - end - return platform - end) -end)() - -local function tmpname() - local fname = os.tmpname() - if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then - -- In Windows tmpname() returns a filename starting with - -- special sequence \s, prepend $TEMP path - local tmpdir = os.getenv('TEMP') - return tmpdir..fname - elseif fname:match('^/tmp') and uname() == 'Darwin' then - -- In OS X /tmp links to /private/tmp - return '/private'..fname - else - return fname - end -end - local function source(code) local fname = tmpname() write_file(fname, code) diff --git a/test/helpers.lua b/test/helpers.lua index 4c50c7644f..0bc62da5d7 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -52,9 +52,49 @@ local function check_logs() assert(0 == runtime_errors) end +-- Tries to get platform name from $SYSTEM_NAME, uname; fallback is "Windows". +local uname = (function() + local platform = nil + return (function() + if platform then + return platform + end + + platform = os.getenv("SYSTEM_NAME") + if platform then + return platform + end + + local status, f = pcall(io.popen, "uname -s") + if status then + platform = f:read("*l") + else + platform = 'Windows' + end + return platform + end) +end)() + +local function tmpname() + local fname = os.tmpname() + if uname() == 'Windows' and fname:sub(1, 2) == '\\s' then + -- In Windows tmpname() returns a filename starting with + -- special sequence \s, prepend $TEMP path + local tmpdir = os.getenv('TEMP') + return tmpdir..fname + elseif fname:match('^/tmp') and uname() == 'Darwin' then + -- In OS X /tmp links to /private/tmp + return '/private'..fname + else + return fname + end +end + return { eq = eq, neq = neq, ok = ok, check_logs = check_logs, + uname = uname, + tmpname = tmpname, } diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index 00637e0b8d..9b47a318f0 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -219,12 +219,10 @@ local function standalone(...) -- luacheck: ignore Preprocess.add_to_include_path('./../../build/include') Preprocess.add_to_include_path('./../../.deps/usr/include') - local input = Preprocess.preprocess_stream(arg[1]) - local raw = input:read('*all') - input:close() + local raw = Preprocess.preprocess(arg[1]) if raw == nil then - print("ERROR: Preprocess.preprocess_stream():read() returned empty") + print("ERROR: Preprocess.preprocess() returned empty") end local formatted diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 3564f76442..c9885f73d0 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -68,14 +68,12 @@ local function cimport(...) local body = nil for _ = 1, 10 do - local stream = Preprocess.preprocess_stream(unpack(paths)) - body = stream:read("*a") - stream:close() + body = Preprocess.preprocess(unpack(paths)) if body ~= nil then break end end if body == nil then - print("ERROR: helpers.lua: Preprocess.preprocess_stream():read() returned empty") + print("ERROR: helpers.lua: Preprocess.preprocess() returned empty") end -- format it (so that the lines are "unique" statements), also filter out diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 10ba997758..99537cd66a 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -1,8 +1,12 @@ -- helps managing loading different headers into the LuaJIT ffi. Untested on -- windows, will probably need quite a bit of adjustment to run there. +local global_helpers = require('test.helpers') + local ffi = require("ffi") +local tmpname = global_helpers.tmpname + local ccs = {} local env_cc = os.getenv("CC") @@ -61,12 +65,12 @@ end -- will produce a string that represents a meta C header file that includes -- all the passed in headers. I.e.: -- --- headerize({"stdio.h", "math.h", true} +-- headerize({"stdio.h", "math.h"}, true) -- produces: -- #include -- #include -- --- headerize({"vim.h", "memory.h", false} +-- headerize({"vim.h", "memory.h"}, false) -- produces: -- #include "vim.h" -- #include "memory.h" @@ -79,8 +83,7 @@ local function headerize(headers, global) end local formatted = {} - for i = 1, #headers do - local hdr = headers[i] + for i, hdr in ipairs(headers) do formatted[#formatted + 1] = "#include " .. tostring(pre) .. tostring(hdr) .. @@ -111,7 +114,8 @@ local Gcc = { '-D "_Nullable="', '-D "_Nonnull="', '-U__BLOCKS__', - } + }, + added_header_defines = '', } function Gcc:new(obj) @@ -145,21 +149,40 @@ end -- returns a stream representing a preprocessed form of the passed-in headers. -- Don't forget to close the stream by calling the close() method on it. -function Gcc:preprocess_stream(...) +function Gcc:preprocess(...) -- create pseudo-header local pseudoheader = headerize({...}, false) + local pseudoheader_fname = 'tmp_pseudoheader.h' + local pseudoheader_file = io.open(pseudoheader_fname, 'w') + pseudoheader_file:write(self.added_header_defines) + pseudoheader_file:write("\n") + pseudoheader_file:write(pseudoheader) + pseudoheader_file:flush() + pseudoheader_file:close() local defines = table.concat(self.preprocessor_extra_flags, ' ') local cmd = ("echo $hdr | " .. tostring(self.path) .. " " .. tostring(defines) .. - " -std=c99 -P -E -"):gsub('$hdr', shell_quote(pseudoheader)) + " -std=c99 -P -E " .. shell_quote(pseudoheader_fname)) + local def_cmd = ("echo $hdr | " .. + tostring(self.path) .. + " " .. + tostring(defines) .. + " -std=c99 -dM -E " .. shell_quote(pseudoheader_fname)) + local def_stream = io.popen(def_cmd) + self.added_header_defines = def_stream:read('*a') + def_stream:close() -- lfs = require("lfs") -- print("CWD: #{lfs.currentdir!}") -- print("CMD: #{cmd}") -- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CMD: #{cmd}\n") - return io.popen(cmd) + local stream = io.popen(cmd) + local ret = stream:read('*a') + stream:close() + os.remove(pseudoheader_fname) + return ret end local Clang = Gcc:new() @@ -197,8 +220,8 @@ return { includes = function(hdr) return cc:dependencies(hdr) end, - preprocess_stream = function(...) - return cc:preprocess_stream(...) + preprocess = function(...) + return cc:preprocess(...) end, add_to_include_path = function(...) return cc:add_to_include_path(...) From 0d7b779cab198c89b70bf9d1e6d42cffc3f28f50 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 3 Jan 2017 08:57:43 +0300 Subject: [PATCH 2/5] unittest: Record previous defines in another place Previous commit made preprocess.lua know how its output will be used. This moves state to cimport, making only it know which is cleaner. --- test/unit/formatc.lua | 2 +- test/unit/helpers.lua | 4 +++- test/unit/preprocess.lua | 11 +++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index 9b47a318f0..e5ac87032a 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -219,7 +219,7 @@ local function standalone(...) -- luacheck: ignore Preprocess.add_to_include_path('./../../build/include') Preprocess.add_to_include_path('./../../.deps/usr/include') - local raw = Preprocess.preprocess(arg[1]) + local raw = Preprocess.preprocess('', arg[1]) if raw == nil then print("ERROR: Preprocess.preprocess() returned empty") diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index c9885f73d0..abbdecacc9 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -45,6 +45,8 @@ local function filter_complex_blocks(body) return table.concat(result, "\n") end +local previous_defines = '' + -- use this helper to import C files, you can pass multiple paths at once, -- this helper will return the C namespace of the nvim library. local function cimport(...) @@ -68,7 +70,7 @@ local function cimport(...) local body = nil for _ = 1, 10 do - body = Preprocess.preprocess(unpack(paths)) + body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths)) if body ~= nil then break end end diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 99537cd66a..062432323f 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -115,7 +115,6 @@ local Gcc = { '-D "_Nonnull="', '-U__BLOCKS__', }, - added_header_defines = '', } function Gcc:new(obj) @@ -149,12 +148,12 @@ end -- returns a stream representing a preprocessed form of the passed-in headers. -- Don't forget to close the stream by calling the close() method on it. -function Gcc:preprocess(...) +function Gcc:preprocess(previous_defines, ...) -- create pseudo-header local pseudoheader = headerize({...}, false) local pseudoheader_fname = 'tmp_pseudoheader.h' local pseudoheader_file = io.open(pseudoheader_fname, 'w') - pseudoheader_file:write(self.added_header_defines) + pseudoheader_file:write(previous_defines) pseudoheader_file:write("\n") pseudoheader_file:write(pseudoheader) pseudoheader_file:flush() @@ -171,7 +170,7 @@ function Gcc:preprocess(...) tostring(defines) .. " -std=c99 -dM -E " .. shell_quote(pseudoheader_fname)) local def_stream = io.popen(def_cmd) - self.added_header_defines = def_stream:read('*a') + local defines = def_stream:read('*a') def_stream:close() -- lfs = require("lfs") -- print("CWD: #{lfs.currentdir!}") @@ -179,10 +178,10 @@ function Gcc:preprocess(...) -- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CMD: #{cmd}\n") local stream = io.popen(cmd) - local ret = stream:read('*a') + local declarations = stream:read('*a') stream:close() os.remove(pseudoheader_fname) - return ret + return declarations, defines end local Clang = Gcc:new() From 2151ddbd73a78fcecc992f58f036b8f765a9113e Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 3 Jan 2017 16:25:04 +0300 Subject: [PATCH 3/5] unittest: Move nil checks to Gcc:preprocess --- test/unit/formatc.lua | 4 ---- test/unit/helpers.lua | 9 +-------- test/unit/preprocess.lua | 39 +++++++++++++++++++++++---------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index e5ac87032a..e288081960 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -221,10 +221,6 @@ local function standalone(...) -- luacheck: ignore local raw = Preprocess.preprocess('', arg[1]) - if raw == nil then - print("ERROR: Preprocess.preprocess() returned empty") - end - local formatted if #arg == 2 and arg[2] == 'no' then formatted = raw diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index abbdecacc9..1e97fc9793 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -69,14 +69,7 @@ local function cimport(...) end local body = nil - for _ = 1, 10 do - body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths)) - if body ~= nil then break end - end - - if body == nil then - print("ERROR: helpers.lua: Preprocess.preprocess() returned empty") - end + body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths)) -- format it (so that the lines are "unique" statements), also filter out -- Objective-C blocks diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 062432323f..236cc58192 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -146,6 +146,19 @@ function Gcc:dependencies(hdr) end end +local function repeated_call(cmd) + for _ = 1, 10 do + local stream = io.popen(cmd) + local ret = stream:read('*a') + stream:close() + if ret then + return ret + end + end + print('ERROR: preprocess.lua: Failed to execute ' .. cmd .. ': nil return after 10 attempts') + return nil +end + -- returns a stream representing a preprocessed form of the passed-in headers. -- Don't forget to close the stream by calling the close() method on it. function Gcc:preprocess(previous_defines, ...) @@ -159,28 +172,22 @@ function Gcc:preprocess(previous_defines, ...) pseudoheader_file:flush() pseudoheader_file:close() local defines = table.concat(self.preprocessor_extra_flags, ' ') - local cmd = ("echo $hdr | " .. - tostring(self.path) .. - " " .. - tostring(defines) .. - " -std=c99 -P -E " .. shell_quote(pseudoheader_fname)) - local def_cmd = ("echo $hdr | " .. - tostring(self.path) .. - " " .. - tostring(defines) .. - " -std=c99 -dM -E " .. shell_quote(pseudoheader_fname)) - local def_stream = io.popen(def_cmd) - local defines = def_stream:read('*a') - def_stream:close() + local cmd_base = self.path .. " " .. defines .. " -std=c99" + + local def_cmd = (cmd_base .. " -dM -E " .. shell_quote(pseudoheader_fname)) + local defines = repeated_call(def_cmd) + -- lfs = require("lfs") -- print("CWD: #{lfs.currentdir!}") -- print("CMD: #{cmd}") -- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CMD: #{cmd}\n") - local stream = io.popen(cmd) - local declarations = stream:read('*a') - stream:close() + local decl_cmd = (cmd_base .. " -P -E " .. shell_quote(pseudoheader_fname)) + local declarations = repeated_call(decl_cmd) + os.remove(pseudoheader_fname) + + assert(declarations and defines) return declarations, defines end From b38e7254280ea87ab7f5757709a22aa42da16b03 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 3 Jan 2017 16:56:35 +0300 Subject: [PATCH 4/5] unittest: Refactor preprocess.lua Keeps arguments separated and not joined as a single string as long as possible. Abstracts away additional arguments so that Gcc:preprocess should work for compilers with different conventions should they be supported. --- test/unit/preprocess.lua | 117 +++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 236cc58192..a2c6b1712a 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -11,22 +11,22 @@ local ccs = {} local env_cc = os.getenv("CC") if env_cc then - table.insert(ccs, {path = "/usr/bin/env " .. tostring(env_cc), type = "gcc"}) + table.insert(ccs, {path = {"/usr/bin/env", env_cc}, type = "gcc"}) end if ffi.os == "Windows" then - table.insert(ccs, {path = "cl", type = "msvc"}) + table.insert(ccs, {path = {"cl"}, type = "msvc"}) end -table.insert(ccs, {path = "/usr/bin/env cc", type = "gcc"}) -table.insert(ccs, {path = "/usr/bin/env gcc", type = "gcc"}) -table.insert(ccs, {path = "/usr/bin/env gcc-4.9", type = "gcc"}) -table.insert(ccs, {path = "/usr/bin/env gcc-4.8", type = "gcc"}) -table.insert(ccs, {path = "/usr/bin/env gcc-4.7", type = "gcc"}) -table.insert(ccs, {path = "/usr/bin/env clang", type = "clang"}) -table.insert(ccs, {path = "/usr/bin/env icc", type = "gcc"}) +table.insert(ccs, {path = {"/usr/bin/env", "cc"}, type = "gcc"}) +table.insert(ccs, {path = {"/usr/bin/env", "gcc"}, type = "gcc"}) +table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.9"}, type = "gcc"}) +table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.8"}, type = "gcc"}) +table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.7"}, type = "gcc"}) +table.insert(ccs, {path = {"/usr/bin/env", "clang"}, type = "clang"}) +table.insert(ccs, {path = {"/usr/bin/env", "icc"}, type = "gcc"}) -local quote_me = '[^%w%+%-%=%@%_%/]' -- complement (needn't quote) +local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) local function shell_quote(str) if string.find(str, quote_me) or str == '' then return "'" .. string.gsub(str, "'", [['"'"']]) .. "'" @@ -94,49 +94,78 @@ local function headerize(headers, global) end local Gcc = { + preprocessor_extra_flags = {}, + get_defines_extra_flags = {'-std=c99', '-dM', '-E'}, + get_declarations_extra_flags = {'-std=c99', '-P', '-E'}, +} + +function Gcc:define(name, args, val) + local define = '-D' .. name + local quoted_define = '' + if args ~= nil then + define = define .. '(' .. table.concat(args, ',') .. ')' + end + if val ~= nil then + define = define .. '=' .. val + end + self.preprocessor_extra_flags[#self.preprocessor_extra_flags + 1] = define +end + +function Gcc:undefine(name) + self.preprocessor_extra_flags[#self.preprocessor_extra_flags + 1] = ( + '-U' .. name) +end + +function Gcc:init_defines(name) -- preprocessor flags that will hopefully make the compiler produce C -- declarations that the LuaJIT ffi understands. - preprocessor_extra_flags = { - '-D "aligned(ARGS)="', - '-D "__attribute__(ARGS)="', - '-D "__asm(ARGS)="', - '-D "__asm__(ARGS)="', - '-D "__inline__="', - '-D "EXTERN=extern"', - '-D "INIT(...)="', - '-D_GNU_SOURCE', - '-DINCLUDE_GENERATED_DECLARATIONS', - - -- Needed for FreeBSD - '-D "_Thread_local="', - - -- Needed for macOS Sierra - '-D "_Nullable="', - '-D "_Nonnull="', - '-U__BLOCKS__', - }, -} + self:define('aligned', {'ARGS'}, '') + self:define('__attribute__', {'ARGS'}, '') + self:define('__asm', {'ARGS'}, '') + self:define('__asm__', {'ARGS'}, '') + self:define('__inline__', nil, '') + self:define('EXTERN', nil, 'extern') + self:define('INIT', {'...'}, '') + self:define('_GNU_SOURCE') + self:define('INCLUDE_GENERATED_DECLARATIONS') + -- Needed for FreeBSD + self:define('_Thread_local', nil, '') + -- Needed for macOS Sierra + self:define('_Nullable', nil, '') + self:define('_Nonnull', nil, '') + self:undefine('__BLOCKS__') +end function Gcc:new(obj) obj = obj or {} setmetatable(obj, self) self.__index = self + self:init_defines() return obj end function Gcc:add_to_include_path(...) - local paths = {...} - for i = 1, #paths do - local path = paths[i] - local directive = '-I ' .. '"' .. path .. '"' + for i = 1, select('#', ...) do + local path = select(i, ...) local ef = self.preprocessor_extra_flags - ef[#ef + 1] = directive + ef[#ef + 1] = '-I' .. path end end +local function argss_to_cmd(...) + local cmd = '' + for i = 1, select('#', ...) do + for _, arg in ipairs(select(i, ...)) do + cmd = cmd .. ' ' .. shell_quote(arg) + end + end + return cmd +end + -- returns a list of the headers files upon which this file relies function Gcc:dependencies(hdr) - local out = io.popen(tostring(self.path) .. " -M " .. tostring(hdr) .. " 2>&1") + local cmd = argss_to_cmd(self.path, {'-M', hdr}) .. ' 2>&1' + local out = io.popen(cmd) local deps = out:read("*a") out:close() if deps then @@ -146,7 +175,8 @@ function Gcc:dependencies(hdr) end end -local function repeated_call(cmd) +local function repeated_call(...) + local cmd = argss_to_cmd(...) for _ = 1, 10 do local stream = io.popen(cmd) local ret = stream:read('*a') @@ -171,19 +201,20 @@ function Gcc:preprocess(previous_defines, ...) pseudoheader_file:write(pseudoheader) pseudoheader_file:flush() pseudoheader_file:close() - local defines = table.concat(self.preprocessor_extra_flags, ' ') - local cmd_base = self.path .. " " .. defines .. " -std=c99" - local def_cmd = (cmd_base .. " -dM -E " .. shell_quote(pseudoheader_fname)) - local defines = repeated_call(def_cmd) + local defines = repeated_call(self.path, self.preprocessor_extra_flags, + self.get_defines_extra_flags, + {pseudoheader_fname}) -- lfs = require("lfs") -- print("CWD: #{lfs.currentdir!}") -- print("CMD: #{cmd}") -- io.stderr\write("CWD: #{lfs.currentdir!}\n") -- io.stderr\write("CMD: #{cmd}\n") - local decl_cmd = (cmd_base .. " -P -E " .. shell_quote(pseudoheader_fname)) - local declarations = repeated_call(decl_cmd) + + local declarations = repeated_call(self.path, self.preprocessor_extra_flags, + self.get_declarations_extra_flags, + {pseudoheader_fname}) os.remove(pseudoheader_fname) From 937b6fac8fecb701895b2c4151a864861aaf03f4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 3 Jan 2017 17:37:18 +0300 Subject: [PATCH 5/5] unittest: Fix linter errors --- test/unit/helpers.lua | 2 +- test/unit/preprocess.lua | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 1e97fc9793..a485a875ab 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -68,7 +68,7 @@ local function cimport(...) return libnvim end - local body = nil + local body body, previous_defines = Preprocess.preprocess(previous_defines, unpack(paths)) -- format it (so that the lines are "unique" statements), also filter out diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index a2c6b1712a..8c2a5c73e5 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -1,12 +1,8 @@ -- helps managing loading different headers into the LuaJIT ffi. Untested on -- windows, will probably need quite a bit of adjustment to run there. -local global_helpers = require('test.helpers') - local ffi = require("ffi") -local tmpname = global_helpers.tmpname - local ccs = {} local env_cc = os.getenv("CC") @@ -83,7 +79,7 @@ local function headerize(headers, global) end local formatted = {} - for i, hdr in ipairs(headers) do + for _, hdr in ipairs(headers) do formatted[#formatted + 1] = "#include " .. tostring(pre) .. tostring(hdr) .. @@ -101,7 +97,6 @@ local Gcc = { function Gcc:define(name, args, val) local define = '-D' .. name - local quoted_define = '' if args ~= nil then define = define .. '(' .. table.concat(args, ',') .. ')' end @@ -116,7 +111,7 @@ function Gcc:undefine(name) '-U' .. name) end -function Gcc:init_defines(name) +function Gcc:init_defines() -- preprocessor flags that will hopefully make the compiler produce C -- declarations that the LuaJIT ffi understands. self:define('aligned', {'ARGS'}, '')