Skip to content

Conversation

cpeterso
Copy link
Contributor

Note that Timespec does not perform any range checking and this change does not add any!

This implementation of Ord assumes that pre-epoch Timespecs have negative sec and positive nsec fields. Linux's and Darwin's struct timespec functions handle pre-epoch timestamps with this "two steps back, half step forward" representation, though I cannot find any documentation that actually puts this in writing. This means that (say) -1.2 seconds is represented by Timespec { sec: -2_i64, nsec: 800_000_000_i32 }, not something like Timespec { sec: -1_i64, nsec: -200_000_000_i32 } or Timespec { sec: -1_i64, nsec: 200_000_000_i32 }.

If we wish to codify this implementation detail, we could make Timespec nsec unsigned and add range checks asserting nsec <= 999_999_999_u32. btw, struct Tm also lacks range checking and uses signed integers for fields that can't be negative.

@cpeterso
Copy link
Contributor Author

I renamed the test_timespec_eq_org() function to test_timespec_eq_ord().

catamorphism added a commit that referenced this pull request Jan 20, 2013
@catamorphism catamorphism merged commit fa4f4fa into rust-lang:incoming Jan 20, 2013
@catamorphism
Copy link
Contributor

Great, thanks! May I suggest putting your comment above about the assumptions about negative and positive fields into a comment in the code? I don't really have opinions on this myself, but at least there'll be a note that's easy to find about what decisions got deferred.

@cpeterso cpeterso deleted the impl-timespec-ord branch January 21, 2013 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants