From ca925b369b557951507e495a62cd58e651287005 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Wed, 31 Jan 2024 23:02:19 +0100 Subject: [PATCH 1/2] FFI class improvements --- src/FFI.php | 55 +++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/FFI.php b/src/FFI.php index 194db6f..6bc413d 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,9 +268,11 @@ 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/opt/vips/"; } $vips = self::libraryLoad($libraryPaths, $vips_libname, << Date: Fri, 2 Feb 2024 16:02:28 +0100 Subject: [PATCH 2/2] Update missed heredoc; use generic lib location --- src/FFI.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FFI.php b/src/FFI.php index 6bc413d..d8ac18a 100644 --- a/src/FFI.php +++ b/src/FFI.php @@ -272,14 +272,14 @@ private static function init(): void // Homebrew on Apple Silicon $libraryPaths[] = "/opt/homebrew/lib/"; // See https://github.com/Homebrew/brew/issues/13481#issuecomment-1207203483 - $libraryPaths[] = "/usr/local/opt/vips/"; + $libraryPaths[] = "/usr/local/lib/"; } - $vips = self::libraryLoad($libraryPaths, $vips_libname, <<