Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stats): fix the layout of struct timespec #1821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lua/lazy/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,29 @@ end
function M.cputime()
if M.C == nil then
pcall(function()
local pad = ""
-- If we're a 32-bit platform, we need to pad by 4 bytes.
if ffi.abi("32bit") then
pad = "int _tv_pad;"
end

local pad_before_nsec = ""
local pad_after_nsec = ""
-- Where we place the padding depends on the endianness.
if ffi.abi("le") then
pad_after_nsec = pad
else
pad_before_nsec = pad
end

ffi.cdef([[
typedef long time_t;
typedef int64_t time_t;
typedef int clockid_t;
typedef struct timespec {
time_t tv_sec; /* seconds */
]] .. pad_before_nsec .. [[
long tv_nsec; /* nanoseconds */
]] .. pad_after_nsec .. [[
} nanotime;
int clock_gettime(clockid_t clk_id, struct timespec *tp);
]])
Expand Down