-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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 |
|---|---|---|
|
|
@@ -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")] | ||
| impl<'f> const Clone for VaList<'f> { | ||
| /// Clone the [`VaList`], producing a second independent cursor into the variable argument list. | ||
|
|
@@ -264,6 +259,7 @@ impl<'f> const Clone for VaList<'f> { | |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "c_variadic", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")] | ||
| impl<'f> const Drop for VaList<'f> { | ||
|
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. This The stabilization report says that “The
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. #155821 adds some clarification that the implementation here calls the rust
Member
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. on current nightly it does call llvm's va_end, this isn't actually a problem worth blocking on since #![feature(c_variadic)]
use std::ffi::c_void;
unsafe extern "C" {
fn g(v: *mut c_void);
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn f(mut args: ...) {
unsafe { g(&raw mut args as *mut c_void) }
}LLVM IR of ; Function Attrs: nounwind nonlazybind uwtable
define void @f(...) unnamed_addr #0 personality ptr @rust_eh_personality {
bb2:
%args = alloca [24 x i8], align 8
call void @llvm.lifetime.start.p0(ptr nonnull %args)
call void @llvm.va_start.p0(ptr nonnull %args)
call void @g(ptr noundef nonnull %args) #3
call void @llvm.va_end.p0(ptr nonnull align 8 dereferenceable(24) %args)
call void @llvm.va_end.p0(ptr nonnull %args)
call void @llvm.lifetime.end.p0(ptr nonnull %args)
ret void
} |
||
| /// Drop the [`VaList`]. | ||
|
|
@@ -279,6 +275,7 @@ impl<'f> const Drop for VaList<'f> { | |
| } | ||
| } | ||
|
|
||
| #[unstable(feature = "c_variadic_internals", issue = "none")] | ||
| mod sealed { | ||
| pub trait Sealed {} | ||
|
|
||
|
|
@@ -333,6 +330,7 @@ mod sealed { | |
| // types with an alignment larger than 8, or 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 unsafe trait VaArgSafe: Copy + sealed::Sealed {} | ||
|
|
||
| crate::cfg_select! { | ||
|
|
@@ -341,7 +339,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 {} | ||
| } | ||
| _ => { | ||
|
|
@@ -355,6 +355,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 {} | ||
| } | ||
| _ => { | ||
|
|
@@ -364,17 +365,26 @@ 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 {} | ||
|
|
||
| #[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`. | ||
|
|
@@ -421,6 +431,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 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.