Skip to content

Commit f475f37

Browse files
committed
load librt only once
Drop duplicate calls to `ffi.load(…)` in `ffi/framebuffer_qtfb` and `ffi/input_pocketbook`: the library is already loaded in the global namespace by `ffi/posix_h`, so `ffi.C` can be used to access its symbols.
1 parent 31fa676 commit f475f37

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

ffi/framebuffer_qtfb.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ local qtfb = require("ffi/qtfb")
55

66
require("ffi/posix_h")
77

8-
-- Fallback/explicit loading of librt for shm_open
9-
local rt
10-
local ok = pcall(function() rt = ffi.load("rt") end)
11-
if not ok or not rt then
12-
rt = C
13-
end
14-
158
local framebuffer = {
169
sock = -1,
1710
data = nil,
@@ -78,7 +71,7 @@ function framebuffer:init()
7871

7972
-- Open and map shared memory
8073
local shmName = string.format("/qtfb_%d", shmKey)
81-
local shmFD = rt.shm_open(shmName, 2, 0) -- O_RDWR = 2
74+
local shmFD = C.shm_open(shmName, 2, 0) -- O_RDWR = 2
8275
if shmFD < 0 then
8376
C.close(self.sock)
8477
self.sock = -1

ffi/input_pocketbook.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local ffi = require("ffi")
22
local C = ffi.C
3-
local rt = ffi.load("librt.so")
43
local inkview = require("ffi/inkview")
54
local util = require("ffi/util")
65

@@ -340,7 +339,7 @@ function input:open()
340339
-- Open the monitor queue. We could technically live without it on older firmwares
341340
-- that don't have it, but I'm not sure how events are meant to be consumed on there
342341
-- to prevent stall, so for the time being we bail when we don't see it.
343-
local hwinput = rt.mq_open("/hwevent", C.O_RDONLY+C.O_NONBLOCK)
342+
local hwinput = C.mq_open("/hwevent", C.O_RDONLY+C.O_NONBLOCK)
344343
assert(hwinput >= 0, "No /hwevent, probably too old firmware")
345344
poll_fds[0].fd = hwinput
346345
poll_fds[0].events = C.POLLIN
@@ -461,7 +460,7 @@ local function waitForEventRaw(timeout)
461460
-- monitor would spam queued events to whaetever else gets focus after us.
462461
if band(poll_fds[0].revents, C.POLLIN) ~= 0 then
463462
updateTimestamp() -- single 'ts' copy for genEmuEvent inside the loop
464-
while rt.mq_receive(poll_fds[0].fd, ffi.cast("char*", hwmsg), hwmsg_len, nil) > 0 do
463+
while C.mq_receive(poll_fds[0].fd, ffi.cast("char*", hwmsg), hwmsg_len, nil) > 0 do
465464
local m = hwmsg[0]
466465
-- If there's no raw keymapping, emit this one instead
467466
if pb_key_events[m.type] and not raw_keymap then
@@ -518,7 +517,7 @@ end
518517
function input.closeAll()
519518
eventq = nil
520519
if poll_fds ~= nil then
521-
rt.mq_close(poll_fds[0].fd)
520+
C.mq_close(poll_fds[0].fd)
522521
for i=1, poll_fds_count-1 do
523522
C.close(poll_fds[i].fd)
524523
end

0 commit comments

Comments
 (0)