Skip to content

[breaking change] gettimeofday 2nd argument incorrect in some targets #1354

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

Merged
merged 1 commit into from
May 22, 2019

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented May 21, 2019

The second argument of gettimeofday was a *mut c_void on all targets,
but that type is incorrect in the following targets, where it should be
a *mut timezone instead:

On these other targets it appears that the signature of gettimeofday was incorrect (it takes a time-zone pointer instead of a void pointer):

*linux+gnu: http://man7.org/linux/man-pages/man2/gettimeofday.2.html
*freebsd: https://www.freebsd.org/cgi/man.cgi?query=gettimeofday&apropos=0&sektion=2&manpath=FreeBSD+11.2-stable&arch=default&format=html
*openbsd: https://man.openbsd.org/gettimeofday.2
*android: https://github.com/ricardoquesada/android-ndk/blob/master/usr/include/sys/time.h
*dragonfly: https://www.dragonflybsd.org/cgi/web-man?command=gettimeofday&section=2

This commit corrects the type on these targets, which is a breaking change. Due
to how this API is commonly used (e.g. passing ptr::null_mut to the second
argument), breakage should be minimal or non-existent (AFAICT only time, libstd, and parking_lot use this API, and they all should compile after this change). Users wanting to support both versions can just write ptr as *mut _ instead.

Closes #1338.


On these targets, the signature of gettimeofday was correct (the second argument is a void*):

cc @alexcrichton

@rust-highfive
Copy link

@gnzlbg: no appropriate reviewer found, use r? to override

@gnzlbg gnzlbg requested a review from alexcrichton May 21, 2019 12:11
@gnzlbg
Copy link
Contributor Author

gnzlbg commented May 21, 2019

@semarie @strangelittlemonkey @leo60228 ping on the breaking changes for newlib, openbsd, and dragonflybsd

@gnzlbg gnzlbg changed the title Deprecate gettimeofday; provide gettimeofday2 [breaking change] gettimeofday 2nd argument incorrect in some targets May 21, 2019
@gnzlbg
Copy link
Contributor Author

gnzlbg commented May 21, 2019

cc @asomers since this is a breaking change on FreeBSD.

@semarie
Copy link
Contributor

semarie commented May 21, 2019

no problem for me with a breaking change. but it seems to me that if you removed the bad definition of gettimeofday, you not added it back for openbsd.

@alexcrichton
Copy link
Member

I wouldn't personally consider this worth a breaking change, but I think it's fine to land. I do think though that it requires being pretty vigilant after the release and ready to revert if it causes undue breakage.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented May 21, 2019

I'll do a release with this change only once its ready, and submit a PR to rust-lang/rust to update libc (we can do a crater run but... that might not find much), or see if these is any breakage after one nightly cycle.

Copy link
Contributor

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem with fixing the 2nd argument. I also agree that it's unlikely that anybody's using it.

@@ -1249,6 +1249,8 @@ f! {
}

extern {
pub fn gettimeofday(tp: *mut ::timeval,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not combine FreeBSD's and Dragonfly's definitions in src/unix/bsd/freebsdlike/mod.rs ?

@leo60228
Copy link
Contributor

Looks good. FWIW, that's the Linux-specific time header in newlib, the actual one is here: https://github.com/devkitPro/newlib/blob/devkitA64/newlib/libc/include/sys/time.h#L370

@leo60228
Copy link
Contributor

Wait, I misunderstood what the commit did. It should be void* on newlib.

The second argument of `gettimeofday` was a `*mut c_void` on all targets,
but that type is incorrect in the following targets, where it should be
a `*mut timezone` instead:

On these other targets it appears that the signature of gettimeofday was incorrect (it takes a time-zone pointer instead of a void pointer):

linux+gnu: http://man7.org/linux/man-pages/man2/gettimeofday.2.html
freebsd: https://www.freebsd.org/cgi/man.cgi?query=gettimeofday&apropos=0&sektion=2&manpath=FreeBSD+11.2-stable&arch=default&format=html
openbsd: https://man.openbsd.org/gettimeofday.2
android: https://github.com/ricardoquesada/android-ndk/blob/master/usr/include/sys/time.h
dragonfly: https://www.dragonflybsd.org/cgi/web-man?command=gettimeofday&section=2

This commit corrects the type on these targets, which is a breaking change. Due
to how this API is commonly used (e.g. passing `ptr::null_mut` to the second
argument), breakage should be minimal. Users wanting to support both versions
can just write `ptr as *mut _` instead.

Closes rust-lang#1338.
@gnzlbg
Copy link
Contributor Author

gnzlbg commented May 22, 2019

thanks @leo60228 for taking a look, i've updated the PR, rebased, and all seems green.

@bors: r+

@bors
Copy link
Contributor

bors commented May 22, 2019

📌 Commit 759c837 has been approved by gnzlbg

bors added a commit that referenced this pull request May 22, 2019
[breaking change] gettimeofday 2nd argument incorrect in some targets

The second argument of `gettimeofday` was a `*mut c_void` on all targets,
but that type is incorrect in the following targets, where it should be
a `*mut timezone` instead:

On these other targets it appears that the signature of gettimeofday was incorrect (it takes a time-zone pointer instead of a void pointer):

*linux+gnu: http://man7.org/linux/man-pages/man2/gettimeofday.2.html
*freebsd: https://www.freebsd.org/cgi/man.cgi?query=gettimeofday&apropos=0&sektion=2&manpath=FreeBSD+11.2-stable&arch=default&format=html
*openbsd: https://man.openbsd.org/gettimeofday.2
*android: https://github.com/ricardoquesada/android-ndk/blob/master/usr/include/sys/time.h
*dragonfly: https://www.dragonflybsd.org/cgi/web-man?command=gettimeofday&section=2

This commit corrects the type on these targets, which is a breaking change. Due
to how this API is commonly used (e.g. passing `ptr::null_mut` to the second
argument), breakage should be minimal or non-existent (AFAICT only `time`, `libstd`, and `parking_lot` use this API, and they all should compile after this change). Users wanting to support both versions can just write `ptr as *mut _` instead.

Closes #1338.

---

On these targets, the signature of `gettimeofday` was correct (the second argument is a `void*`):

* macosx: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/gettimeofday.2.html
* linux+musl: http://git.musl-libc.org/cgit/musl/tree/include/sys/time.h#n11
* linux+newlib: https://chromium.googlesource.com/native_client/nacl-newlib/+/99fc6c167467b41466ec90e8260e9c49cbe3d13c/newlib/libc/include/sys/time.h#74
* netbsd: http://netbsd.gw.com/cgi-bin/man-cgi?gettimeofday+2.i386+NetBSD-8.0
* newlib: https://github.com/devkitPro/newlib/blob/devkitA64/newlib/libc/include/sys/time.h#L370
* solaris/illumos: https://illumos.org/man/3C/gettimeofday
* emscripten: https://chromium.googlesource.com/external/github.com/kripken/emscripten/+/1.35.20/system/include/libc/sys/time.h#11

cc @alexcrichton
@bors
Copy link
Contributor

bors commented May 22, 2019

⌛ Testing commit 759c837 with merge 50f4b67...

@bors
Copy link
Contributor

bors commented May 22, 2019

☀️ Test successful - checks-cirrus, checks-travis, status-appveyor
Approved by: gnzlbg
Pushing 50f4b67 to master...

@bors bors merged commit 759c837 into rust-lang:master May 22, 2019
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.

gettimeofday has incorrect signature
7 participants