]> granicus.if.org Git - php/commitdiff
Use ZPP callable check for Windows specific functions
authorGeorge Peter Banyard <girgias@php.net>
Wed, 8 Jul 2020 16:37:01 +0000 (18:37 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Thu, 13 Aug 2020 19:14:50 +0000 (21:14 +0200)
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
win32/signal.c

index cee18fc086060082d3f1328790d77185582f8915..f3ab8734ea334d1e47ea03339cd7425b48463cce 100755 (executable)
@@ -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
index 535545fdbc230169a3d48f78be751e4b877df3bf..d59c0167deff09fe764de8fcf35f1893dd1d24e9 100755 (executable)
@@ -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
index 2436313d2ac187fef0939ec0e14c494329449523..41936f840fe74dabb4e7fef24281a25353f83384 100644 (file)
@@ -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;
 }/*}}}*/