Skip to content

Commit

Permalink
Change the return value type of Thread:: getArguments() to return nul…
Browse files Browse the repository at this point in the history
…l in the main thread
  • Loading branch information
matyhtf committed Jul 3, 2024
1 parent c0160e3 commit d1f93df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ext-src/stubs/php_swoole_thread.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function join(): bool {}
public function joinable(): bool {}
public function detach(): bool {}

public static function getArguments(): array {}
public static function getArguments(): ?array {}
public static function getId(): int {}
public static function getTsrmInfo(): array {}
}
Expand Down
7 changes: 4 additions & 3 deletions ext-src/stubs/php_swoole_thread_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 234aeadaab2ab31facf1909f0e3027e433f2a88f */
* Stub hash: 261ac9fd29d4f2f37118ff3b96428a0b2f85223a */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Thread___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, script_file, IS_STRING, 0)
Expand All @@ -13,10 +13,11 @@ ZEND_END_ARG_INFO()

#define arginfo_class_Swoole_Thread_detach arginfo_class_Swoole_Thread_join

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getArguments, 0, 0, IS_ARRAY, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getArguments, 0, 0, IS_ARRAY, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getId, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Swoole_Thread_getTsrmInfo arginfo_class_Swoole_Thread_getArguments
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getTsrmInfo, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
6 changes: 4 additions & 2 deletions ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct ThreadObject {
static void php_swoole_thread_join(zend_object *object);
static void php_swoole_thread_register_stdio_file_handles(bool no_close);

static thread_local zval thread_argv;
static thread_local zval thread_argv = {};
static thread_local JMP_BUF *thread_bailout = nullptr;

static sw_inline ThreadObject *thread_fetch_object(zend_object *obj) {
Expand Down Expand Up @@ -189,7 +189,9 @@ static PHP_METHOD(swoole_thread, detach) {
}

static PHP_METHOD(swoole_thread, getArguments) {
RETURN_ZVAL(&thread_argv, 1, 0);
if (Z_TYPE(thread_argv) == IS_ARRAY) {
RETURN_ZVAL(&thread_argv, 1, 0);
}
}

static PHP_METHOD(swoole_thread, getId) {
Expand Down
17 changes: 17 additions & 0 deletions tests/swoole_thread/empty_args.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
swoole_thread: info
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
skip_if_nts();
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Thread;

$args = Thread::getArguments();
Assert::assert($args === null);
?>
--EXPECTF--

0 comments on commit d1f93df

Please sign in to comment.