From 57b593a37f53f35b7cd4eadf969ccaa38953e2c3 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Wed, 14 Feb 2024 13:49:12 +0100 Subject: [PATCH] FFI class improvements (fixes #221) (#230) * FFI class improvements * Update missed heredoc; use generic lib location --- src/FFI.php | 59 +++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/FFI.php b/src/FFI.php index 194db6f..d8ac18a 100644 --- a/src/FFI.php +++ b/src/FFI.php @@ -180,10 +180,10 @@ public static function shutDown(): void public static function newGClosure(): \FFI\CData { - // GClosure measures 32-bit with the first few fields until marshal - // Marshal is a function pointer, thus platform-dependant. - // Data is a pointer, thus platform-dependant. - // Notifiers is an array-pointer, thus platform-dependant. + // GClosure measures 32-bit with the first few fields until marshal. + // - Marshal is a function pointer, thus platform-dependant. + // - Data is a pointer, thus platform-dependant. + // - Notifiers is an array-pointer, thus platform-dependant. // All in all it's basically 4 (bytes) + 3 * POINTER_SIZE // However, gobject wants 8 (bytes) + 3 * POINTER_SIZE. // I'm not sure where that extra byte comes from. Padding on 64-bit machines? @@ -210,7 +210,7 @@ private static function libraryLoad( array $libraryPaths, string $libraryName, string $interface - ): \FFI { + ): ?\FFI { Utils::debugLog("trying to open", ["libraryName" => $libraryName]); foreach ($libraryPaths as $path) { Utils::debugLog("trying path", ["path" => $path]); @@ -225,6 +225,7 @@ private static function libraryLoad( ]); } } + return null; } private static function init(): void @@ -234,7 +235,7 @@ private static function init(): void return; } - // the two usual install problems + // the two usual installation problems if (!extension_loaded('ffi')) { throw new Exception('FFI extension not loaded'); } @@ -267,16 +268,18 @@ private static function init(): void $libraryPaths[] = $vipshome . "/lib/"; } - if (PHP_OS_FAMILY === "OSX" || - PHP_OS_FAMILY === "Darwin") { - $libraryPaths[] = "/opt/homebrew/lib/"; // Homebrew on Apple Silicon + if (PHP_OS_FAMILY === "OSX" || PHP_OS_FAMILY === "Darwin") { + // Homebrew on Apple Silicon + $libraryPaths[] = "/opt/homebrew/lib/"; + // See https://github.com/Homebrew/brew/issues/13481#issuecomment-1207203483 + $libraryPaths[] = "/usr/local/lib/"; } - $vips = self::libraryLoad($libraryPaths, $vips_libname, <<