diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 8536cb8d8..238464f8f 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -296,6 +296,9 @@ Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { result += ToString(p_ty); result += ','; } + if (proto->isVariadic()) { + result += "Box<[VaArg]>,"; + } result += ')'; if (!proto->getReturnType()->isVoidType()) { result += std::format(" -> {}", ToString(proto->getReturnType())); @@ -2234,8 +2237,9 @@ void Converter::EmitArgList(const CallInfo &info) { if (info.is_variadic) { if (!info.is_libc_passthrough) { - StrCat(token::kRef); + StrCat("Box::new"); } + PushParen box(*this, !info.is_libc_passthrough); PushBracket push(*this, !info.is_libc_passthrough); for (auto *arg : info.variadic_args) { { @@ -4069,6 +4073,9 @@ void Converter::ConvertLambdaClosure(const clang::CXXRecordDecl *decl, ConvertVarDeclSkipInit(p); StrCat(token::kComma); } + if (call_operator->isVariadic()) { + StrCat("__args: Box<[VaArg]>", token::kComma); + } in_function_formals_ = false; StrCat('|'); ConvertFunctionReturnType(call_operator); @@ -4626,7 +4633,7 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { StrCat(token::kComma); } if (decl->isVariadic()) { - StrCat("__args: &[VaArg]", token::kComma); + StrCat("__args: Box<[VaArg]>", token::kComma); } in_function_formals_ = false; } @@ -5321,7 +5328,7 @@ Converter::ConvertVariadicTail(clang::Expr *expr, unsigned fixed = tgt_ir ? tgt_ir->params.size() : 0; Buffer buf(*this); - StrCat("&["); + StrCat("Box::<[VaArg]>::from(["); for (unsigned i = fixed; i < all_args.size(); ++i) { { PushParen p(*this); @@ -5329,7 +5336,7 @@ Converter::ConvertVariadicTail(clang::Expr *expr, } StrCat(".into()", token::kComma); } - StrCat("]"); + StrCat("])"); return std::move(buf).str(); } diff --git a/docs/src/rules/conventions.md b/docs/src/rules/conventions.md index 2cd444b84..7d6b86ce1 100644 --- a/docs/src/rules/conventions.md +++ b/docs/src/rules/conventions.md @@ -11,7 +11,7 @@ fails the build; the notes below call out the ones that are not checked. | Type rule | `t1`, `t2`, ... via `using`/`typedef` | `fn tN() -> RustType` with no arguments | | Parameters | free-form (`o`, `it`, `key`, `dst`, `n`, ...) | must be `a0`, `a1`, ... consecutive from 0 | | Generics | `T1`, `T2`, ... (type and non-type params) | `T1`, `T2`, ... consecutive from 1 | -| Variadic pack | `typename... Args` | trailing `va: &[VaArg]` | +| Variadic pack | `typename... Args` | trailing `va: Box<[VaArg]>` | | Constructing pack | `Init &&...args` | trailing `init: RustType` | | Locals in Rust bodies | | double-underscore prefix: `__v`, `__fd`, `__e`, ... | diff --git a/docs/src/rules/writing-rules.md b/docs/src/rules/writing-rules.md index 90f84aefc..fb0f7e25b 100644 --- a/docs/src/rules/writing-rules.md +++ b/docs/src/rules/writing-rules.md @@ -267,7 +267,7 @@ int f1(int a0, int a1, ...) { return fcntl(a0, a1, ...); } is not expressible. A parameter pack can be forwarded (`args...`), which is exactly what the rule body needs to do. The Rust side takes a trailing parameter -that must be typed `&[VaArg]` and named `va`: +that must be typed `Box<[VaArg]>` and named `va`: ```cpp // rules/fcntl/src.cpp @@ -279,7 +279,7 @@ int f1(int a0, int a1, Args... args) { ```rust // rules/fcntl/tgt_refcount.rs -fn f1(a0: i32, a1: i32, va: &[VaArg]) -> i32 { ... } +fn f1(a0: i32, a1: i32, va: Box<[VaArg]>) -> i32 { ... } ``` Bodies read the arguments through the va-args API in `libcc2rs` (`VaArg`, diff --git a/docs/src/runtime/va-args.md b/docs/src/runtime/va-args.md index e8ad69913..d70babf23 100644 --- a/docs/src/runtime/va-args.md +++ b/docs/src/runtime/va-args.md @@ -39,7 +39,7 @@ sum(3, 10, 20, 30); ``` ```rust -pub fn sum_0(count: i32, __args: &[VaArg]) -> i32 { +pub fn sum_0(count: i32, __args: Box<[VaArg]>) -> i32 { let ap: Value = Rc::new(RefCell::new(VaList::default())); (*ap.borrow_mut()) = VaList::new(__args); let total: Value = Rc::new(RefCell::new(0)); @@ -48,7 +48,7 @@ pub fn sum_0(count: i32, __args: &[VaArg]) -> i32 { // ... } -sum_0(3, &[10.into(), 20.into(), 30.into()]); +sum_0(3, Box::new([10.into(), 20.into(), 30.into()])); ``` `arg::()` goes through the `VaArgGet` trait, implemented for the integer and @@ -59,5 +59,5 @@ panics, as does reading past the last argument. Variadic libc functions such as `printf` and `fcntl` are handled by [variadic rules](../rules/writing-rules.md#variadic-functions), whose bodies -receive the same `&[VaArg]` slice; `format_c` in the +receive the same `Box<[VaArg]>`; `format_c` in the [format module](./io.md#formatting) consumes one to evaluate a format string. diff --git a/libcc2rs/src/fn_ptr_arg.rs b/libcc2rs/src/fn_ptr_arg.rs index 621f8d27e..2dfdfb11c 100644 --- a/libcc2rs/src/fn_ptr_arg.rs +++ b/libcc2rs/src/fn_ptr_arg.rs @@ -9,6 +9,7 @@ use std::rc::Rc; use crate::rc::Ptr; use crate::reinterpret::ByteRepr; +use crate::va_args::VaArg; use crate::void::{AnyPtr, ErasedPtr}; pub enum ArgRepr { @@ -126,6 +127,16 @@ impl FnPtrArg for AnyPtr { } } +impl FnPtrArg for Box<[VaArg]> { + #[inline] + fn to_repr(self) -> ArgRepr { + ArgRepr::Record(Box::new(self)) + } + fn from_repr(r: ArgRepr) -> Self { + record_from_repr(r) + } +} + impl FnPtrArg for *mut T { #[inline] fn to_repr(self) -> ArgRepr { diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 355d7202b..b3f6ad797 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -3,7 +3,7 @@ use cfg_expr::Expression; use cfg_expr::expr::{Predicate, TargetPredicate}; -use ra_ap_syntax::ast::{HasAttrs, HasGenericParams, HasName, HasTypeBounds}; +use ra_ap_syntax::ast::{HasAttrs, HasGenericArgs, HasGenericParams, HasName, HasTypeBounds}; use ra_ap_syntax::{AstNode, SyntaxKind, ast, match_ast}; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; @@ -41,8 +41,13 @@ fn pointer_flags(ty: &ast::Type) -> (bool, bool) { } fn is_va_args_type(ty: &ast::Type) -> bool { - if let ast::Type::RefType(r) = ty - && let Some(ast::Type::SliceType(slice)) = r.ty() + if let ast::Type::PathType(boxed) = ty + && let Some(segment) = boxed.path().and_then(|p| p.segment()) + && segment.name_ref().is_some_and(|name| name.text() == "Box") + && let Some(ast::GenericArg::TypeArg(arg)) = segment + .generic_arg_list() + .and_then(|args| args.generic_args().next()) + && let Some(ast::Type::SliceType(slice)) = arg.ty() { return matches!(slice.ty(), Some(ast::Type::PathType(path)) if path diff --git a/rules/fcntl/tgt_refcount.rs b/rules/fcntl/tgt_refcount.rs index eb9d20389..4f2312376 100644 --- a/rules/fcntl/tgt_refcount.rs +++ b/rules/fcntl/tgt_refcount.rs @@ -3,7 +3,7 @@ use libcc2rs::*; -fn f1(a0: i32, a1: i32, va: &[VaArg]) -> i32 { +fn f1(a0: i32, a1: i32, va: Box<[VaArg]>) -> i32 { let __res = match a1 { ::libc::F_GETFL => FdRegistry::with_fd(a0, |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFL) @@ -34,7 +34,7 @@ fn f1(a0: i32, a1: i32, va: &[VaArg]) -> i32 { } } -fn f2(a0: Ptr, a1: i32, va: &[VaArg]) -> i32 { +fn f2(a0: Ptr, a1: i32, va: Box<[VaArg]>) -> i32 { let __mode = match va.first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), diff --git a/rules/ioctl/tgt_refcount.rs b/rules/ioctl/tgt_refcount.rs index 03c178933..0f66b6f84 100644 --- a/rules/ioctl/tgt_refcount.rs +++ b/rules/ioctl/tgt_refcount.rs @@ -3,7 +3,7 @@ use libcc2rs::*; -fn f1(a0: i32, a1: u64, va: &[VaArg]) -> i32 { +fn f1(a0: i32, a1: u64, va: Box<[VaArg]>) -> i32 { panic!( "ioctl is not supported in the refcount model (fd={}, request={}, varargs={})", a0, diff --git a/rules/stdio/tgt_refcount.rs b/rules/stdio/tgt_refcount.rs index 316d5e672..97f2c02be 100644 --- a/rules/stdio/tgt_refcount.rs +++ b/rules/stdio/tgt_refcount.rs @@ -161,8 +161,8 @@ fn f20(a0: i32, a1: Ptr) -> Ptr { Ptr::alloc(CFile::new(a0)) } -fn f21(a0: Ptr, a1: usize, a2: Ptr, va: &[VaArg]) -> i32 { - let __s = libcc2rs::format_c(&a2.to_rust_string(), va); +fn f21(a0: Ptr, a1: usize, a2: Ptr, va: Box<[VaArg]>) -> i32 { + let __s = libcc2rs::format_c(&a2.to_rust_string(), &va); let __b = __s.as_bytes(); if a1 > 0 { let __n = ::std::cmp::min(__b.len(), a1 - 1); @@ -190,12 +190,12 @@ fn f24(a0: Ptr, a1: Ptr, a2: i32, a3: usize) -> i32 { 0 } -fn f28(a0: Ptr, a1: Ptr, va: &[VaArg]) -> i32 { - let __s = libcc2rs::format_c(&a1.to_rust_string(), va); +fn f28(a0: Ptr, a1: Ptr, va: Box<[VaArg]>) -> i32 { + let __s = libcc2rs::format_c(&a1.to_rust_string(), &va); a0.with_mut(|__f| __f.write(__s.as_bytes())) as i32 } -fn f29(a0: Ptr, va: &[VaArg]) -> i32 { - let __s = libcc2rs::format_c(&a0.to_rust_string(), va); +fn f29(a0: Ptr, va: Box<[VaArg]>) -> i32 { + let __s = libcc2rs::format_c(&a0.to_rust_string(), &va); libcc2rs::c_stdout().with_mut(|__f| __f.write(__s.as_bytes())) as i32 } diff --git a/tests/ub/out/refcount/fd_double_close.rs b/tests/ub/out/refcount/fd_double_close.rs index 64738b0d5..08f3be322 100644 --- a/tests/ub/out/refcount/fd_double_close.rs +++ b/tests/ub/out/refcount/fd_double_close.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let mut fd: i32 = { - let __mode = match &[].first() { + let __mode = match Box::<[VaArg]>::from([]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/ub/out/refcount/fd_use_after_close.rs b/tests/ub/out/refcount/fd_use_after_close.rs index a81711288..89b28860b 100644 --- a/tests/ub/out/refcount/fd_use_after_close.rs +++ b/tests/ub/out/refcount/fd_use_after_close.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let mut fd: i32 = { - let __mode = match &[].first() { + let __mode = match Box::<[VaArg]>::from([]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/unit/out/refcount/fcntl.rs b/tests/unit/out/refcount/fcntl.rs index 9e7d871e8..8f7acf6b8 100644 --- a/tests/unit/out/refcount/fcntl.rs +++ b/tests/unit/out/refcount/fcntl.rs @@ -34,7 +34,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFL) }), ::libc::F_SETFL => { - let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFL(__flags)) }) @@ -43,7 +45,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFD) }), ::libc::F_SETFD => { - let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFD(__flags)) }) @@ -68,7 +72,7 @@ fn main_0() -> i32 { }), ::libc::F_SETFL => { let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get( - &&[(flags | ::libc::O_NONBLOCK).into()][0], + &Box::<[VaArg]>::from([(flags | ::libc::O_NONBLOCK).into()])[0], )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFL(__flags)) @@ -79,7 +83,7 @@ fn main_0() -> i32 { }), ::libc::F_SETFD => { let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get( - &&[(flags | ::libc::O_NONBLOCK).into()][0], + &Box::<[VaArg]>::from([(flags | ::libc::O_NONBLOCK).into()])[0], )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFD(__flags)) @@ -103,7 +107,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFL) }), ::libc::F_SETFL => { - let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFL(__flags)) }) @@ -112,7 +118,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFD) }), ::libc::F_SETFD => { - let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFD(__flags)) }) @@ -151,7 +159,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFL) }), ::libc::F_SETFL => { - let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFL(__flags)) }) @@ -160,7 +170,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFD) }), ::libc::F_SETFD => { - let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFD(__flags)) }) @@ -185,7 +197,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFL) }), ::libc::F_SETFL => { - let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get(&&[(1).into()][0])); + let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(1).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFL(__flags)) }) @@ -194,7 +208,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFD) }), ::libc::F_SETFD => { - let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get(&&[(1).into()][0])); + let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(1).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFD(__flags)) }) @@ -218,7 +234,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFL) }), ::libc::F_SETFL => { - let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::OFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFL(__flags)) }) @@ -227,7 +245,9 @@ fn main_0() -> i32 { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_GETFD) }), ::libc::F_SETFD => { - let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get(&&[(0).into()][0])); + let __flags = nix::fcntl::FdFlag::from_bits_retain(i32::get( + &Box::<[VaArg]>::from([(0).into()])[0], + )); FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { nix::fcntl::fcntl(__fd, nix::fcntl::FcntlArg::F_SETFD(__flags)) }) diff --git a/tests/unit/out/refcount/fd_io.rs b/tests/unit/out/refcount/fd_io.rs index babd5ce60..973a2a386 100644 --- a/tests/unit/out/refcount/fd_io.rs +++ b/tests/unit/out/refcount/fd_io.rs @@ -13,7 +13,7 @@ pub fn main() { fn main_0() -> i32 { let mut path: Ptr = Ptr::::from_string_literal(b"cpp2rust_fd_io_test.tmp"); let mut fd: i32 = { - let __mode = match &[(420).into()].first() { + let __mode = match Box::<[VaArg]>::from([(420).into()]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; @@ -49,7 +49,7 @@ fn main_0() -> i32 { ); assert!((((FdRegistry::close(fd) == 0) as i32) != 0)); fd = { - let __mode = match &[].first() { + let __mode = match Box::<[VaArg]>::from([]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/unit/out/refcount/fstat.rs b/tests/unit/out/refcount/fstat.rs index f54905e69..338384356 100644 --- a/tests/unit/out/refcount/fstat.rs +++ b/tests/unit/out/refcount/fstat.rs @@ -13,7 +13,7 @@ pub fn main() { fn main_0() -> i32 { let mut path: Ptr = Ptr::::from_string_literal(b"cpp2rust_fstat_test.tmp"); let mut fd: i32 = { - let __mode = match &[(420).into()].first() { + let __mode = match Box::<[VaArg]>::from([(420).into()]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/unit/out/refcount/isatty.rs b/tests/unit/out/refcount/isatty.rs index a4e92e24e..9be844289 100644 --- a/tests/unit/out/refcount/isatty.rs +++ b/tests/unit/out/refcount/isatty.rs @@ -13,7 +13,7 @@ pub fn main() { fn main_0() -> i32 { let mut path: Ptr = Ptr::::from_string_literal(b"cpp2rust_isatty_test.tmp"); let mut fd: i32 = { - let __mode = match &[(420).into()].first() { + let __mode = match Box::<[VaArg]>::from([(420).into()]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/unit/out/refcount/lseek_ftruncate.rs b/tests/unit/out/refcount/lseek_ftruncate.rs index 4a0e4aec7..92284d790 100644 --- a/tests/unit/out/refcount/lseek_ftruncate.rs +++ b/tests/unit/out/refcount/lseek_ftruncate.rs @@ -13,7 +13,7 @@ pub fn main() { fn main_0() -> i32 { let mut path: Ptr = Ptr::::from_string_literal(b"cpp2rust_lseek_ftruncate_test.tmp"); let mut fd: i32 = { - let __mode = match &[(420).into()].first() { + let __mode = match Box::<[VaArg]>::from([(420).into()]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/unit/out/refcount/printfs.rs b/tests/unit/out/refcount/printfs.rs index 564243d3e..fec81bd86 100644 --- a/tests/unit/out/refcount/printfs.rs +++ b/tests/unit/out/refcount/printfs.rs @@ -22,20 +22,23 @@ pub fn log_to_2(mut out: Ptr, mut fmt: Ptr, mut args_2: Ptr, mut { let __s = libcc2rs::format_c( &fmt.to_rust_string(), - &[((args_2).clone()).into(), (args_3).into()], + &Box::<[VaArg]>::from([((args_2).clone()).into(), (args_3).into()]), ); out.with_mut(|__f| __f.write(__s.as_bytes())) as i32 }; } pub fn log_to_3(mut out: Ptr, mut fmt: Ptr, mut args: i32) { { - let __s = libcc2rs::format_c(&fmt.to_rust_string(), &[(args).into()]); + let __s = libcc2rs::format_c( + &fmt.to_rust_string(), + &Box::<[VaArg]>::from([(args).into()]), + ); out.with_mut(|__f| __f.write(__s.as_bytes())) as i32 }; } pub fn log_fmt_4(mut fmt: Ptr, mut v: i32) { { - let __s = libcc2rs::format_c(&fmt.to_rust_string(), &[(v).into()]); + let __s = libcc2rs::format_c(&fmt.to_rust_string(), &Box::<[VaArg]>::from([(v).into()])); libcc2rs::c_stdout().with_mut(|__f| __f.write(__s.as_bytes())) as i32 }; } diff --git a/tests/unit/out/refcount/snprintf.rs b/tests/unit/out/refcount/snprintf.rs index f309f7a26..394c51a0e 100644 --- a/tests/unit/out/refcount/snprintf.rs +++ b/tests/unit/out/refcount/snprintf.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"x=%d y=%u").to_rust_string(), - &[(-3_i32).into(), (7_u32).into()], + &Box::<[VaArg]>::from([(-3_i32).into(), (7_u32).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -49,7 +49,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%s").to_rust_string(), - &[(Ptr::::from_string_literal(b"hello")).into()], + &Box::<[VaArg]>::from([(Ptr::::from_string_literal(b"hello")).into()]), ); let __b = __s.as_bytes(); if 4_usize > 0 { @@ -82,7 +82,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%05d|%x|%X").to_rust_string(), - &[(42).into(), (255).into(), (255).into()], + &Box::<[VaArg]>::from([(42).into(), (255).into(), (255).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -115,7 +115,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%.2f").to_rust_string(), - &[(3.14159_f64).into()], + &Box::<[VaArg]>::from([(3.14159_f64).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -148,7 +148,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%-6s|").to_rust_string(), - &[(Ptr::::from_string_literal(b"ab")).into()], + &Box::<[VaArg]>::from([(Ptr::::from_string_literal(b"ab")).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -181,7 +181,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%c%%").to_rust_string(), - &[(65).into()], + &Box::<[VaArg]>::from([(65).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -214,7 +214,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%+d % d").to_rust_string(), - &[(5).into(), (5).into()], + &Box::<[VaArg]>::from([(5).into(), (5).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -247,7 +247,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%ld %lu %zu").to_rust_string(), - &[(-1_i64).into(), (1_u64).into(), (9 as usize).into()], + &Box::<[VaArg]>::from([(-1_i64).into(), (1_u64).into(), (9 as usize).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -280,7 +280,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%e").to_rust_string(), - &[(1234.5678_f64).into()], + &Box::<[VaArg]>::from([(1234.5678_f64).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -313,7 +313,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%g").to_rust_string(), - &[(1234567_f64).into()], + &Box::<[VaArg]>::from([(1234567_f64).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { @@ -347,7 +347,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &Ptr::::from_string_literal(b"%d").to_rust_string(), - &[(123).into()], + &Box::<[VaArg]>::from([(123).into()]), ); let __b = __s.as_bytes(); if 0_usize > 0 { @@ -371,7 +371,7 @@ fn main_0() -> i32 { ((({ let __s = libcc2rs::format_c( &(fmt.as_pointer() as Ptr).to_rust_string(), - &[(3.26_f64).into()], + &Box::<[VaArg]>::from([(3.26_f64).into()]), ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[i8; 32]>() > 0 { diff --git a/tests/unit/out/refcount/termios.rs b/tests/unit/out/refcount/termios.rs index 7a9e842eb..71d729b70 100644 --- a/tests/unit/out/refcount/termios.rs +++ b/tests/unit/out/refcount/termios.rs @@ -13,7 +13,7 @@ pub fn main() { fn main_0() -> i32 { let mut path: Ptr = Ptr::::from_string_literal(b"cpp2rust_termios_test.tmp"); let mut fd: i32 = { - let __mode = match &[(420).into()].first() { + let __mode = match Box::<[VaArg]>::from([(420).into()]).first() { Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), None => nix::sys::stat::Mode::empty(), }; diff --git a/tests/unit/out/refcount/va_arg_chain.rs b/tests/unit/out/refcount/va_arg_chain.rs index c6d738694..afe6b1c57 100644 --- a/tests/unit/out/refcount/va_arg_chain.rs +++ b/tests/unit/out/refcount/va_arg_chain.rs @@ -19,7 +19,7 @@ pub fn middle_layer_1(mut n: i32, ap: Ptr) -> i32 { let ap: Value> = Rc::new(RefCell::new(ap)); return ({ extract_nth_0(n, (*ap.borrow()).clone()) }); } -pub fn top_level_2(n: i32, __args: &[VaArg]) -> i32 { +pub fn top_level_2(n: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -34,13 +34,21 @@ pub fn main() { fn main_0() -> i32 { assert!( (((({ - top_level_2(2, &[(100).into(), (200).into(), (300).into(), (400).into()]) + top_level_2( + 2, + Box::new([(100).into(), (200).into(), (300).into(), (400).into()]), + ) }) == 300) as i32) != 0) ); - assert!((((({ top_level_2(0, &[(42).into(), (99).into(),]) }) == 42) as i32) != 0)); + assert!((((({ top_level_2(0, Box::new([(42).into(), (99).into(),])) }) == 42) as i32) != 0)); assert!( - (((({ top_level_2(3, &[(1).into(), (2).into(), (3).into(), (4).into(),]) }) == 4) as i32) + (((({ + top_level_2( + 3, + Box::new([(1).into(), (2).into(), (3).into(), (4).into()]), + ) + }) == 4) as i32) != 0) ); return 0; diff --git a/tests/unit/out/refcount/va_arg_concat.rs b/tests/unit/out/refcount/va_arg_concat.rs index 02efefa8c..07df98448 100644 --- a/tests/unit/out/refcount/va_arg_concat.rs +++ b/tests/unit/out/refcount/va_arg_concat.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn sum_ints_0(first: i32, __args: &[VaArg]) -> i32 { +pub fn sum_ints_0(first: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let first: Value = Rc::new(RefCell::new(first)); let args: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -29,15 +29,20 @@ pub fn main() { } fn main_0() -> i32 { assert!( - (((({ sum_ints_0(1, &[(2).into(), (3).into(), (4).into(), (0).into(),]) }) == 10) as i32) + (((({ + sum_ints_0( + 1, + Box::new([(2).into(), (3).into(), (4).into(), (0).into()]), + ) + }) == 10) as i32) != 0) ); - assert!((((({ sum_ints_0(100, &[(0).into(),]) }) == 100) as i32) != 0)); + assert!((((({ sum_ints_0(100, Box::new([(0).into(),])) }) == 100) as i32) != 0)); assert!( (((({ sum_ints_0( 5, - &[(5).into(), (5).into(), (5).into(), (5).into(), (0).into()], + Box::new([(5).into(), (5).into(), (5).into(), (5).into(), (0).into()]), ) }) == 25) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_conditional.rs b/tests/unit/out/refcount/va_arg_conditional.rs index d514efe14..1ef8ca713 100644 --- a/tests/unit/out/refcount/va_arg_conditional.rs +++ b/tests/unit/out/refcount/va_arg_conditional.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn conditional_log_0(mut verbose: i32, fmt: Ptr, __args: &[VaArg]) -> i32 { +pub fn conditional_log_0(mut verbose: i32, fmt: Ptr, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); if (verbose != 0) { @@ -23,13 +23,23 @@ pub fn main() { } fn main_0() -> i32 { assert!( - (((({ conditional_log_0(1, Ptr::::from_string_literal(b"%d"), &[(42).into(),]) }) == 42) - as i32) + (((({ + conditional_log_0( + 1, + Ptr::::from_string_literal(b"%d"), + Box::new([(42).into()]), + ) + }) == 42) as i32) != 0) ); assert!( - (((({ conditional_log_0(0, Ptr::::from_string_literal(b"%d"), &[(99).into(),]) }) - == -1_i32) as i32) + (((({ + conditional_log_0( + 0, + Ptr::::from_string_literal(b"%d"), + Box::new([(99).into()]), + ) + }) == -1_i32) as i32) != 0) ); return 0; diff --git a/tests/unit/out/refcount/va_arg_copy.rs b/tests/unit/out/refcount/va_arg_copy.rs index 2aabfaf04..e30b5edf4 100644 --- a/tests/unit/out/refcount/va_arg_copy.rs +++ b/tests/unit/out/refcount/va_arg_copy.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn sum_with_copy_0(count: i32, __args: &[VaArg]) -> i32 { +pub fn sum_with_copy_0(count: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -34,7 +34,8 @@ pub fn main() { } fn main_0() -> i32 { assert!( - (((({ sum_with_copy_0(3, &[(10).into(), (20).into(), (30).into(),]) }) == 120) as i32) + (((({ sum_with_copy_0(3, Box::new([(10).into(), (20).into(), (30).into(),])) }) == 120) + as i32) != 0) ); return 0; diff --git a/tests/unit/out/refcount/va_arg_fn_ptr.rs b/tests/unit/out/refcount/va_arg_fn_ptr.rs index b5945c798..a9a81d2e6 100644 --- a/tests/unit/out/refcount/va_arg_fn_ptr.rs +++ b/tests/unit/out/refcount/va_arg_fn_ptr.rs @@ -15,7 +15,7 @@ pub fn negate_1(mut x: i32) -> i32 { pub fn add_2(mut a: i32, mut b: i32) -> i32 { return (a + b); } -pub fn apply_unary_3(x: i32, __args: &[VaArg]) -> i32 { +pub fn apply_unary_3(x: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let x: Value = Rc::new(RefCell::new(x)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -24,7 +24,7 @@ pub fn apply_unary_3(x: i32, __args: &[VaArg]) -> i32 { let mut result: i32 = ({ fn_.call((*x.borrow())) }); return result; } -pub fn apply_binary_4(mut a: i32, b: i32, __args: &[VaArg]) -> i32 { +pub fn apply_binary_4(mut a: i32, b: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let b: Value = Rc::new(RefCell::new(b)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -46,18 +46,31 @@ pub fn main() { } fn main_0() -> i32 { assert!( - (((({ apply_unary_3(5, &[(FnPtr:: i32>::new(square_0)).into(),]) }) == 25) - as i32) + (((({ + apply_unary_3( + 5, + Box::new([(FnPtr:: i32>::new(square_0)).into()]), + ) + }) == 25) as i32) != 0) ); assert!( - (((({ apply_unary_3(7, &[(FnPtr:: i32>::new(negate_1)).into(),]) }) == -7_i32) - as i32) + (((({ + apply_unary_3( + 7, + Box::new([(FnPtr:: i32>::new(negate_1)).into()]), + ) + }) == -7_i32) as i32) != 0) ); assert!( - (((({ apply_binary_4(3, 4, &[(FnPtr:: i32>::new(add_2)).into(),]) }) == 7) - as i32) + (((({ + apply_binary_4( + 3, + 4, + Box::new([(FnPtr:: i32>::new(add_2)).into()]), + ) + }) == 7) as i32) != 0) ); let dummy: Value = Rc::new(RefCell::new(0)); @@ -69,6 +82,30 @@ fn main_0() -> i32 { }) == -3_i32) as i32) != 0) ); + let mut vu: FnPtr) -> i32> = + FnPtr::) -> i32>::new(apply_unary_3); + assert!( + (((({ + vu.call( + 6, + Box::new([(FnPtr:: i32>::new(square_0)).into()]), + ) + }) == 36) as i32) + != 0) + ); + let mut vb: FnPtr) -> i32> = + FnPtr::) -> i32>::new(apply_unary_3) + .cast::) -> i32>(); + vu = vb.cast::) -> i32>(); + assert!( + (((({ + vu.call( + 2, + Box::new([(FnPtr:: i32>::new(negate_1)).into()]), + ) + }) == -2_i32) as i32) + != 0) + ); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/va_arg_forward.rs b/tests/unit/out/refcount/va_arg_forward.rs index 26265a108..3c35034cc 100644 --- a/tests/unit/out/refcount/va_arg_forward.rs +++ b/tests/unit/out/refcount/va_arg_forward.rs @@ -16,7 +16,7 @@ pub fn inner_0(mut count: i32, ap: Ptr) -> i32 { } return total; } -pub fn outer_1(count: i32, __args: &[VaArg]) -> i32 { +pub fn outer_1(count: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -29,9 +29,12 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - assert!((((({ outer_1(3, &[(10).into(), (20).into(), (30).into(),]) }) == 60) as i32) != 0)); - assert!((((({ outer_1(1, &[(42).into(),]) }) == 42) as i32) != 0)); - assert!((((({ outer_1(0, &[]) }) == 0) as i32) != 0)); + assert!( + (((({ outer_1(3, Box::new([(10).into(), (20).into(), (30).into(),])) }) == 60) as i32) + != 0) + ); + assert!((((({ outer_1(1, Box::new([(42).into(),])) }) == 42) as i32) != 0)); + assert!((((({ outer_1(0, Box::new([])) }) == 0) as i32) != 0)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs index e312c7d3c..f567cbc0a 100644 --- a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn mixed_args_0(count: i32, __args: &[VaArg]) -> i32 { +pub fn mixed_args_0(count: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -35,22 +35,30 @@ fn main_0() -> i32 { (((({ mixed_args_0( 3, - &[ + Box::new([ (0).into(), (10).into(), (1).into(), (x.as_pointer()).into(), (0).into(), (20).into(), - ], + ]), ) }) == 130) as i32) != 0) ); let y: Value = Rc::new(RefCell::new(50)); - assert!((((({ mixed_args_0(1, &[(1).into(), (y.as_pointer()).into(),]) }) == 50) as i32) != 0)); assert!( - (((({ mixed_args_0(2, &[(0).into(), (5).into(), (0).into(), (3).into(),]) }) == 8) as i32) + (((({ mixed_args_0(1, Box::new([(1).into(), (y.as_pointer()).into(),])) }) == 50) as i32) + != 0) + ); + assert!( + (((({ + mixed_args_0( + 2, + Box::new([(0).into(), (5).into(), (0).into(), (3).into()]), + ) + }) == 8) as i32) != 0) ); return 0; diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 41142abdc..629919a33 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -14,7 +14,7 @@ pub struct pair { #[offset(4)] pub b: i32, } -pub fn sum_mixed_0(count: i32, __args: &[VaArg]) -> i32 { +pub fn sum_mixed_0(count: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -47,24 +47,24 @@ fn main_0() -> i32 { (((({ sum_mixed_0( 3, - &[ + Box::new([ (0).into(), (10).into(), (1).into(), (20.5_f64).into(), (2).into(), (30_i64).into(), - ], + ]), ) }) == 60) as i32) != 0) ); - assert!((((({ sum_mixed_0(1, &[(0).into(), (42).into(),]) }) == 42) as i32) != 0)); + assert!((((({ sum_mixed_0(1, Box::new([(0).into(), (42).into(),])) }) == 42) as i32) != 0)); assert!( (((({ sum_mixed_0( 2, - &[(1).into(), (3.7_f64).into(), (2).into(), (100_i64).into()], + Box::new([(1).into(), (3.7_f64).into(), (2).into(), (100_i64).into()]), ) }) == 103) as i32) != 0) @@ -74,7 +74,7 @@ fn main_0() -> i32 { (((({ sum_mixed_0( 2, - &[(3).into(), ((p).clone()).into(), (0).into(), (5).into()], + Box::new([(3).into(), ((p).clone()).into(), (0).into(), (5).into()]), ) }) == 61) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs index 8e8237ade..fb380c3e6 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -20,7 +20,7 @@ pub const opt_OPT_STRING_OUT: opt = 0; pub const opt_OPT_FILE: opt = 1; pub const opt_OPT_NODE: opt = 2; pub const opt_OPT_NODE_OUT: opt = 3; -pub fn dispatch_0(option: i32, __args: &[VaArg]) -> i32 { +pub fn dispatch_0(option: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let option: Value = Rc::new(RefCell::new(option)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -62,21 +62,29 @@ pub fn main() { fn main_0() -> i32 { let s: Value> = Rc::new(RefCell::new(Ptr::::null())); assert!( - (((({ dispatch_0((opt_OPT_STRING_OUT as i32), &[(s.as_pointer()).into(),]) }) == 1) - as i32) + (((({ + dispatch_0( + (opt_OPT_STRING_OUT as i32), + Box::new([(s.as_pointer()).into()]), + ) + }) == 1) as i32) != 0) ); assert!((((!((*s.borrow()).is_null())) as i32) != 0)); assert!( - (((({ dispatch_0((opt_OPT_FILE as i32), &[(libcc2rs::c_stdout()).into(),]) }) == 1) - as i32) + (((({ + dispatch_0( + (opt_OPT_FILE as i32), + Box::new([(libcc2rs::c_stdout()).into()]), + ) + }) == 1) as i32) != 0) ); assert!( (((({ dispatch_0( (opt_OPT_FILE as i32), - &[((AnyPtr::default()).reinterpret_cast::()).into()], + Box::new([((AnyPtr::default()).reinterpret_cast::()).into()]), ) }) == 0) as i32) != 0) @@ -86,13 +94,22 @@ fn main_0() -> i32 { next: Ptr::::null(), })); assert!( - (((({ dispatch_0((opt_OPT_NODE as i32), &[(head.as_pointer()).into(),]) }) == 42) as i32) + (((({ + dispatch_0( + (opt_OPT_NODE as i32), + Box::new([(head.as_pointer()).into()]), + ) + }) == 42) as i32) != 0) ); let outp: Value> = Rc::new(RefCell::new((head.as_pointer()))); assert!( - (((({ dispatch_0((opt_OPT_NODE_OUT as i32), &[(outp.as_pointer()).into(),]) }) == 2) - as i32) + (((({ + dispatch_0( + (opt_OPT_NODE_OUT as i32), + Box::new([(outp.as_pointer()).into()]), + ) + }) == 2) as i32) != 0) ); assert!(((((*outp.borrow()).is_null()) as i32) != 0)); diff --git a/tests/unit/out/refcount/va_arg_null_int_ptr.rs b/tests/unit/out/refcount/va_arg_null_int_ptr.rs index 0db9d3745..f6d89bc6d 100644 --- a/tests/unit/out/refcount/va_arg_null_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_null_int_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn first_nonnull_0(count: i32, __args: &[VaArg]) -> i32 { +pub fn first_nonnull_0(count: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -30,24 +30,31 @@ pub fn main() { fn main_0() -> i32 { let x: Value = Rc::new(RefCell::new(42)); assert!( - (((({ first_nonnull_0(2, &[(AnyPtr::default()).into(), (x.as_pointer()).into(),]) }) == 42) - as i32) + (((({ + first_nonnull_0( + 2, + Box::new([(AnyPtr::default()).into(), (x.as_pointer()).into()]), + ) + }) == 42) as i32) != 0) ); assert!( (((({ first_nonnull_0( 3, - &[ + Box::new([ (AnyPtr::default()).into(), (AnyPtr::default()).into(), (x.as_pointer()).into(), - ], + ]), ) }) == 42) as i32) != 0) ); - assert!((((({ first_nonnull_0(1, &[(AnyPtr::default()).into(),]) }) == -1_i32) as i32) != 0)); + assert!( + (((({ first_nonnull_0(1, Box::new([(AnyPtr::default()).into(),])) }) == -1_i32) as i32) + != 0) + ); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/va_arg_printf.rs b/tests/unit/out/refcount/va_arg_printf.rs index 03c6ababb..78296cbca 100644 --- a/tests/unit/out/refcount/va_arg_printf.rs +++ b/tests/unit/out/refcount/va_arg_printf.rs @@ -11,7 +11,7 @@ pub fn logf_impl_0(mut fmt: Ptr, ap: Ptr) -> i32 { &(fmt); return ({ (*ap.borrow_mut()).arg::() } + { (*ap.borrow_mut()).arg::() }); } -pub fn logf_1(fmt: Ptr, __args: &[VaArg]) -> i32 { +pub fn logf_1(fmt: Ptr, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -19,7 +19,7 @@ pub fn logf_1(fmt: Ptr, __args: &[VaArg]) -> i32 { let mut result: i32 = ({ logf_impl_0((*fmt.borrow()).clone(), (*ap.borrow()).clone()) }); return result; } -pub fn lenf_2(fmt: Ptr, __args: &[VaArg]) -> i32 { +pub fn lenf_2(fmt: Ptr, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -38,7 +38,7 @@ fn main_0() -> i32 { (((({ logf_1( Ptr::::from_string_literal(b"hello %d %d"), - &[(10).into(), (dummy.to_c_string_iterator().count()).into()], + Box::new([(10).into(), (dummy.to_c_string_iterator().count()).into()]), ) }) == 15) as i32) != 0) @@ -47,7 +47,7 @@ fn main_0() -> i32 { (((({ logf_1( Ptr::::from_string_literal(b"x %d %d"), - &[(1).into(), (2).into()], + Box::new([(1).into(), (2).into()]), ) }) == 3) as i32) != 0) @@ -56,7 +56,7 @@ fn main_0() -> i32 { (((({ lenf_2( Ptr::::from_string_literal(b"%s"), - &[((dummy).clone()).into()], + Box::new([((dummy).clone()).into()]), ) }) == 5) as i32) != 0) @@ -65,12 +65,12 @@ fn main_0() -> i32 { (((({ lenf_2( Ptr::::from_string_literal(b"%s"), - &[(if (((elem!(dummy, 0).read()) as i32) != 0) { + Box::new([(if (((elem!(dummy, 0).read()) as i32) != 0) { (dummy).clone() } else { Ptr::::from_string_literal(b"") }) - .into()], + .into()]), ) }) == 5) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_promotion.rs b/tests/unit/out/refcount/va_arg_promotion.rs index 2c6adf40b..a568cd23b 100644 --- a/tests/unit/out/refcount/va_arg_promotion.rs +++ b/tests/unit/out/refcount/va_arg_promotion.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn test_promotions_0(count: i32, __args: &[VaArg]) -> i32 { +pub fn test_promotions_0(count: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -31,7 +31,7 @@ fn main_0() -> i32 { (((({ test_promotions_0( 3, - &[(x as i32).into(), (y as i32).into(), (z as f64).into()], + Box::new([(x as i32).into(), (y as i32).into(), (z as f64).into()]), ) }) == 78) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_snprintf.rs b/tests/unit/out/refcount/va_arg_snprintf.rs index c9885c375..df966c5a4 100644 --- a/tests/unit/out/refcount/va_arg_snprintf.rs +++ b/tests/unit/out/refcount/va_arg_snprintf.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn extract_first_0(mut buf: Ptr, mut size: i32, fmt: Ptr, __args: &[VaArg]) -> i32 { +pub fn extract_first_0(mut buf: Ptr, mut size: i32, fmt: Ptr, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -27,7 +27,7 @@ fn main_0() -> i32 { (buf.as_pointer() as Ptr), 1, Ptr::::from_string_literal(b"%d"), - &[(42).into()], + Box::new([(42).into()]), ) }) == 42) as i32) != 0) @@ -39,7 +39,7 @@ fn main_0() -> i32 { (buf.as_pointer() as Ptr), 1, Ptr::::from_string_literal(b"%d"), - &[(65).into()], + Box::new([(65).into()]), ) }) == 65) as i32) != 0) diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index 410332747..1dd1e22ec 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -14,7 +14,7 @@ pub struct context { #[offset(4)] pub last_error: i32, } -pub fn set_error_0(mut ctx: Ptr, fmt: Ptr, __args: &[VaArg]) { +pub fn set_error_0(mut ctx: Ptr, fmt: Ptr, __args: Box<[VaArg]>) { let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); if (ctx.with(|__s| __s.verbose) != 0) { @@ -46,7 +46,7 @@ impl Default for value { } } } -pub fn pick_1(use_long: i32, __args: &[VaArg]) -> i64 { +pub fn pick_1(use_long: i32, __args: Box<[VaArg]>) -> i64 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let use_long: Value = Rc::new(RefCell::new(use_long)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -69,7 +69,7 @@ fn main_0() -> i32 { set_error_0( (ctx.as_pointer()), Ptr::::from_string_literal(b"error %d"), - &[(42).into()], + Box::new([(42).into()]), ) }); assert!(((({ (*ctx.borrow()).last_error } == 42) as i32) != 0)); @@ -78,15 +78,20 @@ fn main_0() -> i32 { set_error_0( (ctx.as_pointer()), Ptr::::from_string_literal(b"error %d"), - &[(99).into()], + Box::new([(99).into()]), ) }); assert!(((({ (*ctx.borrow()).last_error } == 42) as i32) != 0)); let v: Value = >::default(); value::l(v.as_pointer()).write((1_i64 << 40)); - assert!((((({ pick_1(1, &[((*v.borrow()).clone()).into(),]) }) == (1_i64 << 40)) as i32) != 0)); + assert!( + (((({ pick_1(1, Box::new([((*v.borrow()).clone()).into(),])) }) == (1_i64 << 40)) as i32) + != 0) + ); value::i(v.as_pointer()).write(7); - assert!((((({ pick_1(0, &[((*v.borrow()).clone()).into(),]) }) == 7_i64) as i32) != 0)); + assert!( + (((({ pick_1(0, Box::new([((*v.borrow()).clone()).into(),])) }) == 7_i64) as i32) != 0) + ); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/va_arg_two_passes.rs b/tests/unit/out/refcount/va_arg_two_passes.rs index 1e9f8e86f..4bb356d63 100644 --- a/tests/unit/out/refcount/va_arg_two_passes.rs +++ b/tests/unit/out/refcount/va_arg_two_passes.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn sum_then_product_0(first: i32, __args: &[VaArg]) -> i32 { +pub fn sum_then_product_0(first: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let first: Value = Rc::new(RefCell::new(first)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -39,7 +39,9 @@ pub fn main() { } fn main_0() -> i32 { assert!( - (((({ sum_then_product_0(2, &[(3).into(), (4).into(), (0).into(),]) }) == 33) as i32) != 0) + (((({ sum_then_product_0(2, Box::new([(3).into(), (4).into(), (0).into(),])) }) == 33) + as i32) + != 0) ); return 0; } diff --git a/tests/unit/out/refcount/va_arg_void_ptr.rs b/tests/unit/out/refcount/va_arg_void_ptr.rs index 2f311d552..33785ef7e 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.rs @@ -18,7 +18,7 @@ pub struct registry { pub type field = u32; pub const field_FIELD_SLOT: field = 0; pub const field_FIELD_LEVEL: field = 1; -pub fn registry_update_0(mut r: Ptr, field: field, __args: &[VaArg]) -> i32 { +pub fn registry_update_0(mut r: Ptr, field: field, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let field: Value = Rc::new(RefCell::new(field)); let mut result: i32 = 0; @@ -59,14 +59,19 @@ fn main_0() -> i32 { registry_update_0( (r.as_pointer()), field_FIELD_SLOT, - &[(payload.as_pointer()).into()], + Box::new([(payload.as_pointer()).into()]), ) }) == 0) as i32) != 0) ); assert!( - (((({ registry_update_0((r.as_pointer()), field_FIELD_LEVEL, &[(5_i64).into(),]) }) == 0) - as i32) + (((({ + registry_update_0( + (r.as_pointer()), + field_FIELD_LEVEL, + Box::new([(5_i64).into()]), + ) + }) == 0) as i32) != 0) ); assert!( diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 1f7f1e5a4..cd06e88e1 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn sum_0(n: i32, __args: &[VaArg]) -> i32 { +pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -38,7 +38,7 @@ impl Guard_1 { } } } -pub fn sum_ptr_2(n: i32, __args: &[VaArg]) -> i32 { +pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); @@ -66,8 +66,8 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - assert!((({ sum_0(3, &[(1).into(), (2).into(), (3).into(),]) }) == 6)); - assert!((({ sum_ptr_2(2, &[(4).into(), (5).into(),]) }) == 9)); + assert!((({ sum_0(3, Box::new([(1).into(), (2).into(), (3).into(),])) }) == 6)); + assert!((({ sum_ptr_2(2, Box::new([(4).into(), (5).into(),])) }) == 9)); return 0; } pub trait Guard_1Impl { diff --git a/tests/unit/out/unsafe/va_arg_chain.rs b/tests/unit/out/unsafe/va_arg_chain.rs index 0f1b373b1..a7ef2273a 100644 --- a/tests/unit/out/unsafe/va_arg_chain.rs +++ b/tests/unit/out/unsafe/va_arg_chain.rs @@ -17,7 +17,7 @@ pub unsafe fn extract_nth_0(mut n: i32, mut ap: *const VaArg) -> i32 { pub unsafe fn middle_layer_1(mut n: i32, mut ap: *const VaArg) -> i32 { return (unsafe { extract_nth_0(n, ap) }); } -pub unsafe fn top_level_2(mut n: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn top_level_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut result: i32 = (unsafe { middle_layer_1(n, ap) }); @@ -32,14 +32,24 @@ pub fn main() { unsafe fn main_0() -> i32 { assert!( ((((unsafe { - top_level_2(2, &[(100).into(), (200).into(), (300).into(), (400).into()]) + top_level_2( + 2, + Box::new([(100).into(), (200).into(), (300).into(), (400).into()]), + ) }) == (300)) as i32) != 0) ); - assert!(((((unsafe { top_level_2(0, &[(42).into(), (99).into(),]) }) == (42)) as i32) != 0)); assert!( - ((((unsafe { top_level_2(3, &[(1).into(), (2).into(), (3).into(), (4).into(),]) }) == (4)) - as i32) + ((((unsafe { top_level_2(0, Box::new([(42).into(), (99).into(),])) }) == (42)) as i32) + != 0) + ); + assert!( + ((((unsafe { + top_level_2( + 3, + Box::new([(1).into(), (2).into(), (3).into(), (4).into()]), + ) + }) == (4)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/unsafe/va_arg_concat.rs b/tests/unit/out/unsafe/va_arg_concat.rs index 41bba3cb5..58a3fef55 100644 --- a/tests/unit/out/unsafe/va_arg_concat.rs +++ b/tests/unit/out/unsafe/va_arg_concat.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn sum_ints_0(mut first: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn sum_ints_0(mut first: i32, __args: Box<[VaArg]>) -> i32 { let mut args: *const VaArg = ::std::ptr::null(); let mut total: i32 = first; args = __args.as_ptr(); @@ -29,16 +29,20 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!( - ((((unsafe { sum_ints_0(1, &[(2).into(), (3).into(), (4).into(), (0).into(),]) }) == (10)) - as i32) + ((((unsafe { + sum_ints_0( + 1, + Box::new([(2).into(), (3).into(), (4).into(), (0).into()]), + ) + }) == (10)) as i32) != 0) ); - assert!(((((unsafe { sum_ints_0(100, &[(0).into(),]) }) == (100)) as i32) != 0)); + assert!(((((unsafe { sum_ints_0(100, Box::new([(0).into(),])) }) == (100)) as i32) != 0)); assert!( ((((unsafe { sum_ints_0( 5, - &[(5).into(), (5).into(), (5).into(), (5).into(), (0).into()], + Box::new([(5).into(), (5).into(), (5).into(), (5).into(), (0).into()]), ) }) == (25)) as i32) != 0) diff --git a/tests/unit/out/unsafe/va_arg_conditional.rs b/tests/unit/out/unsafe/va_arg_conditional.rs index 2baf70b2d..734fc7ffd 100644 --- a/tests/unit/out/unsafe/va_arg_conditional.rs +++ b/tests/unit/out/unsafe/va_arg_conditional.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub unsafe fn conditional_log_0( mut verbose: i32, mut fmt: *const libc::c_char, - __args: &[VaArg], + __args: Box<[VaArg]>, ) -> i32 { if (verbose != 0) { let mut ap: *const VaArg = ::std::ptr::null(); @@ -28,13 +28,21 @@ pub fn main() { unsafe fn main_0() -> i32 { assert!( ((((unsafe { - conditional_log_0(1, (c"%d".as_ptr().cast_mut()).cast_const(), &[(42).into()]) + conditional_log_0( + 1, + (c"%d".as_ptr().cast_mut()).cast_const(), + Box::new([(42).into()]), + ) }) == (42)) as i32) != 0) ); assert!( ((((unsafe { - conditional_log_0(0, (c"%d".as_ptr().cast_mut()).cast_const(), &[(99).into()]) + conditional_log_0( + 0, + (c"%d".as_ptr().cast_mut()).cast_const(), + Box::new([(99).into()]), + ) }) == (-1_i32)) as i32) != 0) ); diff --git a/tests/unit/out/unsafe/va_arg_copy.rs b/tests/unit/out/unsafe/va_arg_copy.rs index 5025b1629..e9354f571 100644 --- a/tests/unit/out/unsafe/va_arg_copy.rs +++ b/tests/unit/out/unsafe/va_arg_copy.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn sum_with_copy_0(mut count: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn sum_with_copy_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); let mut aq: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); @@ -34,8 +34,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!( - ((((unsafe { sum_with_copy_0(3, &[(10).into(), (20).into(), (30).into(),]) }) == (120)) - as i32) + ((((unsafe { sum_with_copy_0(3, Box::new([(10).into(), (20).into(), (30).into(),])) }) + == (120)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/unsafe/va_arg_fn_ptr.rs b/tests/unit/out/unsafe/va_arg_fn_ptr.rs index 789263519..32fc0b729 100644 --- a/tests/unit/out/unsafe/va_arg_fn_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_fn_ptr.rs @@ -15,7 +15,7 @@ pub unsafe fn negate_1(mut x: i32) -> i32 { pub unsafe fn add_2(mut a: i32, mut b: i32) -> i32 { return ((a) + (b)); } -pub unsafe fn apply_unary_3(mut x: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn apply_unary_3(mut x: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut fn_: Option i32> = std::mem::transmute::< @@ -25,7 +25,7 @@ pub unsafe fn apply_unary_3(mut x: i32, __args: &[VaArg]) -> i32 { let mut result: i32 = (unsafe { (fn_).unwrap()(x) }); return result; } -pub unsafe fn apply_binary_4(mut a: i32, mut b: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn apply_binary_4(mut a: i32, mut b: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut fn_: Option i32> = std::mem::transmute::< @@ -56,10 +56,9 @@ unsafe fn main_0() -> i32 { ((((unsafe { apply_unary_3( 5, - &[ - (Some(square_0).map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) - .into(), - ], + Box::new([(Some(square_0) + .map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) + .into()]), ) }) == (25)) as i32) != 0) @@ -68,10 +67,9 @@ unsafe fn main_0() -> i32 { ((((unsafe { apply_unary_3( 7, - &[ - (Some(negate_1).map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) - .into(), - ], + Box::new([(Some(negate_1) + .map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) + .into()]), ) }) == (-7_i32)) as i32) != 0) @@ -81,10 +79,9 @@ unsafe fn main_0() -> i32 { apply_binary_4( 3, 4, - &[ - (Some(add_2).map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) - .into(), - ], + Box::new([(Some(add_2) + .map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) + .into()]), ) }) == (7)) as i32) != 0) @@ -98,6 +95,37 @@ unsafe fn main_0() -> i32 { }) == (-3_i32)) as i32) != 0) ); + let mut vu: Option) -> i32> = Some(apply_unary_3); + assert!( + ((((unsafe { + (vu).unwrap()( + 6, + Box::new([(Some(square_0) + .map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) + .into()]), + ) + }) == (36)) as i32) + != 0) + ); + let mut vb: Option) -> i32> = std::mem::transmute::< + Option) -> i32>, + Option) -> i32>, + >(Some(apply_unary_3)); + vu = std::mem::transmute::< + Option) -> i32>, + Option) -> i32>, + >(vb); + assert!( + ((((unsafe { + (vu).unwrap()( + 2, + Box::new([(Some(negate_1) + .map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)) + .into()]), + ) + }) == (-2_i32)) as i32) + != 0) + ); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/va_arg_forward.rs b/tests/unit/out/unsafe/va_arg_forward.rs index bccf0d8fc..3e27a0cbb 100644 --- a/tests/unit/out/unsafe/va_arg_forward.rs +++ b/tests/unit/out/unsafe/va_arg_forward.rs @@ -15,7 +15,7 @@ pub unsafe fn inner_0(mut count: i32, mut ap: *const VaArg) -> i32 { } return total; } -pub unsafe fn outer_1(mut count: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn outer_1(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut result: i32 = (unsafe { inner_0(count, ap) }); @@ -29,11 +29,12 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!( - ((((unsafe { outer_1(3, &[(10).into(), (20).into(), (30).into(),]) }) == (60)) as i32) + ((((unsafe { outer_1(3, Box::new([(10).into(), (20).into(), (30).into(),])) }) == (60)) + as i32) != 0) ); - assert!(((((unsafe { outer_1(1, &[(42).into(),]) }) == (42)) as i32) != 0)); - assert!(((((unsafe { outer_1(0, &[]) }) == (0)) as i32) != 0)); + assert!(((((unsafe { outer_1(1, Box::new([(42).into(),])) }) == (42)) as i32) != 0)); + assert!(((((unsafe { outer_1(0, Box::new([])) }) == (0)) as i32) != 0)); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs b/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs index 6508cd480..109b77a89 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn mixed_args_0(mut count: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn mixed_args_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut total: i32 = 0; @@ -35,27 +35,31 @@ unsafe fn main_0() -> i32 { ((((unsafe { mixed_args_0( 3, - &[ + Box::new([ (0).into(), (10).into(), (1).into(), (&mut x as *mut i32).into(), (0).into(), (20).into(), - ], + ]), ) }) == (130)) as i32) != 0) ); let mut y: i32 = 50; assert!( - ((((unsafe { mixed_args_0(1, &[(1).into(), (&mut y as *mut i32).into(),]) }) == (50)) - as i32) + ((((unsafe { mixed_args_0(1, Box::new([(1).into(), (&mut y as *mut i32).into(),])) }) + == (50)) as i32) != 0) ); assert!( - ((((unsafe { mixed_args_0(2, &[(0).into(), (5).into(), (0).into(), (3).into(),]) }) == (8)) - as i32) + ((((unsafe { + mixed_args_0( + 2, + Box::new([(0).into(), (5).into(), (0).into(), (3).into()]), + ) + }) == (8)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/unsafe/va_arg_mixed_types.rs b/tests/unit/out/unsafe/va_arg_mixed_types.rs index 94cbe3392..f767d9bb5 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.rs @@ -12,7 +12,7 @@ pub struct pair { pub a: i32, pub b: i32, } -pub unsafe fn sum_mixed_0(mut count: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn sum_mixed_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut total: i32 = 0; @@ -45,32 +45,38 @@ unsafe fn main_0() -> i32 { ((((unsafe { sum_mixed_0( 3, - &[ + Box::new([ (0).into(), (10).into(), (1).into(), (20.5_f64).into(), (2).into(), (30_i64).into(), - ], + ]), ) }) == (60)) as i32) != 0) ); - assert!(((((unsafe { sum_mixed_0(1, &[(0).into(), (42).into(),]) }) == (42)) as i32) != 0)); + assert!( + ((((unsafe { sum_mixed_0(1, Box::new([(0).into(), (42).into(),])) }) == (42)) as i32) != 0) + ); assert!( ((((unsafe { sum_mixed_0( 2, - &[(1).into(), (3.7_f64).into(), (2).into(), (100_i64).into()], + Box::new([(1).into(), (3.7_f64).into(), (2).into(), (100_i64).into()]), ) }) == (103)) as i32) != 0) ); let mut p: pair = pair { a: 7, b: 8 }; assert!( - ((((unsafe { sum_mixed_0(2, &[(3).into(), (p).into(), (0).into(), (5).into(),]) }) == (61)) - as i32) + ((((unsafe { + sum_mixed_0( + 2, + Box::new([(3).into(), (p).into(), (0).into(), (5).into()]), + ) + }) == (61)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs index 7259516c6..744d36e38 100644 --- a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs @@ -17,7 +17,7 @@ pub const opt_OPT_STRING_OUT: opt = 0; pub const opt_OPT_FILE: opt = 1; pub const opt_OPT_NODE: opt = 2; pub const opt_OPT_NODE_OUT: opt = 3; -pub unsafe fn dispatch_0(mut option: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn dispatch_0(mut option: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut result: i32 = 0; @@ -62,7 +62,7 @@ unsafe fn main_0() -> i32 { ((((unsafe { dispatch_0( (opt_OPT_STRING_OUT as i32), - &[(&mut s as *mut *const libc::c_char).into()], + Box::new([(&mut s as *mut *const libc::c_char).into()]), ) }) == (1)) as i32) != 0) @@ -70,7 +70,10 @@ unsafe fn main_0() -> i32 { assert!((((!((s).is_null())) as i32) != 0)); assert!( ((((unsafe { - dispatch_0((opt_OPT_FILE as i32), &[(libcc2rs::stdout_unsafe()).into()]) + dispatch_0( + (opt_OPT_FILE as i32), + Box::new([(libcc2rs::stdout_unsafe()).into()]), + ) }) == (1)) as i32) != 0) ); @@ -78,7 +81,7 @@ unsafe fn main_0() -> i32 { ((((unsafe { dispatch_0( (opt_OPT_FILE as i32), - &[((0 as *mut ::libc::c_void) as *mut ::libc::FILE).into()], + Box::new([((0 as *mut ::libc::c_void) as *mut ::libc::FILE).into()]), ) }) == (0)) as i32) != 0) @@ -88,8 +91,12 @@ unsafe fn main_0() -> i32 { next: std::ptr::null_mut(), }; assert!( - ((((unsafe { dispatch_0((opt_OPT_NODE as i32), &[(&mut head as *mut node).into(),]) }) - == (42)) as i32) + ((((unsafe { + dispatch_0( + (opt_OPT_NODE as i32), + Box::new([(&mut head as *mut node).into()]), + ) + }) == (42)) as i32) != 0) ); let mut outp: *mut node = (&mut head as *mut node); @@ -97,7 +104,7 @@ unsafe fn main_0() -> i32 { ((((unsafe { dispatch_0( (opt_OPT_NODE_OUT as i32), - &[(&mut outp as *mut *mut node).into()], + Box::new([(&mut outp as *mut *mut node).into()]), ) }) == (2)) as i32) != 0) diff --git a/tests/unit/out/unsafe/va_arg_null_int_ptr.rs b/tests/unit/out/unsafe/va_arg_null_int_ptr.rs index 38eebb0e5..6367da53c 100644 --- a/tests/unit/out/unsafe/va_arg_null_int_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_null_int_ptr.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn first_nonnull_0(mut count: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn first_nonnull_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut result: i32 = -1_i32; @@ -33,10 +33,10 @@ unsafe fn main_0() -> i32 { ((((unsafe { first_nonnull_0( 2, - &[ + Box::new([ (0 as *mut ::libc::c_void).into(), (&mut x as *mut i32).into(), - ], + ]), ) }) == (42)) as i32) != 0) @@ -45,18 +45,18 @@ unsafe fn main_0() -> i32 { ((((unsafe { first_nonnull_0( 3, - &[ + Box::new([ (0 as *mut ::libc::c_void).into(), (0 as *mut ::libc::c_void).into(), (&mut x as *mut i32).into(), - ], + ]), ) }) == (42)) as i32) != 0) ); assert!( - ((((unsafe { first_nonnull_0(1, &[(0 as *mut ::libc::c_void).into(),]) }) == (-1_i32)) - as i32) + ((((unsafe { first_nonnull_0(1, Box::new([(0 as *mut ::libc::c_void).into(),])) }) + == (-1_i32)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/unsafe/va_arg_printf.rs b/tests/unit/out/unsafe/va_arg_printf.rs index a1a758f53..bf245667b 100644 --- a/tests/unit/out/unsafe/va_arg_printf.rs +++ b/tests/unit/out/unsafe/va_arg_printf.rs @@ -10,13 +10,13 @@ pub unsafe fn logf_impl_0(mut fmt: *const libc::c_char, mut ap: *const VaArg) -> &(fmt); return ((ap.arg::()) + (ap.arg::())); } -pub unsafe fn logf_1(mut fmt: *const libc::c_char, __args: &[VaArg]) -> i32 { +pub unsafe fn logf_1(mut fmt: *const libc::c_char, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut result: i32 = (unsafe { logf_impl_0(fmt, ap) }); return result; } -pub unsafe fn lenf_2(mut fmt: *const libc::c_char, __args: &[VaArg]) -> i32 { +pub unsafe fn lenf_2(mut fmt: *const libc::c_char, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut s: *const libc::c_char = ap.arg::<*const libc::c_char>(); @@ -35,7 +35,7 @@ unsafe fn main_0() -> i32 { ((((unsafe { logf_1( (c"hello %d %d".as_ptr().cast_mut()).cast_const(), - &[(10).into(), (libc::strlen(dummy)).into()], + Box::new([(10).into(), (libc::strlen(dummy)).into()]), ) }) == (15)) as i32) != 0) @@ -44,26 +44,30 @@ unsafe fn main_0() -> i32 { ((((unsafe { logf_1( (c"x %d %d".as_ptr().cast_mut()).cast_const(), - &[(1).into(), (2).into()], + Box::new([(1).into(), (2).into()]), ) }) == (3)) as i32) != 0) ); assert!( - ((((unsafe { lenf_2((c"%s".as_ptr().cast_mut()).cast_const(), &[(dummy).into(),]) }) == (5)) - as i32) + ((((unsafe { + lenf_2( + (c"%s".as_ptr().cast_mut()).cast_const(), + Box::new([(dummy).into()]), + ) + }) == (5)) as i32) != 0) ); assert!( ((((unsafe { lenf_2( (c"%s".as_ptr().cast_mut()).cast_const(), - &[(if (((*dummy.offset((0) as isize)) as i32) != 0) { + Box::new([(if (((*dummy.offset((0) as isize)) as i32) != 0) { dummy } else { (c"".as_ptr().cast_mut() as *const libc::c_char) }) - .into()], + .into()]), ) }) == (5)) as i32) != 0) diff --git a/tests/unit/out/unsafe/va_arg_promotion.rs b/tests/unit/out/unsafe/va_arg_promotion.rs index d9c00b5d4..eb483df2d 100644 --- a/tests/unit/out/unsafe/va_arg_promotion.rs +++ b/tests/unit/out/unsafe/va_arg_promotion.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn test_promotions_0(mut count: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn test_promotions_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut a: i32 = ap.arg::(); @@ -31,7 +31,7 @@ unsafe fn main_0() -> i32 { ((((unsafe { test_promotions_0( 3, - &[(x as i32).into(), (y as i32).into(), (z as f64).into()], + Box::new([(x as i32).into(), (y as i32).into(), (z as f64).into()]), ) }) == (78)) as i32) != 0) diff --git a/tests/unit/out/unsafe/va_arg_snprintf.rs b/tests/unit/out/unsafe/va_arg_snprintf.rs index ba6e5071b..bf169c557 100644 --- a/tests/unit/out/unsafe/va_arg_snprintf.rs +++ b/tests/unit/out/unsafe/va_arg_snprintf.rs @@ -10,7 +10,7 @@ pub unsafe fn extract_first_0( mut buf: *mut libc::c_char, mut size: i32, mut fmt: *const libc::c_char, - __args: &[VaArg], + __args: Box<[VaArg]>, ) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); @@ -32,7 +32,7 @@ unsafe fn main_0() -> i32 { buf.as_mut_ptr(), 1, (c"%d".as_ptr().cast_mut()).cast_const(), - &[(42).into()], + Box::new([(42).into()]), ) }) == (42)) as i32) != 0) @@ -44,7 +44,7 @@ unsafe fn main_0() -> i32 { buf.as_mut_ptr(), 1, (c"%d".as_ptr().cast_mut()).cast_const(), - &[(65).into()], + Box::new([(65).into()]), ) }) == (65)) as i32) != 0) diff --git a/tests/unit/out/unsafe/va_arg_struct_ctx.rs b/tests/unit/out/unsafe/va_arg_struct_ctx.rs index 6fddfea1a..4f13f6ecd 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.rs @@ -12,7 +12,11 @@ pub struct context { pub verbose: i32, pub last_error: i32, } -pub unsafe fn set_error_0(mut ctx: *mut context, mut fmt: *const libc::c_char, __args: &[VaArg]) { +pub unsafe fn set_error_0( + mut ctx: *mut context, + mut fmt: *const libc::c_char, + __args: Box<[VaArg]>, +) { if ((*ctx).verbose != 0) { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); @@ -30,7 +34,7 @@ impl Default for value { unsafe { std::mem::zeroed() } } } -pub unsafe fn pick_1(mut use_long: i32, __args: &[VaArg]) -> i64 { +pub unsafe fn pick_1(mut use_long: i32, __args: Box<[VaArg]>) -> i64 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut v: value = ap.arg::(); @@ -53,7 +57,7 @@ unsafe fn main_0() -> i32 { set_error_0( (&mut ctx as *mut context), (c"error %d".as_ptr().cast_mut()).cast_const(), - &[(42).into()], + Box::new([(42).into()]), ) }); assert!(((((ctx.last_error) == (42)) as i32) != 0)); @@ -62,15 +66,15 @@ unsafe fn main_0() -> i32 { set_error_0( (&mut ctx as *mut context), (c"error %d".as_ptr().cast_mut()).cast_const(), - &[(99).into()], + Box::new([(99).into()]), ) }); assert!(((((ctx.last_error) == (42)) as i32) != 0)); let mut v: value = ::default(); v.l = ((1_i64) << (40)); - assert!(((((unsafe { pick_1(1, &[(v).into(),]) }) == ((1_i64) << (40))) as i32) != 0)); + assert!(((((unsafe { pick_1(1, Box::new([(v).into(),])) }) == ((1_i64) << (40))) as i32) != 0)); v.i = 7; - assert!(((((unsafe { pick_1(0, &[(v).into(),]) }) == (7_i64)) as i32) != 0)); + assert!(((((unsafe { pick_1(0, Box::new([(v).into(),])) }) == (7_i64)) as i32) != 0)); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/va_arg_two_passes.rs b/tests/unit/out/unsafe/va_arg_two_passes.rs index 93c040ab7..8d2aa6eb1 100644 --- a/tests/unit/out/unsafe/va_arg_two_passes.rs +++ b/tests/unit/out/unsafe/va_arg_two_passes.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn sum_then_product_0(mut first: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn sum_then_product_0(mut first: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); let mut sum: i32 = first; let mut product: i32 = first; @@ -39,8 +39,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!( - ((((unsafe { sum_then_product_0(2, &[(3).into(), (4).into(), (0).into(),]) }) == (33)) - as i32) + ((((unsafe { sum_then_product_0(2, Box::new([(3).into(), (4).into(), (0).into(),])) }) + == (33)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/unsafe/va_arg_void_ptr.rs b/tests/unit/out/unsafe/va_arg_void_ptr.rs index 45f9a38a8..01dae35ca 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_ptr.rs @@ -15,7 +15,11 @@ pub struct registry { pub type field = u32; pub const field_FIELD_SLOT: field = 0; pub const field_FIELD_LEVEL: field = 1; -pub unsafe fn registry_update_0(mut r: *mut registry, mut field: field, __args: &[VaArg]) -> i32 { +pub unsafe fn registry_update_0( + mut r: *mut registry, + mut field: field, + __args: Box<[VaArg]>, +) -> i32 { let mut result: i32 = 0; let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); @@ -54,7 +58,7 @@ unsafe fn main_0() -> i32 { registry_update_0( (&mut r as *mut registry), field_FIELD_SLOT, - &[(&mut payload as *mut i32).into()], + Box::new([(&mut payload as *mut i32).into()]), ) }) == (0)) as i32) != 0) @@ -64,7 +68,7 @@ unsafe fn main_0() -> i32 { registry_update_0( (&mut r as *mut registry), field_FIELD_LEVEL, - &[(5_i64).into()], + Box::new([(5_i64).into()]), ) }) == (0)) as i32) != 0) diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index c01ce8831..6fbccc3be 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn sum_0(mut n: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut guard: Guard_1 = Guard_1::new({ &mut ap }); @@ -37,7 +37,7 @@ impl Guard_1 { if self.active {} } } -pub unsafe fn sum_ptr_2(mut n: i32, __args: &[VaArg]) -> i32 { +pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut cursor: Cursor_3 = Cursor_3 { @@ -63,8 +63,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - assert!(((unsafe { sum_0(3, &[(1).into(), (2).into(), (3).into(),]) }) == (6))); - assert!(((unsafe { sum_ptr_2(2, &[(4).into(), (5).into(),]) }) == (9))); + assert!(((unsafe { sum_0(3, Box::new([(1).into(), (2).into(), (3).into(),])) }) == (6))); + assert!(((unsafe { sum_ptr_2(2, Box::new([(4).into(), (5).into(),])) }) == (9))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/va_arg_fn_ptr.c b/tests/unit/va_arg_fn_ptr.c index 36e209e92..3af296ac3 100644 --- a/tests/unit/va_arg_fn_ptr.c +++ b/tests/unit/va_arg_fn_ptr.c @@ -3,6 +3,8 @@ typedef int (*unary)(int); typedef int (*binary)(int, int); +typedef int (*variadic_unary)(int, ...); +typedef int (*variadic_binary)(int, int, ...); int square(int x) { return x * x; } int negate(int x) { return -x; } @@ -39,5 +41,10 @@ int main() { assert(apply_binary(3, 4, add) == 7); int dummy = 0; assert(not_supported(&dummy, square, &dummy) == -3); + variadic_unary vu = apply_unary; + assert(vu(6, square) == 36); + variadic_binary vb = (variadic_binary)apply_unary; + vu = (variadic_unary)vb; + assert(vu(2, negate) == -2); return 0; }