This repository was archived by the owner on Sep 16, 2024. It is now read-only.
modutime.c: Ensure proper smallint values on overflow#115
Merged
husigeza merged 3 commits intopycom:masterfrom Jan 23, 2018
robert-hh:utime
Merged
modutime.c: Ensure proper smallint values on overflow#115husigeza merged 3 commits intopycom:masterfrom robert-hh:utime
husigeza merged 3 commits intopycom:masterfrom
robert-hh:utime
Conversation
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 #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().
Contributor
Author
|
Letting ticks_ms() and ticks_us() return 64 bit values would not change that behavior, but then ticks_diff() would be obsolete, because if can re replaced by calculating the difference in Python. The code for that could be: Edit: Changing in addition ticks_diff into: avoids the overflow exception and gives a reasonable behavior for diffs <= 2**31, and maybe it's the only change needed. |
Revert changes to ticks_diff() and the addition of ticks_add()
… ticks_xx() in ticks_diff() Make ticks_add consistent to ticks_diff And also still avoid the overrun condition when using results from ticks_xx() in ticks_diff() and ticks_add()
X-Ryl669
pushed a commit
to X-Ryl669/pycom-micropython-sigfox
that referenced
this pull request
May 12, 2023
modutime.c: Ensure proper smallint values on overflow
X-Ryl669
pushed a commit
to X-Ryl669/pycom-micropython-sigfox
that referenced
this pull request
May 12, 2023
Pybytes config block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 #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().