Skip to content

Commit 3b50384

Browse files
authored
Move zend.max_allowed_stack_size=-1 check to signalConnect() (#261)
Most users don't need to set this INI directive; it's only required when explicitly calling `signalConnect()` or using the `SourceCustom` and/or `TargetCustom` classes.
1 parent 256575d commit 3b50384

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/FFI.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ 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

251247
$vips_libname = self::libraryName("libvips", 42);
252248
if (PHP_OS_FAMILY === "Windows") {

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)