gh-104040: Silence a "comparison is always false" warning#104043
gh-104040: Silence a "comparison is always false" warning#104043TabLand wants to merge 8 commits into
Conversation
On i686 by clarifying datatype used in check_ticks_per_second
|
Hi @pganssle, |
|
Hi @abalkin / @arhadthedev, |
| cannot overflow. */ | ||
| if (tps >= 0 && (_PyTime_t)tps > _PyTime_MAX / SEC_TO_NS) { | ||
| _PyTime_t max_time_in_seconds = _PyTime_MAX / SEC_TO_NS; | ||
| if (tps >= 0 && (_PyTime_t)tps > max_time_in_seconds) { |
There was a problem hiding this comment.
I dislike this fix. You should use LONG_MAX and the preprocessor instead, something like:
#ifdef LONG_MAX >= _PyTime_MAX
if (...)
#endifThe compiler is correct that with 32-bit long (which is the case on Windows 64-bit), the condition is always false:
$ python
>>> SEC_TO_NS = 10**9
# _PyTime_t is always signed 64-bit
>>> _PyTime_MAX=2**63-1
# 64-bit signed long
>>> LONG_MAX=2**63-1
>>> LONG_MAX > (_PyTime_MAX // SEC_TO_NS)
True
# 32-bit long
>>> LONG_MAX=2**31-1
>>> LONG_MAX > (_PyTime_MAX // SEC_TO_NS)
False|
Hi @vstinner, Apologies for the delay. It looks like the recent reworking you've done on the timemodule.c file now makes this pull request obsolete. Many thanks for your efforts 🙂️ |
Pull request was closed
Oh, right. I just removed the check. IMO it's no longer needed. Thanks for your PR anyway. |
On i686 by clarifying datatype used in check_ticks_per_second