From 8867cfae9cb2dff45ad2dcf431e645d58404d9c6 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 14 Jan 2025 21:05:52 +0000 Subject: [PATCH 1/2] 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). --- ext/pcntl/pcntl.c | 2 +- ext/pcntl/tests/pcntl_cpuaffinity.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 68b76cd1e6fdf..fe5074f1a954c 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -1721,7 +1721,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_argument_type_error(2, "cpu id invalid type (%s)", ZSTR_VAL(wcpu)); zend_string_release(wcpu); PCNTL_CPU_DESTROY(mask); RETURN_THROWS(); diff --git a/ext/pcntl/tests/pcntl_cpuaffinity.phpt b/ext/pcntl/tests/pcntl_cpuaffinity.phpt index 6dc3399e16118..82c1dc7c9c734 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(); } ?> From 7ae8788c6a51afdb761237058ca0a84a4b1f6fdf Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 15 Jan 2025 18:17:12 +0000 Subject: [PATCH 2/2] changes from feedback --- ext/pcntl/pcntl.c | 4 +--- ext/pcntl/tests/pcntl_cpuaffinity.phpt | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index fe5074f1a954c..89631960d5677 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_type_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 82c1dc7c9c734..1e3809f928c78 100644 --- a/ext/pcntl/tests/pcntl_cpuaffinity.phpt +++ b/ext/pcntl/tests/pcntl_cpuaffinity.phpt @@ -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