| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7c801e0 commit f35ddf2
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1050,26 +1050,14 @@ py_win_perf_counter_frequency(LONGLONG *pfrequency, int raise) | |||
| 1050 | 1050 | LONGLONG frequency; | |
| 1051 | 1051 | ||
| 1052 | 1052 | LARGE_INTEGER freq; | |
| 1053 | - if (!QueryPerformanceFrequency(&freq)) { | ||
| 1054 | - if (raise) { | ||
| 1055 | - PyErr_SetFromWindowsErr(0); | ||
| 1056 | - } | ||
| 1057 | - return -1; | ||
| 1058 | - } | ||
| 1053 | + // Since Windows XP, the function cannot fail. | ||
| 1054 | + (void)QueryPerformanceFrequency(&freq); | ||
| 1059 | 1055 | frequency = freq.QuadPart; | |
| 1060 | 1056 | ||
| 1061 | - /* Sanity check: should never occur in practice */ | ||
| 1062 | - if (frequency < 1) { | ||
| 1063 | - if (raise) { | ||
| 1064 | - PyErr_SetString(PyExc_RuntimeError, | ||
| 1065 | - "invalid QueryPerformanceFrequency"); | ||
| 1066 | - } | ||
| 1067 | - return -1; | ||
| 1068 | - } | ||
| 1069 | - | ||
| 1070 | - /* Check that frequency can be casted to _PyTime_t. | ||
| 1057 | + // Since Windows XP, frequency cannot be zero. | ||
| 1058 | + assert(frequency >= 1); | ||
| 1071 | 1059 | ||
| 1072 | - Make also sure that (ticks * SEC_TO_NS) cannot overflow in | ||
| 1060 | + /* Make also sure that (ticks * SEC_TO_NS) cannot overflow in | ||
| 1073 | 1061 | _PyTime_MulDiv(), with ticks < frequency. | |
| 1074 | 1062 | ||
| 1075 | 1063 | Known QueryPerformanceFrequency() values: | |
@@ -1078,10 +1066,8 @@ py_win_perf_counter_frequency(LONGLONG *pfrequency, int raise) | |||
| 1078 | 1066 | * 3,579,545 Hz (3.6 MHz): 279 ns resolution | |
| 1079 | 1067 | ||
| 1080 | 1068 | None of these frequencies can overflow with 64-bit _PyTime_t, but | |
| 1081 | - check for overflow, just in case. */ | ||
| 1082 | - if (frequency > _PyTime_MAX | ||
| 1083 | - || frequency > (LONGLONG)_PyTime_MAX / (LONGLONG)SEC_TO_NS) | ||
| 1084 | - { | ||
| 1069 | + check for integer overflow just in case. */ | ||
| 1070 | + if (frequency > _PyTime_MAX / SEC_TO_NS) { | ||
| 1085 | 1071 | if (raise) { | |
| 1086 | 1072 | PyErr_SetString(PyExc_OverflowError, | |
| 1087 | 1073 | "QueryPerformanceFrequency is too large"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments