Skip to content

Commit d1f93df

Browse files
committed
Change the return value type of Thread:: getArguments() to return null in the main thread
1 parent c0160e3 commit d1f93df

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

ext-src/stubs/php_swoole_thread.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function join(): bool {}
88
public function joinable(): bool {}
99
public function detach(): bool {}
1010

11-
public static function getArguments(): array {}
11+
public static function getArguments(): ?array {}
1212
public static function getId(): int {}
1313
public static function getTsrmInfo(): array {}
1414
}

ext-src/stubs/php_swoole_thread_arginfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 234aeadaab2ab31facf1909f0e3027e433f2a88f */
2+
* Stub hash: 261ac9fd29d4f2f37118ff3b96428a0b2f85223a */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Thread___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, script_file, IS_STRING, 0)
@@ -13,10 +13,11 @@ ZEND_END_ARG_INFO()
1313

1414
#define arginfo_class_Swoole_Thread_detach arginfo_class_Swoole_Thread_join
1515

16-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getArguments, 0, 0, IS_ARRAY, 0)
16+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getArguments, 0, 0, IS_ARRAY, 1)
1717
ZEND_END_ARG_INFO()
1818

1919
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getId, 0, 0, IS_LONG, 0)
2020
ZEND_END_ARG_INFO()
2121

22-
#define arginfo_class_Swoole_Thread_getTsrmInfo arginfo_class_Swoole_Thread_getArguments
22+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getTsrmInfo, 0, 0, IS_ARRAY, 0)
23+
ZEND_END_ARG_INFO()

ext-src/swoole_thread.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct ThreadObject {
5555
static void php_swoole_thread_join(zend_object *object);
5656
static void php_swoole_thread_register_stdio_file_handles(bool no_close);
5757

58-
static thread_local zval thread_argv;
58+
static thread_local zval thread_argv = {};
5959
static thread_local JMP_BUF *thread_bailout = nullptr;
6060

6161
static sw_inline ThreadObject *thread_fetch_object(zend_object *obj) {
@@ -189,7 +189,9 @@ static PHP_METHOD(swoole_thread, detach) {
189189
}
190190

191191
static PHP_METHOD(swoole_thread, getArguments) {
192-
RETURN_ZVAL(&thread_argv, 1, 0);
192+
if (Z_TYPE(thread_argv) == IS_ARRAY) {
193+
RETURN_ZVAL(&thread_argv, 1, 0);
194+
}
193195
}
194196

195197
static PHP_METHOD(swoole_thread, getId) {

tests/swoole_thread/empty_args.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
swoole_thread: info
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../include/skipif.inc';
6+
skip_if_nts();
7+
?>
8+
--FILE--
9+
<?php
10+
require __DIR__ . '/../include/bootstrap.php';
11+
12+
use Swoole\Thread;
13+
14+
$args = Thread::getArguments();
15+
Assert::assert($args === null);
16+
?>
17+
--EXPECTF--

0 commit comments

Comments
 (0)