Skip to content

Commit f60916a

Browse files
authored
Merge branch 'master' into termux-support
2 parents e532e64 + efbf4c4 commit f60916a

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ To your `php.ini`.
7373
require __DIR__ . '/vendor/autoload.php';
7474
use Jcupitt\Vips;
7575

76+
// check libvips version
77+
echo 'libvips version: ' . Vips\Config::version() . PHP_EOL;
78+
7679
// fast thumbnail generator
7780
$image = Vips\Image::thumbnail('somefile.jpg', 128);
7881
$image->writeToFile('tiny.jpg');

src/FFI.php

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,10 @@ private static function init(): void
243243
if (!ini_get('ffi.enable')) {
244244
throw new Exception("ffi.enable not set to 'true'");
245245
}
246-
if (version_compare(PHP_VERSION, '8.3', '>=') &&
247-
ini_get('zend.max_allowed_stack_size') != '-1') {
248-
throw new Exception("zend.max_allowed_stack_size not set to '-1'");
249-
}
250246

251-
// Use "libvips.so" on Termux, otherwise use the standard versioned library
252-
$vips_libname = getenv('PREFIX') === '/data/data/com.termux/files/usr'
253-
? "libvips.so"
254-
: self::libraryName("libvips", 42);
255-
256-
if (PHP_OS_FAMILY === "Windows") {
257-
$glib_libname = self::libraryName("libglib-2.0", 0);
258-
$gobject_libname = self::libraryName("libgobject-2.0", 0);
259-
} else {
260-
$glib_libname = $vips_libname;
261-
$gobject_libname = $vips_libname;
262-
}
247+
$vips_libname = self::libraryName("libvips", 42);
248+
$glib_libname = self::libraryName("libglib-2.0", 0);
249+
$gobject_libname = self::libraryName("libgobject-2.0", 0);
263250

264251
Utils::debugLog("init", ["library" => $vips_libname]);
265252

@@ -779,21 +766,24 @@ private static function init(): void
779766
}
780767

781768
Utils::debugLog("init", ["binding ..."]);
782-
self::$glib = self::libraryLoad(
783-
$libraryPaths,
784-
$glib_libname,
785-
$glib_decls
786-
);
787-
self::$gobject = self::libraryLoad(
788-
$libraryPaths,
789-
$gobject_libname,
790-
$gobject_decls
791-
);
792-
self::$vips = self::libraryLoad(
793-
$libraryPaths,
794-
$vips_libname,
795-
$vips_decls
796-
);
769+
770+
/**
771+
* We can sometimes get dependent libraries from libvips -- either the platform
772+
* will open dependencies for us automatically, or the libvips binary has been
773+
* built to includes all main dependencies (common on Windows, can happen
774+
* elsewhere).
775+
*
776+
* We must get GLib functions from libvips if we can, since it will be the
777+
* one that libvips itself is using, and they will share runtime types.
778+
*/
779+
self::$glib =
780+
self::libraryLoad($libraryPaths, $vips_libname, $glib_decls) ??
781+
self::libraryLoad($libraryPaths, $glib_libname, $glib_decls);
782+
self::$gobject =
783+
self::libraryLoad($libraryPaths, $vips_libname, $gobject_decls) ??
784+
self::libraryLoad($libraryPaths, $gobject_libname, $gobject_decls);
785+
786+
self::$vips = self::libraryLoad($libraryPaths, $vips_libname, $vips_decls);
797787

798788
# Useful for debugging
799789
# self::$vips->vips_leak_set(1);

src/GObject.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ abstract class GObject
6060
*/
6161
private CData $pointer;
6262

63+
/**
64+
* libvips executes FFI callbacks off the main thread and this confuses
65+
* the stack limit checks available since PHP 8.3.0. We need to check
66+
* if `zend.max_allowed_stack_size` is set to `-1`.
67+
* See: https://github.com/libvips/php-vips/pull/237.
68+
*/
69+
private static bool $check_max_stack_size = true;
70+
6371
/**
6472
* Wrap a GObject around an underlying vips resource. The GObject takes
6573
* ownership of the pointer and will unref it on finalize.
@@ -104,6 +112,16 @@ public function unref(): void
104112
*/
105113
public function signalConnect(string $name, callable $callback): void
106114
{
115+
if (self::$check_max_stack_size) {
116+
$max_allowed_stack_size = ini_get('zend.max_allowed_stack_size');
117+
if ($max_allowed_stack_size !== false &&
118+
$max_allowed_stack_size !== '-1') {
119+
throw new Exception("signalConnect() requires zend.max_allowed_stack_size set to '-1'");
120+
}
121+
122+
self::$check_max_stack_size = false;
123+
}
124+
107125
$marshaler = self::getMarshaler($name, $callback);
108126
if ($marshaler === null) {
109127
throw new Exception("unsupported signal $name");

0 commit comments

Comments
 (0)