mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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.
This commit is contained in:
parent
7c801e0fa6
commit
f35ddf2422
1 changed files with 7 additions and 21 deletions
|
@ -1050,26 +1050,14 @@ py_win_perf_counter_frequency(LONGLONG *pfrequency, int raise)
|
||||||
LONGLONG frequency;
|
LONGLONG frequency;
|
||||||
|
|
||||||
LARGE_INTEGER freq;
|
LARGE_INTEGER freq;
|
||||||
if (!QueryPerformanceFrequency(&freq)) {
|
// Since Windows XP, the function cannot fail.
|
||||||
if (raise) {
|
(void)QueryPerformanceFrequency(&freq);
|
||||||
PyErr_SetFromWindowsErr(0);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
frequency = freq.QuadPart;
|
frequency = freq.QuadPart;
|
||||||
|
|
||||||
/* Sanity check: should never occur in practice */
|
// Since Windows XP, frequency cannot be zero.
|
||||||
if (frequency < 1) {
|
assert(frequency >= 1);
|
||||||
if (raise) {
|
|
||||||
PyErr_SetString(PyExc_RuntimeError,
|
|
||||||
"invalid QueryPerformanceFrequency");
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check that frequency can be casted to _PyTime_t.
|
/* 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.
|
_PyTime_MulDiv(), with ticks < frequency.
|
||||||
|
|
||||||
Known QueryPerformanceFrequency() values:
|
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
|
* 3,579,545 Hz (3.6 MHz): 279 ns resolution
|
||||||
|
|
||||||
None of these frequencies can overflow with 64-bit _PyTime_t, but
|
None of these frequencies can overflow with 64-bit _PyTime_t, but
|
||||||
check for overflow, just in case. */
|
check for integer overflow just in case. */
|
||||||
if (frequency > _PyTime_MAX
|
if (frequency > _PyTime_MAX / SEC_TO_NS) {
|
||||||
|| frequency > (LONGLONG)_PyTime_MAX / (LONGLONG)SEC_TO_NS)
|
|
||||||
{
|
|
||||||
if (raise) {
|
if (raise) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"QueryPerformanceFrequency is too large");
|
"QueryPerformanceFrequency is too large");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue