Skip to content
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

[WIP] Enable va_arg for raw pointers to unsized types #61126

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libcore/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,20 @@ impl_va_arg_safe!{i8, i16, i32, i64, usize}
impl_va_arg_safe!{u8, u16, u32, u64, isize}
impl_va_arg_safe!{f64}

// FIXME(ahomescu): this also enables VaArgSafe for fat pointers,
// which we'd like to avoid. There is no way to currently implement
// a trait exclusively for thin pointers, but RFC #2580 changes this
// so we can fix our implementation once 2580 is implemented.
#[unstable(feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
all supported platforms",
issue = "44930")]
impl<T> sealed_trait::VaArgSafe for *mut T {}
impl<T: ?Sized> sealed_trait::VaArgSafe for *mut T {}
#[unstable(feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
all supported platforms",
issue = "44930")]
impl<T> sealed_trait::VaArgSafe for *const T {}
impl<T: ?Sized> sealed_trait::VaArgSafe for *const T {}

#[unstable(feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
Expand Down
12 changes: 12 additions & 0 deletions src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#![crate_type = "staticlib"]
#![feature(c_variadic)]
#![feature(rustc_private)]
#![feature(extern_types)]

extern crate libc;

use libc::{c_char, c_double, c_int, c_long, c_longlong};
use std::ffi::VaList;
use std::ffi::{CString, CStr};

extern {
// This is an unsized type, used to test pointer-to-unsized-types
type Opaque;
}

macro_rules! continue_if {
($cond:expr) => {
if !($cond) {
Expand Down Expand Up @@ -91,3 +97,9 @@ pub unsafe extern "C" fn check_varargs_1(_: c_int, mut ap: ...) -> usize {
pub unsafe extern "C" fn check_varargs_2(_: c_int, _ap: ...) -> usize {
0
}

#[no_mangle]
pub unsafe extern "C" fn check_varargs_3(_: c_int, mut ap: ...) -> usize {
continue_if!(ap.arg::<*const Opaque>() as usize == 0x1234usize);
0
}
7 changes: 7 additions & 0 deletions src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ extern size_t check_list_copy_0(va_list ap);
extern size_t check_varargs_0(int fixed, ...);
extern size_t check_varargs_1(int fixed, ...);
extern size_t check_varargs_2(int fixed, ...);
extern size_t check_varargs_3(int fixed, ...);

struct opaque_t;

int test_rust(size_t (*fn)(va_list), ...) {
size_t ret = 0;
Expand All @@ -36,5 +39,9 @@ int main(int argc, char* argv[]) {

assert(check_varargs_2(0, "All", "of", "these", "are", "ignored", ".") == 0);

// Test pointer-to-unsized-type values
struct opaque_t *op = (struct opaque_t*) 0x1234;
assert(check_varargs_3(0, op) == 0);

return 0;
}