From 6979a7a954eb23f58c27b67097406765fed2317c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 14 Jan 2025 21:05:52 +0000 Subject: [PATCH] ext/pcntl: Fix pcntl_setcpuaffinity exception type for invalid cpu id. found while working [on the doc](https://github.com/php/doc-en/pull/4346). close GH-17474 --- NEWS | 5 +++++ ext/pcntl/pcntl.c | 4 +--- ext/pcntl/tests/pcntl_cpuaffinity.phpt | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 3486f8764fe..ef0391468eb 100644 --- a/NEWS +++ b/NEWS @@ -47,6 +47,11 @@ PHP NEWS . Fixed bug GH-17428 (Assertion failure ext/opcache/jit/zend_jit_ir.c:8940). (nielsdos) +- PCNTL: + . Fixed pcntl_setcpuaffinity exception type from ValueError to TypeError for + the cpu mask argument with entries type different than int/string. + (David Carlier) + - PHPDBG: . Fix crashes in function registration + test. (nielsdos, Girgias) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 68b76cd1e6f..89631960d56 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -1720,9 +1720,7 @@ PHP_FUNCTION(pcntl_setcpuaffinity) cpu = (zend_long)tmp; } else { - zend_string *wcpu = zval_get_string_func(ncpu); - zend_argument_value_error(2, "cpu id invalid type (%s)", ZSTR_VAL(wcpu)); - zend_string_release(wcpu); + zend_argument_type_error(2, "value must be of type int|string, %s given", zend_zval_value_name(ncpu)); PCNTL_CPU_DESTROY(mask); RETURN_THROWS(); } diff --git a/ext/pcntl/tests/pcntl_cpuaffinity.phpt b/ext/pcntl/tests/pcntl_cpuaffinity.phpt index 6dc3399e161..1e3809f928c 100644 --- a/ext/pcntl/tests/pcntl_cpuaffinity.phpt +++ b/ext/pcntl/tests/pcntl_cpuaffinity.phpt @@ -48,7 +48,7 @@ try { try { pcntl_setcpuaffinity(null, [1, array(1)]); -} catch (\ValueError $e) { +} catch (\TypeError $e) { echo $e->getMessage(); } ?> @@ -64,6 +64,4 @@ pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id invalid value (def) pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id must be between 0 and %d (%d) pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id must be between 0 and %d (-1024) pcntl_getcpuaffinity(): Argument #1 ($process_id) invalid process (-1024) - -Warning: Array to string conversion in %s on line %d -pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id invalid type (Array) +pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) value must be of type int|string, array given