use new ffi.loadlib helper (#12545)

To load our native libraries.
This commit is contained in:
Benoit Pierre
2024-09-26 18:36:09 +02:00
committed by GitHub
parent 88aea09f73
commit a1edbbf0c4
11 changed files with 19 additions and 39 deletions

2
base

Submodule base updated: fd34cb21ce...4ecca10c53

View File

@@ -476,7 +476,7 @@ end
function Kindle:openInputDevices() function Kindle:openInputDevices()
-- Auto-detect input devices (via FBInk's fbink_input_scan) -- Auto-detect input devices (via FBInk's fbink_input_scan)
local ok, FBInkInput = pcall(ffi.load, "fbink_input") local ok, FBInkInput = pcall(ffi.loadlib, "fbink_input")
if not ok then if not ok then
-- NOP fallback for the testsuite... -- NOP fallback for the testsuite...
FBInkInput = { fbink_input_scan = function() end } FBInkInput = { fbink_input_scan = function() end }

View File

@@ -862,7 +862,7 @@ function Kobo:init()
self:initEventAdjustHooks() self:initEventAdjustHooks()
-- Auto-detect input devices (via FBInk's fbink_input_scan) -- Auto-detect input devices (via FBInk's fbink_input_scan)
local ok, FBInkInput = pcall(ffi.load, "fbink_input") local ok, FBInkInput = pcall(ffi.loadlib, "fbink_input")
if not ok then if not ok then
-- NOP fallback for the testsuite... -- NOP fallback for the testsuite...
FBInkInput = { fbink_input_scan = NOP } FBInkInput = { fbink_input_scan = NOP }

View File

@@ -2,8 +2,8 @@ local ffi = require("ffi")
local logger = require("logger") local logger = require("logger")
local MessageQueue = require("ui/message/messagequeue") local MessageQueue = require("ui/message/messagequeue")
local _ = require("ffi/zeromq_h") local _ = require("ffi/zeromq_h")
local czmq = ffi.load("libs/libczmq.so.4") local czmq = ffi.loadlib("czmq", "4")
local filemq = ffi.load("libs/libfmq.so.1") local filemq = ffi.loadlib("fmq", "1")
local FileMessageQueue = MessageQueue:extend{ local FileMessageQueue = MessageQueue:extend{
client = nil, client = nil,

View File

@@ -3,7 +3,7 @@ local Event = require("ui/event")
local logger = require("logger") local logger = require("logger")
local _ = require("ffi/zeromq_h") local _ = require("ffi/zeromq_h")
local czmq = ffi.load("libs/libczmq.so.4") local czmq = ffi.loadlib("czmq", "4")
local MessageQueue = {} local MessageQueue = {}

View File

@@ -3,8 +3,8 @@ local logger = require("logger")
local MessageQueue = require("ui/message/messagequeue") local MessageQueue = require("ui/message/messagequeue")
local _ = require("ffi/zeromq_h") local _ = require("ffi/zeromq_h")
local zmq = ffi.load("libs/libzmq.so.5") local zmq = ffi.loadlib("zmq", "5")
local czmq = ffi.load("libs/libczmq.so.4") local czmq = ffi.loadlib("czmq", "4")
local C = ffi.C local C = ffi.C
local StreamMessageQueue = MessageQueue:extend{ local StreamMessageQueue = MessageQueue:extend{

View File

@@ -3,8 +3,8 @@ local logger = require("logger")
local MessageQueue = require("ui/message/messagequeue") local MessageQueue = require("ui/message/messagequeue")
local _ = require("ffi/zeromq_h") local _ = require("ffi/zeromq_h")
local zmq = ffi.load("libs/libzmq.so.5") local zmq = ffi.loadlib("zmq", "5")
local czmq = ffi.load("libs/libczmq.so.4") local czmq = ffi.loadlib("czmq", "4")
local C = ffi.C local C = ffi.C
local StreamMessageQueueServer = MessageQueue:extend{ local StreamMessageQueueServer = MessageQueue:extend{

View File

@@ -1,6 +1,9 @@
local android = require("android") local android = require("android")
android.dl.library_path = android.dl.library_path .. ":" .. android.dir .. "/libs" android.dl.library_path = android.dl.library_path .. ":" .. android.dir .. "/libs"
-- setup Lua paths, and ffi helper / override
require("setupkoenv")
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
local ffi = require("ffi") local ffi = require("ffi")
local dummy = require("ffi/posix_h") local dummy = require("ffi/posix_h")

View File

@@ -291,7 +291,7 @@ end)
local function findKeyboards() local function findKeyboards()
local keyboards = {} local keyboards = {}
local FBInkInput = ffi.load("fbink_input") local FBInkInput = ffi.loadlib("fbink_input")
local dev_count = ffi.new("size_t[1]") local dev_count = ffi.new("size_t[1]")
local devices = FBInkInput.fbink_input_scan(C.INPUT_KEYBOARD, 0, 0, dev_count) local devices = FBInkInput.fbink_input_scan(C.INPUT_KEYBOARD, 0, 0, dev_count)
if devices ~= nil then if devices ~= nil then
@@ -312,7 +312,7 @@ end
local function checkKeyboard(path) local function checkKeyboard(path)
local keyboard local keyboard
local FBInkInput = ffi.load("fbink_input") local FBInkInput = ffi.loadlib("fbink_input")
local dev = FBInkInput.fbink_input_check(path, C.INPUT_KEYBOARD, 0, 0) local dev = FBInkInput.fbink_input_check(path, C.INPUT_KEYBOARD, 0, 0)
if dev ~= nil then if dev ~= nil then
if dev.matched then if dev.matched then

View File

@@ -1,32 +1,9 @@
-- set search path for 'require()' -- Set search path for `require()`.
package.path = package.path =
"common/?.lua;frontend/?.lua;" .. "common/?.lua;frontend/?.lua;" ..
package.path package.path
package.cpath = package.cpath =
"common/?.so;common/?.dll;/usr/lib/lua/?.so;" .. "common/?.so;common/?.dll;/usr/lib/lua/?.so;" ..
package.cpath package.cpath
-- Setup `ffi.load` override and 'loadlib' helper.
-- set search path for 'ffi.load()' require("ffi/loadlib")
local ffi = require("ffi")
require("ffi/posix_h")
local C = ffi.C
if ffi.os == "Windows" then
C._putenv("PATH=libs;common;")
end
local ffi_load = ffi.load
-- patch ffi.load for thirdparty luajit libraries
ffi.load = function(lib, global)
io.write("ffi.load: ", lib, global and " (RTLD_GLOBAL)\n" or "\n")
local loaded, re = pcall(ffi_load, lib)
if loaded then return re end
local lib_path = package.searchpath(lib, "./lib?.so;./libs/lib?.so;./libs/lib?.so.1")
if not lib_path then
io.write("ffi.load (warning): ", re, "\n")
error("Not able to load dynamic library: " .. lib)
else
io.write("ffi.load (assisted searchpath): ", lib_path, "\n")
return ffi_load(lib_path, global)
end
end