-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clock_getres(3) and improve clockid_t constants. #247
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@nbaksalyar It would be great if you could check the Solaris part. I don't quite understand what's available as Memo: checker tool use std::time::Instant;
#[allow(non_camel_case_types)]
type clockid_t = i32;
extern {
fn clock_gettime(clkid: clockid_t, t: *mut Instant) -> i32;
fn clock_getres(clkid: clockid_t, t: *mut Instant) -> i32;
}
fn f(clkid: clockid_t) {
let mut res = Instant::now();
let mut now0 = Instant::now();
let mut now1 = Instant::now();
assert_eq!(0, unsafe { clock_getres(clkid, &mut res as *mut _) } );
assert_eq!(0, unsafe { clock_gettime(clkid, &mut now0 as *mut _) } );
assert_eq!(0, unsafe { clock_gettime(clkid, &mut now1 as *mut _) } );
println!("{}: {:?} {:?} {:?} {:?}", clkid, res, now0, now1, now1 - now0);
}
fn main() {
f(0);
f(1);
f(2);
f(3);
} |
We actually need to avoid |
/// let rc = unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC_COARSE, &mut ts) }; | ||
/// assert_eq!(0, rc); | ||
/// } | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave out the documentation in this library as these are all just straight bindings to libc, no need to document how to use each and every one
Can you elaborate? How can |
If a C function returns an enum then it can actually return any integer. In Rust it's not memory safe to have a value of type |
Right, I had only passing an enum to C API in mind, like in this case of |
Yeah unfortunately there's still the problems of:
|
Well, then a downstream user should stop and think how to deal with the newly added case, so isn't breakage rather desirable? I'd say it's only propagating a semantic incompatibility brought by the OS. Anyways, you're telling me this project should be a literally "raw bindings" to the system libc (and such considerations should perhaps be addressed by another, high-level wrapper of libc.) Fair enough, I reverted them back to plain int Any comments on constants that might not exist in older kernels? Of course an user is expected to check the return value of APIs, but I just want to know about the general principles for handling backward-incompatibilities if there are any. |
More than half of Travis failures came from the style checker (on comment lines longer than 80 chars in length,) BUT others indeed highlighted a compatibility issue. For example, the aarch64 cross tools shipped with Trusty/14.04 seems to lack when the native build tools had no issues with it: @alexcrichton Any suggestions? It's true that few people will complain when |
Yes
It's the job of consumers of libc to handle this, we simply bind everything and assume the kernel retains ABI compatibility with older releases.
It's fine to leave out this constant on aarch64 for now. We may just need to update the aarch64 glibc or something like that |
Hi @nodakai. Providing greater safety on top of the libc APIs is the primary goal of the nix project (https://github.com/nix-rust/nix). We would welcome changes there as well once the core bits have made it into libc. Nix is the core behind a number of libraries such as mio (at least on *nix). |
@posborne Thanks, I'll consider merging some of my private binding to it @alexcrichton Now all Travis failures come from missing |
// https://github.com/illumos/illumos-gate/ | ||
// blob/HEAD/usr/src/uts/common/sys/time_impl.h | ||
// Confusing! CLOCK_HIGHRES==CLOCK_MONOTONIC==4 | ||
// __CLOCK_REALTIME0==0 is an obsolated version of CLOCK_REALTIME==3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: obsoleted
@nodakai just to set expectations, we're still figuring out how to handle enum-style constants in nix (nix-rust/nix#254). We'd definitely welcome experiences and ideas on how to to that though, so a PR would be quite welcome! Also thanks for adding the new stuff in libc. I was unaware of |
Perhaps we can just leave out the constants for platforms that don't have it yet? I'd also remove the comments here as well as the duplication across the source isn't buying us much and this library isn't really intended to be read for documentation. |
Signed-off-by: NODA, Kai <nodakai@gmail.com>
@alexcrichton Moved |
Add clock_getres(3) and improve clockid_t constants. This is still a draft
☀️ Test successful - status-appveyor, travis |
* Completes SSE and adds some MMX intrinsics MMX: - `_mm_cmpgt_pi{8,16,32}` - `_mm_unpack{hi,lo}_pi{8,16,32}` SSE (is now complete): - `_mm_cvtp{i,u}{8,16}_ps` - add test for `_m_pmulhuw` * fmt and clippy * add an exception for intrinsics using cvtpi2ps
This is still a draft