Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move zend.max_allowed_stack_size=-1 check to signalConnect() #261

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/FFI.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ private static function init(): void
if (!ini_get('ffi.enable')) {
throw new Exception("ffi.enable not set to 'true'");
}
if (version_compare(PHP_VERSION, '8.3', '>=') &&
ini_get('zend.max_allowed_stack_size') != '-1') {
throw new Exception("zend.max_allowed_stack_size not set to '-1'");
}

$vips_libname = self::libraryName("libvips", 42);
if (PHP_OS_FAMILY === "Windows") {
Expand Down
18 changes: 18 additions & 0 deletions src/GObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ abstract class GObject
*/
private CData $pointer;

/**
* libvips executes FFI callbacks off the main thread and this confuses
* the stack limit checks available since PHP 8.3.0. We need to check
* if `zend.max_allowed_stack_size` is set to `-1`.
* See: https://github.com/libvips/php-vips/pull/237.
*/
private static bool $check_max_stack_size = true;

/**
* Wrap a GObject around an underlying vips resource. The GObject takes
* ownership of the pointer and will unref it on finalize.
Expand Down Expand Up @@ -104,6 +112,16 @@ public function unref(): void
*/
public function signalConnect(string $name, callable $callback): void
{
if (self::$check_max_stack_size) {
$max_allowed_stack_size = ini_get('zend.max_allowed_stack_size');
if ($max_allowed_stack_size !== false &&
$max_allowed_stack_size !== '-1') {
throw new Exception("signalConnect() requires zend.max_allowed_stack_size set to '-1'");
}

self::$check_max_stack_size = false;
}

$marshaler = self::getMarshaler($name, $callback);
if ($marshaler === null) {
throw new Exception("unsupported signal $name");
Expand Down