You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #141361 - folkertdev:varargs-cfg, r=workingjubilee
use `cfg_select!` to select the right `VaListImpl` definition
tracking issue: #44930
Just a bit of cleanup really.
We could use `PhantomInvariantLifetime<'f>` (#135806) to make it more precise what that `PhantomData<&'f mut &'f c_void>` marker is doing. I'm not sure how ready that feature is though, `@jhpratt` are these types good to use internally?
---
Some research into the lifetimes of `VaList` and `VaListImpl`:
It's easy to see why the lifetime of these types should not be extended, a `VaList` or `VaListImpl` escaping its function is a bad idea. I don't currently see why coercing the lifetime to a shorter lifetime is problematic though, but probably I just don't understand variance well enough to see it. The history does not provide much explanation:
- immunant@0814087 original implementation
- immunant@b9ea653 adds `VaListImpl<'f>`, but it is only covariant in `'f`
- #62639 makes `VaListImpl<'f>` invariant over `'f` (because `VaList<'a, 'f>` is already invariant over `'f`, but I think that is just an implementation detail?)
Beyond that I don't see how the lifetime situation can be simplified significantly, e.g. this function really needs `'copy` to be unconstrained.
```rust
/// Copies the `va_list` at the current location.
pub unsafe fn with_copy<F, R>(&self, f: F) -> R
where
F: for<'copy> FnOnce(VaList<'copy, 'f>) -> R,
{
let mut ap = self.clone();
let ret = f(ap.as_va_list());
// SAFETY: the caller must uphold the safety contract for `va_end`.
unsafe {
va_end(&mut ap);
}
ret
}
```
`@rustbot` label +F-c_variadic
r? `@workingjubilee`
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
41
+
#[derive(Debug)]
42
+
#[lang = "va_list"]
43
+
pubstructVaListImpl<'f> {
44
+
gpr:u8,
45
+
fpr:u8,
46
+
reserved:u16,
47
+
overflow_arg_area:*mut c_void,
48
+
reg_save_area:*mut c_void,
49
+
_marker:PhantomInvariantLifetime<'f>,
50
+
}
51
+
}
52
+
target_arch = "s390x" => {
53
+
/// s390x ABI implementation of a `va_list`.
54
+
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
68
+
#[derive(Debug)]
69
+
#[lang = "va_list"]
70
+
pubstructVaListImpl<'f> {
71
+
gp_offset:i32,
72
+
fp_offset:i32,
73
+
overflow_arg_area:*mut c_void,
74
+
reg_save_area:*mut c_void,
75
+
_marker:PhantomInvariantLifetime<'f>,
76
+
}
77
+
}
78
+
target_arch = "xtensa" => {
79
+
/// Xtensa ABI implementation of a `va_list`.
80
+
#[repr(C)]
81
+
#[derive(Debug)]
82
+
#[lang = "va_list"]
83
+
pubstructVaListImpl<'f> {
84
+
stk:*muti32,
85
+
reg:*muti32,
86
+
ndx:i32,
87
+
_marker:PhantomInvariantLifetime<'f>,
88
+
}
52
89
}
53
-
}
54
-
55
-
/// AArch64 ABI implementation of a `va_list`. See the
56
-
/// [AArch64 Procedure Call Standard] for more details.
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
81
-
#[derive(Debug)]
82
-
#[lang = "va_list"]
83
-
pubstructVaListImpl<'f>{
84
-
gpr:u8,
85
-
fpr:u8,
86
-
reserved:u16,
87
-
overflow_arg_area:*mutc_void,
88
-
reg_save_area:*mutc_void,
89
-
_marker:PhantomData<&'fmut&'fc_void>,
90
-
}
91
-
92
-
/// s390x ABI implementation of a `va_list`.
93
-
#[cfg(target_arch = "s390x")]
94
-
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
#[cfg_attr(not(doc), repr(C))]// work around https://github.com/rust-lang/rust/issues/66401
108
-
#[derive(Debug)]
109
-
#[lang = "va_list"]
110
-
pubstructVaListImpl<'f>{
111
-
gp_offset:i32,
112
-
fp_offset:i32,
113
-
overflow_arg_area:*mutc_void,
114
-
reg_save_area:*mutc_void,
115
-
_marker:PhantomData<&'fmut&'fc_void>,
116
-
}
91
+
// The fallback implementation, used for:
92
+
//
93
+
// - apple aarch64 (see https://github.com/rust-lang/rust/pull/56599)
94
+
// - windows
95
+
// - uefi
96
+
// - any other target for which we don't specify the `VaListImpl` above
97
+
//
98
+
// In this implementation the `va_list` type is just an alias for an opaque pointer.
99
+
// That pointer is probably just the next variadic argument on the caller's stack.
100
+
_ => {
101
+
/// Basic implementation of a `va_list`.
102
+
#[repr(transparent)]
103
+
#[lang = "va_list"]
104
+
pubstructVaListImpl<'f> {
105
+
ptr:*mut c_void,
106
+
107
+
// Invariant over `'f`, so each `VaListImpl<'f>` object is tied to
0 commit comments