From dec3ad0096784a919649cffe95bd3d8746f804ab Mon Sep 17 00:00:00 2001 From: TheTechsTech Date: Mon, 13 Mar 2023 17:11:57 -0400 Subject: [PATCH] bug fix preload.php and StandardModule.php --- preload.php | 23 +++++++++++++---------- zend/StandardModule.php | 3 +++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/preload.php b/preload.php index b9308c9..bdaf0dc 100644 --- a/preload.php +++ b/preload.php @@ -257,16 +257,20 @@ function ffi_char_variadic(string ...$string): CData */ function ffi_char_assoc(array ...$items): CData { - $i = 0; - $environment = \FFI::new('char*[' . (\count($items) + 1) . ']', false); - foreach ($items as $key => $value) { - $is = \is_array($value); - $key = $is ? \array_key_first($value) : $key; - $entry = \sprintf('%s=%s', $key, $is ? $value[$key] : $value); - $environment[$i] = \ffi_char($entry); - $i++; + try { + $i = 0; + $environment = \FFI::new('char*[' . (\count($items) + 1) . ']', false); + foreach ($items as $key => $value) { + $is = \is_array($value); + $key = $is ? \array_key_first($value) : $key; + $entry = \sprintf('%s=%s', $key, $is ? @\array_values($value)[0] : $value); + $environment[$i] = \ffi_char($entry); + $i++; + } + $environment[$i] = NULL; + } catch (\Throwable $e) { + $environment = \ffi_null(); } - $environment[$i] = NULL; return \ze_cast('char**', $environment); } @@ -821,7 +825,6 @@ function zend_preloader(): void } \setup_ffi_loader('ts', $header); - \tsrmls_cache_define(); } } } diff --git a/zend/StandardModule.php b/zend/StandardModule.php index 752e3c7..a1f8c2c 100644 --- a/zend/StandardModule.php +++ b/zend/StandardModule.php @@ -329,6 +329,9 @@ final public function __construct( $this->startup(); } + if (\PHP_ZTS) + \tsrmls_cache_define(); + if (\PHP_ZTS && \is_null($this->module_mutex)) $this->module_mutex = \ze_ffi()->tsrm_mutex_alloc(); }