mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Use ZPP callable check for Windows specific functions
This commit is contained in:
parent
9cb522166c
commit
dae83cd7cb
@ -1529,9 +1529,7 @@ function sapi_windows_cp_conv(int|string $in_codepage, int|string $out_codepage,
|
||||
|
||||
function sapi_windows_cp_is_utf8(): bool {}
|
||||
|
||||
/** @param callable|null $handler */
|
||||
function sapi_windows_set_ctrl_handler($handler, bool $add = true): bool {}
|
||||
function sapi_windows_set_ctrl_handler(?callable $handler, bool $add = true): bool {}
|
||||
|
||||
/** @param callable|null $handler */
|
||||
function sapi_windows_generate_ctrl_event(int $event, int $pid = 0): bool {}
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 35cb2432b5deea7cff903c2014bce795b4f30209 */
|
||||
* Stub hash: 269d4da84e4bc6fae246b90e4c50e48463b86f41 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
|
||||
@ -2229,7 +2229,7 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#if defined(PHP_WIN32)
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sapi_windows_set_ctrl_handler, 0, 1, _IS_BOOL, 0)
|
||||
ZEND_ARG_INFO(0, handler)
|
||||
ZEND_ARG_TYPE_INFO(0, handler, IS_CALLABLE, 1)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, add, _IS_BOOL, 0, "true")
|
||||
ZEND_END_ARG_INFO()
|
||||
#endif
|
||||
|
@ -87,10 +87,13 @@ static BOOL WINAPI php_win32_signal_system_ctrl_handler(DWORD evt)
|
||||
/* {{{ Assigns a CTRL signal handler to a PHP function */
|
||||
PHP_FUNCTION(sapi_windows_set_ctrl_handler)
|
||||
{
|
||||
zval *handler = NULL;
|
||||
zend_fcall_info fci;
|
||||
zend_fcall_info_cache fcc;
|
||||
zend_bool add = 1;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &handler, &add) == FAILURE) {
|
||||
|
||||
/* callable argument corresponds to the CTRL handler */
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!|b", &fci, &fcc, &add) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
@ -106,8 +109,7 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler)
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
|
||||
if (IS_NULL == Z_TYPE_P(handler)) {
|
||||
if (!ZEND_FCI_INITIALIZED(fci)) {
|
||||
zval_dtor(&ctrl_handler);
|
||||
ZVAL_UNDEF(&ctrl_handler);
|
||||
if (!SetConsoleCtrlHandler(NULL, add)) {
|
||||
@ -116,20 +118,15 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler)
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
if (!zend_is_callable(handler, 0, NULL)) {
|
||||
zend_argument_type_error(1, "must be a valid callable function name");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if (!SetConsoleCtrlHandler(NULL, FALSE) || !SetConsoleCtrlHandler(php_win32_signal_system_ctrl_handler, add)) {
|
||||
zend_string *func_name = zend_get_callable_name(handler);
|
||||
zend_string *func_name = zend_get_callable_name(&fci.function_name);
|
||||
php_error_docref(NULL, E_WARNING, "Unable to attach %s as a CTRL handler", ZSTR_VAL(func_name));
|
||||
zend_string_release_ex(func_name, 0);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
zval_dtor(&ctrl_handler);
|
||||
ZVAL_COPY(&ctrl_handler, handler);
|
||||
ZVAL_COPY(&ctrl_handler, &fci.function_name);
|
||||
|
||||
RETURN_TRUE;
|
||||
}/*}}}*/
|
||||
|
Loading…
Reference in New Issue
Block a user