Skip to content

Commit 6979a7a

Browse files
committedJan 15, 2025··
ext/pcntl: Fix pcntl_setcpuaffinity exception type for invalid cpu id.
found while working [on the doc](php/doc-en#4346). close GH-17474
1 parent 9aaa469 commit 6979a7a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed
 

‎NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ PHP NEWS
4747
. Fixed bug GH-17428 (Assertion failure ext/opcache/jit/zend_jit_ir.c:8940).
4848
(nielsdos)
4949

50+
- PCNTL:
51+
. Fixed pcntl_setcpuaffinity exception type from ValueError to TypeError for
52+
the cpu mask argument with entries type different than int/string.
53+
(David Carlier)
54+
5055
- PHPDBG:
5156
. Fix crashes in function registration + test. (nielsdos, Girgias)
5257

‎ext/pcntl/pcntl.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -1720,9 +1720,7 @@ PHP_FUNCTION(pcntl_setcpuaffinity)
17201720

17211721
cpu = (zend_long)tmp;
17221722
} else {
1723-
zend_string *wcpu = zval_get_string_func(ncpu);
1724-
zend_argument_value_error(2, "cpu id invalid type (%s)", ZSTR_VAL(wcpu));
1725-
zend_string_release(wcpu);
1723+
zend_argument_type_error(2, "value must be of type int|string, %s given", zend_zval_value_name(ncpu));
17261724
PCNTL_CPU_DESTROY(mask);
17271725
RETURN_THROWS();
17281726
}

‎ext/pcntl/tests/pcntl_cpuaffinity.phpt

+2-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ try {
4848

4949
try {
5050
pcntl_setcpuaffinity(null, [1, array(1)]);
51-
} catch (\ValueError $e) {
51+
} catch (\TypeError $e) {
5252
echo $e->getMessage();
5353
}
5454
?>
@@ -64,6 +64,4 @@ pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id invalid value (def)
6464
pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id must be between 0 and %d (%d)
6565
pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id must be between 0 and %d (-1024)
6666
pcntl_getcpuaffinity(): Argument #1 ($process_id) invalid process (-1024)
67-
68-
Warning: Array to string conversion in %s on line %d
69-
pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) cpu id invalid type (Array)
67+
pcntl_setcpuaffinity(): Argument #2 ($cpu_ids) value must be of type int|string, array given

0 commit comments

Comments
 (0)
Please sign in to comment.