-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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
Open
folkertdev
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
folkertdev:stabilize-c-variadic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,6 @@ | |
| //! | ||
| //! Better known as "varargs". | ||
|
|
||
| #![unstable( | ||
| feature = "c_variadic", | ||
| issue = "44930", | ||
| reason = "the `c_variadic` feature has not been properly tested on all supported platforms" | ||
| )] | ||
|
|
||
| #[cfg(not(target_arch = "xtensa"))] | ||
| use crate::ffi::c_void; | ||
| use crate::fmt; | ||
|
|
@@ -195,8 +189,6 @@ crate::cfg_select! { | |
| /// is automatically initialized (equivalent to calling `va_start` in C). | ||
| /// | ||
| /// ``` | ||
| /// #![feature(c_variadic)] | ||
| /// | ||
| /// use std::ffi::VaList; | ||
| /// | ||
| /// /// # Safety | ||
|
|
@@ -230,11 +222,13 @@ crate::cfg_select! { | |
| /// terms of layout and ABI. | ||
| #[repr(transparent)] | ||
| #[lang = "va_list"] | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| pub struct VaList<'a> { | ||
| inner: VaListInner, | ||
| _marker: PhantomCovariantLifetime<'a>, | ||
| } | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| impl fmt::Debug for VaList<'_> { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| // No need to include `_marker` in debug output. | ||
|
|
@@ -249,6 +243,7 @@ impl VaList<'_> { | |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")] | ||
| const impl<'f> Clone for VaList<'f> { | ||
| /// Clone the [`VaList`], producing a second independent cursor into the variable argument list. | ||
|
|
@@ -264,6 +259,7 @@ const impl<'f> Clone for VaList<'f> { | |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")] | ||
| const impl<'f> Drop for VaList<'f> { | ||
| /// Drop the [`VaList`]. | ||
|
|
@@ -316,6 +312,7 @@ const impl<'f> Drop for VaList<'f> { | |
| // types with a non-scalar layout. Inline assembly can be used to accept unsupported types in the | ||
| // meantime. | ||
| #[lang = "va_arg_safe"] | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| pub impl(self) unsafe trait VaArgSafe: Copy {} | ||
|
|
||
| crate::cfg_select! { | ||
|
|
@@ -324,7 +321,9 @@ crate::cfg_select! { | |
| // | ||
| // - i8 is implicitly promoted to c_int in C, and cannot implement `VaArgSafe`. | ||
| // - u8 is implicitly promoted to c_uint in C, and cannot implement `VaArgSafe`. | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for i16 {} | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for u16 {} | ||
| } | ||
| _ => { | ||
|
|
@@ -338,6 +337,7 @@ crate::cfg_select! { | |
| crate::cfg_select! { | ||
| target_arch = "avr" => { | ||
| // c_double is f32 on this target. | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for f32 {} | ||
|
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. I think this is fine but just noting that avr seems to be listed under (also the |
||
| } | ||
| _ => { | ||
|
|
@@ -347,12 +347,18 @@ crate::cfg_select! { | |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for i32 {} | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for i64 {} | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for isize {} | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for u32 {} | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for u64 {} | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for usize {} | ||
|
|
||
| // Implement `VaArgSafe` for 128-bit integers on targets where clang provides `__int128`. | ||
|
|
@@ -400,19 +406,19 @@ cfg_select! { | |
| _ => { | ||
| #[repr(transparent)] | ||
| #[derive(Clone, Copy)] | ||
| struct S(i32); | ||
|
|
||
| // When there are no actual implementations on i128, declare the c_variadic_int128 feature | ||
| // on a private type so that the feature is defined on all targets. | ||
| #[unstable(feature = "c_variadic_int128", issue = "155752")] | ||
| unsafe impl VaArgSafe for S {} | ||
|
|
||
| struct S(i32); | ||
| } | ||
| } | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl VaArgSafe for f64 {} | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl<T> VaArgSafe for *mut T {} | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| unsafe impl<T> VaArgSafe for *const T {} | ||
|
|
||
| // Check that relevant `core::ffi` types implement `VaArgSafe`. | ||
|
|
@@ -459,6 +465,7 @@ impl<'f> VaList<'f> { | |
| /// | ||
| /// [`c_void`]: core::ffi::c_void | ||
| #[inline] // Avoid codegen when not used to help backends that don't support VaList. | ||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")] | ||
| #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces | ||
| pub const unsafe fn next_arg<T: VaArgSafe>(&mut self) -> T { | ||
|
|
||
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
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
This file was deleted.
Oops, something went wrong.
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
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
| 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() { | ||
|
|
||
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
| 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() { | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| //@run-native | ||
| #![feature(c_variadic)] | ||
|
|
||
| use std::ffi::{CStr, VaList, c_char, c_double, c_int, c_long}; | ||
|
|
||
|
|
||
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.