summaryrefslogtreecommitdiffstats
path: root/Python/pytime.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-09-24 22:31:56 (GMT)
committerGitHub <noreply@github.com>2021-09-24 22:31:56 (GMT)
commitf35ddf24227e834c9b6b39ad23a0ec382b4de48b (patch)
tree28917201368bc58cacdf2dc46007713d659b3c4d /Python/pytime.c
parent7c801e0fa603b155eab3fd19698aa90854ac5a7b (diff)
downloadcpython-f35ddf24227e834c9b6b39ad23a0ec382b4de48b.zip
cpython-f35ddf24227e834c9b6b39ad23a0ec382b4de48b.tar.gz
cpython-f35ddf24227e834c9b6b39ad23a0ec382b4de48b.tar.bz2
bpo-41299: QueryPerformanceFrequency() cannot fail (GH-28552)
py_win_perf_counter_frequency() no longer checks for QueryPerformanceFrequency() failure. According to the QueryPerformanceFrequency() documentation, the function can no longer fails since Windows XP.
Diffstat (limited to 'Python/pytime.c')
-rw-r--r--Python/pytime.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index 7f9f301..b47a573 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -1050,26 +1050,14 @@ py_win_perf_counter_frequency(LONGLONG *pfrequency, int raise)
LONGLONG frequency;
LARGE_INTEGER freq;
- if (!QueryPerformanceFrequency(&freq)) {
- if (raise) {
- PyErr_SetFromWindowsErr(0);
- }
- return -1;
- }
+ // Since Windows XP, the function cannot fail.
+ (void)QueryPerformanceFrequency(&freq);
frequency = freq.QuadPart;
- /* Sanity check: should never occur in practice */
- if (frequency < 1) {
- if (raise) {
- PyErr_SetString(PyExc_RuntimeError,
- "invalid QueryPerformanceFrequency");
- }
- return -1;
- }
-
- /* Check that frequency can be casted to _PyTime_t.
+ // Since Windows XP, frequency cannot be zero.
+ assert(frequency >= 1);
- Make also sure that (ticks * SEC_TO_NS) cannot overflow in
+ /* Make also sure that (ticks * SEC_TO_NS) cannot overflow in
_PyTime_MulDiv(), with ticks < frequency.
Known QueryPerformanceFrequency() values:
@@ -1078,10 +1066,8 @@ py_win_perf_counter_frequency(LONGLONG *pfrequency, int raise)
* 3,579,545 Hz (3.6 MHz): 279 ns resolution
None of these frequencies can overflow with 64-bit _PyTime_t, but
- check for overflow, just in case. */
- if (frequency > _PyTime_MAX
- || frequency > (LONGLONG)_PyTime_MAX / (LONGLONG)SEC_TO_NS)
- {
+ check for integer overflow just in case. */
+ if (frequency > _PyTime_MAX / SEC_TO_NS) {
if (raise) {
PyErr_SetString(PyExc_OverflowError,
"QueryPerformanceFrequency is too large");