-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Stabilize c-variadic function definitions #155697
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,20 +23,10 @@ use crate::fmt; | |
| #[stable(feature = "c_str_module", since = "1.88.0")] | ||
| pub mod c_str; | ||
|
|
||
| #[unstable( | ||
| feature = "c_variadic", | ||
| issue = "44930", | ||
| reason = "the `c_variadic` feature has not been properly tested on all supported platforms" | ||
| )] | ||
| mod va_list; | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| pub use self::va_list::{VaArgSafe, VaList}; | ||
|
|
||
| #[unstable( | ||
| feature = "c_variadic", | ||
| issue = "44930", | ||
| reason = "the `c_variadic` feature has not been properly tested on all supported platforms" | ||
| )] | ||
| pub mod va_list; | ||
|
Comment on lines
-26
to
-38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to do any surface area change like the module in a separate PR so we see the effects in the nightly docs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I only noticed that the module was |
||
|
|
||
| mod primitives; | ||
| #[stable(feature = "core_ffi_c", since = "1.64.0")] | ||
| pub use self::primitives::{ | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| #![feature(c_variadic)] | ||
|
|
||
| unsafe extern "C" fn helper(_: i32, _: ...) {} | ||
|
|
||
| fn main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| #![feature(c_variadic)] | ||
|
|
||
| unsafe extern "C" fn helper(_: i32, _: ...) {} | ||
|
|
||
| fn main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| #![feature(c_variadic)] | ||
|
|
||
| use std::ffi::{CStr, VaList, c_char, c_double, c_int, c_long}; | ||
|
|
||
| fn ignores_arguments() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| // See issue #58853. | ||
|
|
||
| //@ pp-exact | ||
| #![feature(c_variadic)] | ||
|
|
||
| extern "C" { | ||
| pub fn foo(x: i32, ...); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
(Using a random file for a thread)
I wonder, is this too strict? And does this restriction apply across FFI?
I'm thinking about a
printfimplementation where it is common and valid (as far as I know) to use%xwith both signed and unsigned integers.View changes since the review
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.
It is too strict, and the reference PR does not state it this strongly.
There is a difference here between what C says (in section
7.16.1.1):So signedness is irrelevant, and my interpretation of the other rules is that any pointer type is compatible with any other pointer type (in the same address space).
That is not what Miri currently implements, it instead uses strict type equality because @RalfJung did not have much appetite for (from memory, the third, but in any case) another notion of type equivalence. I went with the more restrictive formulation because we can always relax it later, the inverse is not true.
Perhaps T-opsem has suggestions for a better way to phrase this.
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.
If we can relax the signedness requirements to match C then I think that is preferable, so we don't need to worry about soundness across FFI. It makes sense that Miri should match up with whatever behavior is decided, pinging @rust-lang/miri for thoughts here.
Is "compatible types" in the context of varargs defined anywhere? My read is that if they mean va-compatible then you could consider
int *andunsigned *to be compatible, and you could considervoid *andchar *to be compatible, but you couldn't considerint *andlong *to be compatible. Though I don't think Ive ever seen anybody cast pointers to void before using%p.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.
If it does mean va-compatible then
unsafe impl<T> VaArgSafe for *mut T {}may not be correctThere 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.
Hmm no, I think your read is correct.
Based on the last rule I think
*mut Talwaysbut then the only valid value you can provide there is the NULL pointer... So then
unsafe impl<T: VaArgSafe> VaArgSafe for *mut T {}might be more accurate.That's really cumbersome, and I've similarly never seen people cast to
void *when using%p. I don't really see a practical reason for it either.Uh oh!
There was an error while loading. Please reload this page.
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.
https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Compatible-Types.html spells out compatible types in a bit clearer form. edit In particular:
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.
Aha! In 7.21.6.
So the common use in C is UB. Nice.
Found via https://stackoverflow.com/questions/24867814/printfp-and-casting-to-void