This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
utime: ticks_diff() raises an exception with large values returned by ticks_us() or ticks_ms() #113
Comments
Made a PR attemting to fix that issue. |
This simple script will trigger an exception latest after about 35 minutes.
|
Actually the minimal change to fix that is to modify ticks_diff() as:
This change will also return a reasonable behavior, if the arguments of the call are swapped - sign change. The only deviating result is achieved with ticks_diff(0x80000000, 0), and ticks_diff(0, 0x8000000), which return the same value -2147483648 |
Thanks for merging. |
X-Ryl669
pushed a commit
to X-Ryl669/pycom-micropython-sigfox
that referenced
this issue
May 12, 2023
This fixes ensure, that the return values of ticks_ms(), ticks_us() and ticks_cpu() fit into a MP_SMALL_INT. That way, they can be fed into ticks_diff() without the risk of an OverflowError (see issue pycom#113). As a side effect, the result of ticks_diff(a, b) is always defined as a reasonable value even if a is a time after b (a > b). In that case, the value is negative. The implementation just copies the mechanism from py/extmod/mphal_utime.c. Second change: Add the method ticks_add().
X-Ryl669
pushed a commit
to X-Ryl669/pycom-micropython-sigfox
that referenced
this issue
May 12, 2023
Update get_idf_libs.py
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Uh oh!
There was an error while loading. Please reload this page.
The functions utime.ticks_us() and utime.ticks_ms() may return values, which then cannot be used as input for utime.ticks_diff(). Example:
The reason is, that the return values are not stripped to values which can be representef by a MP_SMALL_INT, or at least 31 bit.
Edit: Funny enough, the utime module is mostly implemented twice, in esp32/mods/modutime.c and in py/extmod/mphal_utime.c, where the latter seems to have proper value/overflow handling.
The text was updated successfully, but these errors were encountered: