From 6412d02e80f973041166f52b95a2adef324745c9 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:01:18 +0100 Subject: [PATCH 01/10] Update tests --- tests/ub/out/refcount/fd_double_close.rs | 2 +- tests/ub/out/refcount/fd_use_after_close.rs | 2 +- .../ub/out/refcount/file_use_after_fclose.rs | 4 +- tests/unit/out/refcount/array_reference.rs | 10 +- .../out/refcount/bool_condition_logical.rs | 2 +- .../out/refcount/bool_condition_logical_c.rs | 2 +- tests/unit/out/refcount/char_printing.rs | 2 +- tests/unit/out/refcount/char_printing_cerr.rs | 2 +- tests/unit/out/refcount/cstring.rs | 117 +++++++++--------- tests/unit/out/refcount/default_in_statics.rs | 6 +- tests/unit/out/refcount/enum_int_interop.rs | 6 +- tests/unit/out/refcount/enum_int_interop_c.rs | 12 +- tests/unit/out/refcount/errno.rs | 2 +- tests/unit/out/refcount/expr_as_bool_c.rs | 2 +- tests/unit/out/refcount/expr_as_bool_cpp.rs | 2 +- tests/unit/out/refcount/fd_io.rs | 6 +- .../out/refcount/fn_ptr_stdlib_compare.rs | 16 +-- tests/unit/out/refcount/fopen.rs | 6 +- tests/unit/out/refcount/fstat.rs | 4 +- .../out/refcount/global_non_const_init.rs | 4 +- tests/unit/out/refcount/global_pointers.rs | 6 +- tests/unit/out/refcount/ifaddrs.rs | 2 +- tests/unit/out/refcount/inet_pton_ntop.rs | 24 ++-- tests/unit/out/refcount/isatty.rs | 2 +- tests/unit/out/refcount/iterators.rs | 2 +- .../unit/out/refcount/libc_char_ptr_field.rs | 4 +- tests/unit/out/refcount/lseek_ftruncate.rs | 6 +- tests/unit/out/refcount/macros.rs | 8 +- tests/unit/out/refcount/map-reallocation.rs | 26 ++-- tests/unit/out/refcount/netdb.rs | 12 +- tests/unit/out/refcount/offsetof.rs | 4 +- .../out/refcount/operator_comparison_mixed.rs | 4 +- tests/unit/out/refcount/pipe_io.rs | 4 +- tests/unit/out/refcount/poll.rs | 2 +- tests/unit/out/refcount/printfs.rs | 10 +- .../out/refcount/reinterpret_cast_string.rs | 2 +- tests/unit/out/refcount/select.rs | 2 +- tests/unit/out/refcount/snprintf.rs | 48 +++---- tests/unit/out/refcount/stdcopy_ostream.rs | 2 +- tests/unit/out/refcount/stdio.rs | 16 ++- tests/unit/out/refcount/stdio_nofd.rs | 67 +++++----- tests/unit/out/refcount/strdup.rs | 6 +- tests/unit/out/refcount/string.rs | 24 ++-- tests/unit/out/refcount/string2.rs | 4 +- tests/unit/out/refcount/string_escape.rs | 2 +- tests/unit/out/refcount/string_h.rs | 112 +++++++++-------- .../refcount/string_literal_interior_null.rs | 4 +- .../out/refcount/string_literal_ptr_init.rs | 13 +- tests/unit/out/refcount/string_literals.rs | 15 +-- tests/unit/out/refcount/string_literals_c.rs | 28 +++-- .../out/refcount/string_literals_concat.rs | 4 +- .../out/refcount/string_literals_concat_c.rs | 2 +- .../out/refcount/string_literals_return.rs | 8 +- .../out/refcount/string_literals_return_c.rs | 8 +- tests/unit/out/refcount/sys_stat.rs | 12 +- tests/unit/out/refcount/sys_time.rs | 12 +- tests/unit/out/refcount/termios.rs | 2 +- .../out/refcount/union_tagged_many_arms.rs | 2 +- .../out/refcount/union_tagged_struct_arms.rs | 6 +- .../out/refcount/user_defined_same_as_libc.rs | 4 +- tests/unit/out/refcount/va_arg_conditional.rs | 6 +- .../out/refcount/va_arg_non_primitive_ptrs.rs | 2 +- tests/unit/out/refcount/va_arg_printf.rs | 12 +- tests/unit/out/refcount/va_arg_snprintf.rs | 4 +- tests/unit/out/refcount/va_arg_struct_ctx.rs | 4 +- 65 files changed, 397 insertions(+), 361 deletions(-) diff --git a/tests/ub/out/refcount/fd_double_close.rs b/tests/ub/out/refcount/fd_double_close.rs index 1434c283f..bdb6d699e 100644 --- a/tests/ub/out/refcount/fd_double_close.rs +++ b/tests/ub/out/refcount/fd_double_close.rs @@ -17,7 +17,7 @@ fn main_0() -> i32 { None => nix::sys::stat::Mode::empty(), }; match nix::fcntl::open( - Ptr::from_string_literal(b"/dev/null") + Ptr::::from_string_literal(b"/dev/null") .to_rust_string() .as_str(), nix::fcntl::OFlag::from_bits_retain(::libc::O_RDONLY), diff --git a/tests/ub/out/refcount/fd_use_after_close.rs b/tests/ub/out/refcount/fd_use_after_close.rs index a1160c367..d0d6c0f20 100644 --- a/tests/ub/out/refcount/fd_use_after_close.rs +++ b/tests/ub/out/refcount/fd_use_after_close.rs @@ -17,7 +17,7 @@ fn main_0() -> i32 { None => nix::sys::stat::Mode::empty(), }; match nix::fcntl::open( - Ptr::from_string_literal(b"/dev/null") + Ptr::::from_string_literal(b"/dev/null") .to_rust_string() .as_str(), nix::fcntl::OFlag::from_bits_retain(::libc::O_RDONLY), diff --git a/tests/ub/out/refcount/file_use_after_fclose.rs b/tests/ub/out/refcount/file_use_after_fclose.rs index 22f2ed1d6..7417df9ec 100644 --- a/tests/ub/out/refcount/file_use_after_fclose.rs +++ b/tests/ub/out/refcount/file_use_after_fclose.rs @@ -13,8 +13,8 @@ pub fn main() { fn main_0() -> i32 { let fp: Value> = Rc::new(RefCell::new( match CFile::open( - &Ptr::from_string_literal(b"/tmp/cpp2rust_uafc_test.tmp").to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"/tmp/cpp2rust_uafc_test.tmp").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index fd73fcccb..24e105e8d 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -164,7 +164,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - assert!((({ len_0(Ptr::from_string_literal_array(b"beta"),) }) == 4)); + assert!((({ len_0(Ptr::>::from_string_literal_array(b"beta"),) }) == 4)); let buf: Value> = Rc::new(RefCell::new(Box::from(*b"abcd\0"))); assert!((({ len_0((buf.as_pointer() as Ptr>),) }) == 4)); let arr: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); @@ -176,10 +176,10 @@ fn main_0() -> i32 { ({ fill_and_sum_5((arr.as_pointer() as Ptr>), 2, out.as_pointer()) }); assert!(((*out.borrow()) == 12)); assert!(((*arr.borrow())[(0) as usize] == 2)); - let lit: Ptr> = Ptr::from_string_literal_array(b"beta"); + let lit: Ptr> = Ptr::>::from_string_literal_array(b"beta"); assert!((({ len_0(((lit).clone() as Ptr>),) }) == 4)); assert!( - ((((({ pick_6(Ptr::from_string_literal_array(b"beta"),) }) + ((((({ pick_6(Ptr::>::from_string_literal_array(b"beta"),) }) .to_strong() .as_pointer() as Ptr::) .offset((0) as isize) @@ -206,8 +206,8 @@ fn main_0() -> i32 { assert!(((*(*pts.borrow())[(1) as usize].y.borrow()) == 14)); assert!((({ sum_points_7((pts.as_pointer() as Ptr>),) }) == 30)); let names: Value]>> = Rc::new(RefCell::new(Box::new([ - Ptr::from_string_literal(b"ab"), - Ptr::from_string_literal(b"cde"), + Ptr::::from_string_literal(b"ab"), + Ptr::::from_string_literal(b"cde"), ]))); assert!((({ total_len_9((names.as_pointer() as Ptr]>>),) }) == 5)); return 0; diff --git a/tests/unit/out/refcount/bool_condition_logical.rs b/tests/unit/out/refcount/bool_condition_logical.rs index fd8c7a915..e178b31fe 100644 --- a/tests/unit/out/refcount/bool_condition_logical.rs +++ b/tests/unit/out/refcount/bool_condition_logical.rs @@ -104,7 +104,7 @@ fn main_0() -> i32 { if ((*n.borrow()) != 0) || (((*bits.borrow()) & 256_i64) != 0) { assert!(true); } - let cp: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hi"))); + let cp: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hi"))); let cnp: Value> = Rc::new(RefCell::new(Ptr::::null())); if ((*x.borrow()) > (*y.borrow())) && (!(*cp.borrow()).is_null()) { assert!(true); diff --git a/tests/unit/out/refcount/bool_condition_logical_c.rs b/tests/unit/out/refcount/bool_condition_logical_c.rs index 8843447ea..ecc334a72 100644 --- a/tests/unit/out/refcount/bool_condition_logical_c.rs +++ b/tests/unit/out/refcount/bool_condition_logical_c.rs @@ -127,7 +127,7 @@ fn main_0() -> i32 { { assert!((1 != 0)); } - let cp: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hi"))); + let cp: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hi"))); let cnp: Value> = Rc::new(RefCell::new(Ptr::::null())); if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) && (!(*cp.borrow()).is_null())) as i32) != 0) diff --git a/tests/unit/out/refcount/char_printing.rs b/tests/unit/out/refcount/char_printing.rs index a3a2ed9aa..6de934691 100644 --- a/tests/unit/out/refcount/char_printing.rs +++ b/tests/unit/out/refcount/char_printing.rs @@ -14,7 +14,7 @@ fn main_0() -> i32 { let vec_: Value> = Rc::new(RefCell::new(vec![195_u8, 167_u8])); let i: Value = Rc::new(RefCell::new(27)); let str: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"rdas.") + Ptr::::from_string_literal(b"rdas.") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/char_printing_cerr.rs b/tests/unit/out/refcount/char_printing_cerr.rs index 66a1cab73..25f7e4e69 100644 --- a/tests/unit/out/refcount/char_printing_cerr.rs +++ b/tests/unit/out/refcount/char_printing_cerr.rs @@ -14,7 +14,7 @@ fn main_0() -> i32 { let vec_: Value> = Rc::new(RefCell::new(vec![195_u8, 167_u8])); let i: Value = Rc::new(RefCell::new(27)); let str: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"rdas.") + Ptr::::from_string_literal(b"rdas.") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/cstring.rs b/tests/unit/out/refcount/cstring.rs index 2ac030344..e2aae7a50 100644 --- a/tests/unit/out/refcount/cstring.rs +++ b/tests/unit/out/refcount/cstring.rs @@ -125,7 +125,7 @@ pub fn test_memmove_3() { ); } pub fn test_strchr_4() { - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).clone(); let __t = (('w' as u8) as i32) as u8; @@ -161,15 +161,20 @@ pub fn test_strchr_4() { ); } pub fn test_strlen_5() { - assert!((Ptr::from_string_literal(b"").to_c_string_iterator().count() == 0_usize)); assert!( - (Ptr::from_string_literal(b"hello") + (Ptr::::from_string_literal(b"") + .to_c_string_iterator() + .count() + == 0_usize) + ); + assert!( + (Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .count() == 5_usize) ); assert!( - (Ptr::from_string_literal(b"hello world") + (Ptr::::from_string_literal(b"hello world") .to_c_string_iterator() .count() == 11_usize) @@ -178,8 +183,8 @@ pub fn test_strlen_5() { pub fn test_strcmp_6() { assert!( ({ - let mut __it1 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it1 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -194,8 +199,8 @@ pub fn test_strcmp_6() { ); assert!( ({ - let mut __it1 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"abd").to_c_string_iterator(); + let mut __it1 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"abd").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -210,8 +215,8 @@ pub fn test_strcmp_6() { ); assert!( ({ - let mut __it1 = Ptr::from_string_literal(b"abd").to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it1 = Ptr::::from_string_literal(b"abd").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -224,8 +229,8 @@ pub fn test_strcmp_6() { } } > 0) ); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abc"))); - let q: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abd"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abc"))); + let q: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abd"))); let buf: Value> = Rc::new(RefCell::new(Box::new([ ('a' as u8), ('b' as u8), @@ -285,10 +290,10 @@ pub fn test_strncmp_7() { assert!( ({ let __n = 3_usize; - let mut __it1 = Ptr::from_string_literal(b"abcdef") + let mut __it1 = Ptr::::from_string_literal(b"abcdef") .to_c_string_iterator() .take(__n); - let mut __it2 = Ptr::from_string_literal(b"abcxyz") + let mut __it2 = Ptr::::from_string_literal(b"abcxyz") .to_c_string_iterator() .take(__n); loop { @@ -306,10 +311,10 @@ pub fn test_strncmp_7() { assert!( ({ let __n = 4_usize; - let mut __it1 = Ptr::from_string_literal(b"abcdef") + let mut __it1 = Ptr::::from_string_literal(b"abcdef") .to_c_string_iterator() .take(__n); - let mut __it2 = Ptr::from_string_literal(b"abcxyz") + let mut __it2 = Ptr::::from_string_literal(b"abcxyz") .to_c_string_iterator() .take(__n); loop { @@ -327,10 +332,10 @@ pub fn test_strncmp_7() { assert!( ({ let __n = 4_usize; - let mut __it1 = Ptr::from_string_literal(b"abcxyz") + let mut __it1 = Ptr::::from_string_literal(b"abcxyz") .to_c_string_iterator() .take(__n); - let mut __it2 = Ptr::from_string_literal(b"abcdef") + let mut __it2 = Ptr::::from_string_literal(b"abcdef") .to_c_string_iterator() .take(__n); loop { @@ -345,8 +350,8 @@ pub fn test_strncmp_7() { } } > 0) ); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abcdef"))); - let q: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abcxyz"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abcdef"))); + let q: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abcxyz"))); let buf: Value> = Rc::new(RefCell::new(Box::new([ ('a' as u8), ('b' as u8), @@ -475,7 +480,7 @@ pub fn test_memchr_8() { }); } pub fn test_strrchr_9() { - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).clone(); let __t = (('l' as u8) as i32) as u8; @@ -553,13 +558,13 @@ pub fn test_strrchr_9() { } pub fn test_strdup_10() { let d: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - Ptr::from_string_literal(b"hello"), + Ptr::::from_string_literal(b"hello"), ))); assert!(!((*d.borrow()).is_null())); assert!( ({ let mut __it1 = (*d.borrow()).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"hello").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"hello").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -573,7 +578,7 @@ pub fn test_strdup_10() { } == 0) ); libcc2rs::free_refcount(((*d.borrow()).clone() as Ptr).to_any()); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"world"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"world"))); let buf: Value> = Rc::new(RefCell::new(Box::new([ ('a' as u8), ('b' as u8), @@ -626,8 +631,8 @@ pub fn test_strdup_10() { pub fn test_strcspn_11() { assert!( ({ - let __set = Ptr::from_string_literal(b"el"); - Ptr::from_string_literal(b"hello") + let __set = Ptr::::from_string_literal(b"el"); + Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -635,8 +640,8 @@ pub fn test_strcspn_11() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"xyz"); - Ptr::from_string_literal(b"abc") + let __set = Ptr::::from_string_literal(b"xyz"); + Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -644,15 +649,15 @@ pub fn test_strcspn_11() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"abc"); - Ptr::from_string_literal(b"") + let __set = Ptr::::from_string_literal(b"abc"); + Ptr::::from_string_literal(b"") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() } == 0_usize) ); - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); - let rej: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"el"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); + let rej: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"el"))); assert!( ({ let __set = (*rej.borrow()).clone(); @@ -666,8 +671,8 @@ pub fn test_strcspn_11() { pub fn test_strspn_12() { assert!( ({ - let __set = Ptr::from_string_literal(b"hel"); - Ptr::from_string_literal(b"hello") + let __set = Ptr::::from_string_literal(b"hel"); + Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -675,8 +680,8 @@ pub fn test_strspn_12() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"xyz"); - Ptr::from_string_literal(b"abc") + let __set = Ptr::::from_string_literal(b"xyz"); + Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -684,15 +689,15 @@ pub fn test_strspn_12() { ); assert!( ({ - let __set = Ptr::from_string_literal(b"a"); - Ptr::from_string_literal(b"aaa") + let __set = Ptr::::from_string_literal(b"a"); + Ptr::::from_string_literal(b"aaa") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() } == 3_usize) ); - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); - let acc: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hel"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); + let acc: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hel"))); assert!( ({ let __set = (*acc.borrow()).clone(); @@ -704,9 +709,9 @@ pub fn test_strspn_12() { ); } pub fn test_strstr_13() { - let h: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let h: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __needle = Ptr::from_string_literal(b"world"); + let __needle = Ptr::::from_string_literal(b"world"); let mut __p = (*h.borrow()).clone(); loop { let mut __h = __p.to_c_string_iterator(); @@ -729,7 +734,7 @@ pub fn test_strstr_13() { }); assert!( ({ - let __needle = Ptr::from_string_literal(b"xyz"); + let __needle = Ptr::::from_string_literal(b"xyz"); let mut __p = (*h.borrow()).clone(); loop { let mut __h = __p.to_c_string_iterator(); @@ -757,7 +762,7 @@ pub fn test_strstr_13() { ]))); assert!( ({ - let __needle = Ptr::from_string_literal(b"ll"); + let __needle = Ptr::::from_string_literal(b"ll"); let mut __p = (buf.as_pointer() as Ptr); loop { let mut __h = __p.to_c_string_iterator(); @@ -776,10 +781,10 @@ pub fn test_strstr_13() { ); } pub fn test_strpbrk_14() { - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).clone(); - let __set = Ptr::from_string_literal(b"wo"); + let __set = Ptr::::from_string_literal(b"wo"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -796,7 +801,7 @@ pub fn test_strpbrk_14() { assert!( ({ let __s = (*s.borrow()).clone(); - let __set = Ptr::from_string_literal(b"xyz"); + let __set = Ptr::::from_string_literal(b"xyz"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -816,7 +821,7 @@ pub fn test_strpbrk_14() { assert!( ({ let __s = (buf.as_pointer() as Ptr); - let __set = Ptr::from_string_literal(b"b"); + let __set = Ptr::::from_string_literal(b"b"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -830,10 +835,10 @@ pub fn test_strpbrk_14() { pub fn test_strcasecmp_15() { assert!( ({ - let mut __it1 = Ptr::from_string_literal(b"HELLO") + let mut __it1 = Ptr::::from_string_literal(b"HELLO") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); - let mut __it2 = Ptr::from_string_literal(b"hello") + let mut __it2 = Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); loop { @@ -850,10 +855,10 @@ pub fn test_strcasecmp_15() { ); assert!( ({ - let mut __it1 = Ptr::from_string_literal(b"abc") + let mut __it1 = Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); - let mut __it2 = Ptr::from_string_literal(b"abd") + let mut __it2 = Ptr::::from_string_literal(b"abd") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); loop { @@ -870,10 +875,10 @@ pub fn test_strcasecmp_15() { ); assert!( ({ - let mut __it1 = Ptr::from_string_literal(b"abd") + let mut __it1 = Ptr::::from_string_literal(b"abd") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); - let mut __it2 = Ptr::from_string_literal(b"abc") + let mut __it2 = Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); loop { @@ -888,8 +893,8 @@ pub fn test_strcasecmp_15() { } } > 0) ); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"FOO"))); - let q: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"foo"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"FOO"))); + let q: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"foo"))); assert!( ({ let mut __it1 = (*p.borrow()) diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index 0a1be0874..aecf08082 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.rs @@ -183,7 +183,7 @@ thread_local!( ); thread_local!( pub static static_foo_3: Value = Rc::new(RefCell::new(Foo { - s1: Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))), + s1: Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))), s2: Rc::new(RefCell::new(Ptr::::null())), fn1: Rc::new(RefCell::new(FnPtr:: i32>::null())), fn2: Rc::new(RefCell::new(FnPtr:: i32>::null())), @@ -193,14 +193,14 @@ thread_local!( thread_local!( pub static static_foo_array_4: Value> = Rc::new(RefCell::new(Box::new([ Foo { - s1: Rc::new(RefCell::new(Ptr::from_string_literal(b"first"))), + s1: Rc::new(RefCell::new(Ptr::::from_string_literal(b"first"))), s2: Rc::new(RefCell::new(Ptr::::null())), fn1: Rc::new(RefCell::new(FnPtr:: i32>::null())), fn2: Rc::new(RefCell::new(FnPtr:: i32>::null())), n: Rc::new(RefCell::new(1)), }, Foo { - s1: Rc::new(RefCell::new(Ptr::from_string_literal(b"second"))), + s1: Rc::new(RefCell::new(Ptr::::from_string_literal(b"second"))), s2: Rc::new(RefCell::new(Ptr::::null())), fn1: Rc::new(RefCell::new(FnPtr:: i32>::null())), fn2: Rc::new(RefCell::new(FnPtr:: i32>::null())), diff --git a/tests/unit/out/refcount/enum_int_interop.rs b/tests/unit/out/refcount/enum_int_interop.rs index 97d1f52e9..3996d0370 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -65,17 +65,17 @@ thread_local!( thread_local!( pub static entries_3: Value> = Rc::new(RefCell::new(Box::new([ Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"first"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"first"))), color: Rc::new(RefCell::new(Color_RED)), opt: Rc::new(RefCell::new(Option_OPT_NONE)), }, Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"second"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"second"))), color: Rc::new(RefCell::new(Color_GREEN)), opt: Rc::new(RefCell::new(Option_OPT_A)), }, Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"third"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"third"))), color: Rc::new(RefCell::new(Color_BLUE)), opt: Rc::new(RefCell::new(Option_OPT_C)), }, diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index 7aa38123e..a36c3c4fa 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -63,17 +63,17 @@ thread_local!( thread_local!( pub static entries_3: Value> = Rc::new(RefCell::new(Box::new([ Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"first"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"first"))), color: Rc::new(RefCell::new(Color_RED)), opt: Rc::new(RefCell::new(Option_OPT_NONE)), }, Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"second"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"second"))), color: Rc::new(RefCell::new(Color_GREEN)), opt: Rc::new(RefCell::new(Option_OPT_A)), }, Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"third"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"third"))), color: Rc::new(RefCell::new(Color_BLUE)), opt: Rc::new(RefCell::new(Option_OPT_C)), }, @@ -254,9 +254,9 @@ fn main_0() -> i32 { != 0) ); let names: Value]>> = Rc::new(RefCell::new(Box::new([ - Ptr::from_string_literal(b"red"), - Ptr::from_string_literal(b"green"), - Ptr::from_string_literal(b"blue"), + Ptr::::from_string_literal(b"red"), + Ptr::::from_string_literal(b"green"), + Ptr::::from_string_literal(b"blue"), ]))); let idx: Value = Rc::new(RefCell::new(Color_GREEN)); assert!( diff --git a/tests/unit/out/refcount/errno.rs b/tests/unit/out/refcount/errno.rs index 226cb2bf7..afafafc17 100644 --- a/tests/unit/out/refcount/errno.rs +++ b/tests/unit/out/refcount/errno.rs @@ -18,7 +18,7 @@ pub fn test_errno_0() { pub fn test_errno_preserved_across_strdup_1() { libcc2rs::cpp2rust_errno().write(99); let d: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - Ptr::from_string_literal(b"hello"), + Ptr::::from_string_literal(b"hello"), ))); assert!((((!((*d.borrow()).is_null())) as i32) != 0)); assert!(((((libcc2rs::cpp2rust_errno().read()) == 99) as i32) != 0)); diff --git a/tests/unit/out/refcount/expr_as_bool_c.rs b/tests/unit/out/refcount/expr_as_bool_c.rs index c2010ce82..7470fb9aa 100644 --- a/tests/unit/out/refcount/expr_as_bool_c.rs +++ b/tests/unit/out/refcount/expr_as_bool_c.rs @@ -71,7 +71,7 @@ fn main_0() -> i32 { assert!(((((*eq.borrow()) == 1) as i32) != 0)); assert!(((((*lt.borrow()) == 0) as i32) != 0)); assert!(((((*neq.borrow()) == 0) as i32) != 0)); - let p1: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hi"))); + let p1: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hi"))); let p2: Value> = Rc::new(RefCell::new(Ptr::::null())); let either: Value = Rc::new(RefCell::new( (((!(*p1.borrow()).is_null()) || (!(*p2.borrow()).is_null())) as i32), diff --git a/tests/unit/out/refcount/expr_as_bool_cpp.rs b/tests/unit/out/refcount/expr_as_bool_cpp.rs index 62dff945f..b80c663d6 100644 --- a/tests/unit/out/refcount/expr_as_bool_cpp.rs +++ b/tests/unit/out/refcount/expr_as_bool_cpp.rs @@ -67,7 +67,7 @@ fn main_0() -> i32 { assert!(((*eq.borrow()) == 1)); assert!(((*lt.borrow()) == 0)); assert!(((*neq.borrow()) == 0)); - let p1: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hi"))); + let p1: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hi"))); let p2: Value> = Rc::new(RefCell::new(Ptr::::null())); let either: Value = Rc::new(RefCell::new( (((!(*p1.borrow()).is_null()) || (!(*p2.borrow()).is_null())) as i32), diff --git a/tests/unit/out/refcount/fd_io.rs b/tests/unit/out/refcount/fd_io.rs index 2ad7329ea..d8902a1fe 100644 --- a/tests/unit/out/refcount/fd_io.rs +++ b/tests/unit/out/refcount/fd_io.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_fd_io_test.tmp", ))); let fd: Value = Rc::new(RefCell::new({ @@ -36,7 +36,7 @@ fn main_0() -> i32 { assert!(((((*fd.borrow()) >= 0) as i32) != 0)); assert!( (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { - Ptr::from_string_literal(b"hello world") + Ptr::::from_string_literal(b"hello world") .to_any() .reinterpret_cast::() .with_slice(11_usize, |__buf| nix::unistd::write(__fd, __buf)) @@ -97,7 +97,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"hello world").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"hello world").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); diff --git a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs index cccb7ef72..cd39e7034 100644 --- a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs +++ b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs @@ -66,8 +66,8 @@ fn main_0() -> i32 { __do_while = false; let stream: Value> = Rc::new(RefCell::new( match CFile::open( - &Ptr::from_string_literal(b"/dev/zero").to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"/dev/zero").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -113,8 +113,8 @@ fn main_0() -> i32 { __do_while = false; let stream: Value> = Rc::new(RefCell::new( match CFile::open( - &Ptr::from_string_literal(b"/dev/zero").to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"/dev/zero").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -198,8 +198,8 @@ fn main_0() -> i32 { __do_while = false; let stream: Value> = Rc::new(RefCell::new( match CFile::open( - &Ptr::from_string_literal(b"/dev/null").to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"/dev/null").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -235,8 +235,8 @@ fn main_0() -> i32 { __do_while = false; let stream: Value> = Rc::new(RefCell::new( match CFile::open( - &Ptr::from_string_literal(b"/dev/null").to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"/dev/null").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), diff --git a/tests/unit/out/refcount/fopen.rs b/tests/unit/out/refcount/fopen.rs index 972ff7c9e..185523c64 100644 --- a/tests/unit/out/refcount/fopen.rs +++ b/tests/unit/out/refcount/fopen.rs @@ -11,8 +11,10 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let fname: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"testfile.txt"))); - let mode: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"rb"))); + let fname: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( + b"testfile.txt", + ))); + let mode: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"rb"))); let file_ptr: Value> = Rc::new(RefCell::new( match CFile::open( &(*fname.borrow()).to_rust_string(), diff --git a/tests/unit/out/refcount/fstat.rs b/tests/unit/out/refcount/fstat.rs index d932b694f..ac3ebe744 100644 --- a/tests/unit/out/refcount/fstat.rs +++ b/tests/unit/out/refcount/fstat.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_fstat_test.tmp", ))); let fd: Value = Rc::new(RefCell::new({ @@ -36,7 +36,7 @@ fn main_0() -> i32 { assert!(((((*fd.borrow()) >= 0) as i32) != 0)); assert!( (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { - Ptr::from_string_literal(b"hello") + Ptr::::from_string_literal(b"hello") .to_any() .reinterpret_cast::() .with_slice(5_usize, |__buf| nix::unistd::write(__fd, __buf)) diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index a60421a35..3d731878b 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -90,7 +90,7 @@ thread_local!( ); thread_local!( pub static str_9: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"abc") + Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), @@ -194,7 +194,7 @@ fn main_0() -> i32 { .iter() .copied() .take(str_9.with(|rc| rc.borrow().clone()).len().saturating_sub(1)) - .eq(Ptr::from_string_literal(b"abc").to_c_string_iterator()) + .eq(Ptr::::from_string_literal(b"abc").to_c_string_iterator()) ); assert!((member_10.with(|rc| rc.borrow().clone()) == 3)); assert!(((*inline_member_11.with(|rc| rc.borrow().clone()).v.borrow()) == 5)); diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index b00ca7cdc..cd81c6a34 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.rs @@ -38,18 +38,18 @@ impl ByteRepr for Entry { } thread_local!( pub static single_entry_0: Value = Rc::new(RefCell::new(Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"alone"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"alone"))), p: Rc::new(RefCell::new(Ptr::::null())), })); ); thread_local!( pub static entries_1: Value> = Rc::new(RefCell::new(Box::new([ Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"first"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"first"))), p: Rc::new(RefCell::new(Ptr::::null())), }, Entry { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"second"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"second"))), p: Rc::new(RefCell::new(Ptr::::null())), }, ]))); diff --git a/tests/unit/out/refcount/ifaddrs.rs b/tests/unit/out/refcount/ifaddrs.rs index 0c46e9320..570413000 100644 --- a/tests/unit/out/refcount/ifaddrs.rs +++ b/tests/unit/out/refcount/ifaddrs.rs @@ -148,7 +148,7 @@ fn main_0() -> i32 { }; assert!( (((match nix::net::if_::if_nametoindex( - Ptr::from_string_literal(b"cpp2rust_no_such_if") + Ptr::::from_string_literal(b"cpp2rust_no_such_if") .to_rust_string() .as_str() ) { diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index 3e7ceb4e3..e43d1713f 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -16,7 +16,7 @@ fn main_0() -> i32 { )); assert!( (((if libc::AF_INET == libc::AF_INET { - match Ptr::from_string_literal(b"1.2.3.4") + match Ptr::::from_string_literal(b"1.2.3.4") .to_rust_string() .parse::() { @@ -30,7 +30,7 @@ fn main_0() -> i32 { Err(_) => 0, } } else if libc::AF_INET == libc::AF_INET6 { - match Ptr::from_string_literal(b"1.2.3.4") + match Ptr::::from_string_literal(b"1.2.3.4") .to_rust_string() .parse::() { @@ -61,7 +61,7 @@ fn main_0() -> i32 { ); assert!( (((if libc::AF_INET == libc::AF_INET { - match Ptr::from_string_literal(b"999.1.1.1") + match Ptr::::from_string_literal(b"999.1.1.1") .to_rust_string() .parse::() { @@ -75,7 +75,7 @@ fn main_0() -> i32 { Err(_) => 0, } } else if libc::AF_INET == libc::AF_INET6 { - match Ptr::from_string_literal(b"999.1.1.1") + match Ptr::::from_string_literal(b"999.1.1.1") .to_rust_string() .parse::() { @@ -96,7 +96,7 @@ fn main_0() -> i32 { ); assert!( (((if libc::AF_INET == libc::AF_INET { - match Ptr::from_string_literal(b"not an ip") + match Ptr::::from_string_literal(b"not an ip") .to_rust_string() .parse::() { @@ -110,7 +110,7 @@ fn main_0() -> i32 { Err(_) => 0, } } else if libc::AF_INET == libc::AF_INET6 { - match Ptr::from_string_literal(b"not an ip") + match Ptr::::from_string_literal(b"not an ip") .to_rust_string() .parse::() { @@ -131,7 +131,7 @@ fn main_0() -> i32 { ); assert!( (((if libc::AF_INET6 == libc::AF_INET { - match Ptr::from_string_literal(b"::1") + match Ptr::::from_string_literal(b"::1") .to_rust_string() .parse::() { @@ -145,7 +145,7 @@ fn main_0() -> i32 { Err(_) => 0, } } else if libc::AF_INET6 == libc::AF_INET6 { - match Ptr::from_string_literal(b"::1") + match Ptr::::from_string_literal(b"::1") .to_rust_string() .parse::() { @@ -171,7 +171,7 @@ fn main_0() -> i32 { ); assert!( (((if libc::AF_INET6 == libc::AF_INET { - match Ptr::from_string_literal(b"2001:db8::5") + match Ptr::::from_string_literal(b"2001:db8::5") .to_rust_string() .parse::() { @@ -185,7 +185,7 @@ fn main_0() -> i32 { Err(_) => 0, } } else if libc::AF_INET6 == libc::AF_INET6 { - match Ptr::from_string_literal(b"2001:db8::5") + match Ptr::::from_string_literal(b"2001:db8::5") .to_rust_string() .parse::() { @@ -255,7 +255,7 @@ fn main_0() -> i32 { } } .to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"10.0.0.1").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"10.0.0.1").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -328,7 +328,7 @@ fn main_0() -> i32 { } } .to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"::1").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"::1").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); diff --git a/tests/unit/out/refcount/isatty.rs b/tests/unit/out/refcount/isatty.rs index 6b75dba6d..045125717 100644 --- a/tests/unit/out/refcount/isatty.rs +++ b/tests/unit/out/refcount/isatty.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_isatty_test.tmp", ))); let fd: Value = Rc::new(RefCell::new({ diff --git a/tests/unit/out/refcount/iterators.rs b/tests/unit/out/refcount/iterators.rs index 9eb280bfe..8b173fd7f 100644 --- a/tests/unit/out/refcount/iterators.rs +++ b/tests/unit/out/refcount/iterators.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let x: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"hello") + Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/libc_char_ptr_field.rs b/tests/unit/out/refcount/libc_char_ptr_field.rs index 10679e8e9..e1a29dcb9 100644 --- a/tests/unit/out/refcount/libc_char_ptr_field.rs +++ b/tests/unit/out/refcount/libc_char_ptr_field.rs @@ -31,7 +31,9 @@ fn main_0() -> i32 { )); let d: Value> = Rc::new(RefCell::new( match nix::dir::Dir::open( - Ptr::from_string_literal(b"/tmp").to_rust_string().as_str(), + Ptr::::from_string_literal(b"/tmp") + .to_rust_string() + .as_str(), nix::fcntl::OFlag::O_RDONLY, nix::sys::stat::Mode::empty(), ) { diff --git a/tests/unit/out/refcount/lseek_ftruncate.rs b/tests/unit/out/refcount/lseek_ftruncate.rs index 3a59e1546..d53e6a82c 100644 --- a/tests/unit/out/refcount/lseek_ftruncate.rs +++ b/tests/unit/out/refcount/lseek_ftruncate.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_lseek_ftruncate_test.tmp", ))); let fd: Value = Rc::new(RefCell::new({ @@ -36,7 +36,7 @@ fn main_0() -> i32 { assert!(((((*fd.borrow()) >= 0) as i32) != 0)); assert!( (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { - Ptr::from_string_literal(b"hello world") + Ptr::::from_string_literal(b"hello world") .to_any() .reinterpret_cast::() .with_slice(11_usize, |__buf| nix::unistd::write(__fd, __buf)) @@ -118,7 +118,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"world").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"world").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); diff --git a/tests/unit/out/refcount/macros.rs b/tests/unit/out/refcount/macros.rs index 927b5ec12..7493c53fd 100644 --- a/tests/unit/out/refcount/macros.rs +++ b/tests/unit/out/refcount/macros.rs @@ -24,15 +24,15 @@ pub fn main() { fn main_0() -> i32 { println!( "{} {} {}", - Ptr::from_string_literal(b"macros.cpp"), + Ptr::::from_string_literal(b"macros.cpp"), 8, - Ptr::from_string_literal(b"main") + Ptr::::from_string_literal(b"main") ); ({ log_0( - Ptr::from_string_literal(b"macros.cpp"), + Ptr::::from_string_literal(b"macros.cpp"), 9, - Ptr::from_string_literal(b"main"), + Ptr::::from_string_literal(b"main"), ) }); return 0; diff --git a/tests/unit/out/refcount/map-reallocation.rs b/tests/unit/out/refcount/map-reallocation.rs index bb4f3bee2..9ab9500a8 100644 --- a/tests/unit/out/refcount/map-reallocation.rs +++ b/tests/unit/out/refcount/map-reallocation.rs @@ -29,15 +29,19 @@ fn main_0() -> i32 { let p: Value> = Rc::new(RefCell::new(((*it.borrow()).second().as_pointer()))); assert!( ((*(*it.borrow()).second().borrow()) == (*sentinel.borrow())) - && (!(Ptr::from_string_literal(b"iterator does not have correct value before insert")) - .is_null()) + && (!(Ptr::::from_string_literal( + b"iterator does not have correct value before insert" + )) + .is_null()) ); assert!( ({ let _lhs = ((*p.borrow()).read()); _lhs == (*sentinel.borrow()) - }) && (!(Ptr::from_string_literal(b"pointer does not have correct value before insert")) - .is_null()) + }) && (!(Ptr::::from_string_literal( + b"pointer does not have correct value before insert" + )) + .is_null()) ); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*sentinel.borrow())) { @@ -65,22 +69,26 @@ fn main_0() -> i32 { } assert!( ((*(*it.borrow()).second().borrow()) != 0) - && (!(Ptr::from_string_literal( + && (!(Ptr::::from_string_literal( b"in refcount, iterator points to index 0 instead of sentinel" )) .is_null()) ); assert!( ((*(*it.borrow()).second().borrow()) == (*sentinel.borrow())) - && (!(Ptr::from_string_literal(b"iterator does not have correct value after insert")) - .is_null()) + && (!(Ptr::::from_string_literal( + b"iterator does not have correct value after insert" + )) + .is_null()) ); assert!( ({ let _lhs = ((*p.borrow()).read()); _lhs == (*sentinel.borrow()) - }) && (!(Ptr::from_string_literal(b"pointer does not have correct value after insert")) - .is_null()) + }) && (!(Ptr::::from_string_literal( + b"pointer does not have correct value after insert" + )) + .is_null()) ); (*(*it.borrow()).second().borrow_mut()) = 57005; assert!( diff --git a/tests/unit/out/refcount/netdb.rs b/tests/unit/out/refcount/netdb.rs index bd2abecd3..1688bd046 100644 --- a/tests/unit/out/refcount/netdb.rs +++ b/tests/unit/out/refcount/netdb.rs @@ -20,8 +20,8 @@ pub fn test_ipv4_literal_0() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __node = Ptr::from_string_literal(b"127.0.0.1"); - let __service = Ptr::from_string_literal(b"8080"); + let __node = Ptr::::from_string_literal(b"127.0.0.1"); + let __service = Ptr::::from_string_literal(b"8080"); let __hints = (hints.as_pointer()); let __out = (res.as_pointer()); let __family = if __hints.is_null() { @@ -191,8 +191,8 @@ pub fn test_ipv6_literal_1() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __node = Ptr::from_string_literal(b"::1"); - let __service = Ptr::from_string_literal(b"443"); + let __node = Ptr::::from_string_literal(b"::1"); + let __service = Ptr::::from_string_literal(b"443"); let __hints = (hints.as_pointer()); let __out = (res.as_pointer()); let __family = if __hints.is_null() { @@ -352,8 +352,8 @@ pub fn test_null_hints_2() { Rc::new(RefCell::new(Ptr::::null())); assert!( ((({ - let __node = Ptr::from_string_literal(b"127.0.0.1"); - let __service = Ptr::from_string_literal(b"80"); + let __node = Ptr::::from_string_literal(b"127.0.0.1"); + let __service = Ptr::::from_string_literal(b"80"); let __hints = Ptr::::null(); let __out = (res.as_pointer()); let __family = if __hints.is_null() { diff --git a/tests/unit/out/refcount/offsetof.rs b/tests/unit/out/refcount/offsetof.rs index 5a9dacdd3..77af17457 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.rs @@ -105,7 +105,9 @@ fn main_0() -> i32 { .reinterpret_cast::() .write(305419896_u32); assert!(((*(*v.borrow()).b.borrow()) == 305419896_u32)); - let text: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"example-body"))); + let text: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( + b"example-body", + ))); let len: Value = Rc::new(RefCell::new( ((*text.borrow()).to_c_string_iterator().count()).wrapping_add(1_usize), )); diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index bd1115762..5211a616d 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -95,13 +95,13 @@ fn main_0() -> i32 { assert!(({ SImpl::operator_lt(&cs, 6,) })); assert!(({ SImpl::operator_gt(&cs, 4.5E+0,) })); assert!(({ SImpl::operator_le(&cs, 5_i64,) })); - assert!(({ SImpl::operator_ge(&cs, Ptr::from_string_literal(b"3"),) })); + assert!(({ SImpl::operator_ge(&cs, Ptr::::from_string_literal(b"3"),) })); assert!(({ operator_eq_0(5, s.as_pointer(),) })); assert!(({ operator_ne_1(4, s.as_pointer(),) })); assert!(({ operator_lt_2(4, s.as_pointer(),) })); assert!(({ operator_gt_3(5.5E+0, s.as_pointer(),) })); assert!(({ operator_le_4(5_i64, s.as_pointer(),) })); - assert!(({ operator_ge_5(Ptr::from_string_literal(b"7"), s.as_pointer(),) })); + assert!(({ operator_ge_5(Ptr::::from_string_literal(b"7"), s.as_pointer(),) })); assert!( ({ let _a: Ptr = s.as_pointer(); diff --git a/tests/unit/out/refcount/pipe_io.rs b/tests/unit/out/refcount/pipe_io.rs index 253057240..f1e9a252c 100644 --- a/tests/unit/out/refcount/pipe_io.rs +++ b/tests/unit/out/refcount/pipe_io.rs @@ -31,7 +31,7 @@ fn main_0() -> i32 { ); assert!( (((match FdRegistry::with_fd((*fds.borrow())[(1) as usize], |__fd| { - Ptr::from_string_literal(b"ab") + Ptr::::from_string_literal(b"ab") .to_any() .reinterpret_cast::() .with_slice(2_usize, |__buf| nix::unistd::write(__fd, __buf)) @@ -73,7 +73,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"ab").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"ab").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); diff --git a/tests/unit/out/refcount/poll.rs b/tests/unit/out/refcount/poll.rs index 6878ee8f3..3c7b2555c 100644 --- a/tests/unit/out/refcount/poll.rs +++ b/tests/unit/out/refcount/poll.rs @@ -31,7 +31,7 @@ fn main_0() -> i32 { ); assert!( (((match FdRegistry::with_fd((*fds.borrow())[(1) as usize], |__fd| { - Ptr::from_string_literal(b"x") + Ptr::::from_string_literal(b"x") .to_any() .reinterpret_cast::() .with_slice(1_usize, |__buf| nix::unistd::write(__fd, __buf)) diff --git a/tests/unit/out/refcount/printfs.rs b/tests/unit/out/refcount/printfs.rs index 2276ea056..26d9aa989 100644 --- a/tests/unit/out/refcount/printfs.rs +++ b/tests/unit/out/refcount/printfs.rs @@ -11,7 +11,7 @@ pub fn fn_0(v: Vec) -> Vec { return { let mut r = (*v.borrow()).clone(); r.pop(); - r.extend(Ptr::from_string_literal(b" str").to_c_string_iterator()); + r.extend(Ptr::::from_string_literal(b" str").to_c_string_iterator()); r.push(0); r }; @@ -24,15 +24,15 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - println!("{}", Ptr::from_string_literal(b"fprintf stdout")); + println!("{}", Ptr::::from_string_literal(b"fprintf stdout")); println!("{} {} {}", 1, 2_u32, 3_i64); print!("hello world"); let in_: Value> = Rc::new(RefCell::new((libcc2rs::c_stdin()).clone())); assert!(!((*in_.borrow()).is_null())); - println!("{}", Ptr::from_string_literal(b"printf")); + println!("{}", Ptr::::from_string_literal(b"printf")); print!("hello world"); let s: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"a string") + Ptr::::from_string_literal(b"a string") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), @@ -43,7 +43,7 @@ fn main_0() -> i32 { (Rc::new(RefCell::new( ({ fn_0( - Ptr::from_string_literal(b"foo") + Ptr::::from_string_literal(b"foo") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/reinterpret_cast_string.rs b/tests/unit/out/refcount/reinterpret_cast_string.rs index 4e0a6fe98..ebec189c7 100644 --- a/tests/unit/out/refcount/reinterpret_cast_string.rs +++ b/tests/unit/out/refcount/reinterpret_cast_string.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let s: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"ABCD") + Ptr::::from_string_literal(b"ABCD") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/select.rs b/tests/unit/out/refcount/select.rs index 0bd55094d..7de4d5c2e 100644 --- a/tests/unit/out/refcount/select.rs +++ b/tests/unit/out/refcount/select.rs @@ -173,7 +173,7 @@ fn main_0() -> i32 { ); assert!( (((match FdRegistry::with_fd((*fds.borrow())[(1) as usize], |__fd| { - Ptr::from_string_literal(b"x") + Ptr::::from_string_literal(b"x") .to_any() .reinterpret_cast::() .with_slice(1_usize, |__buf| nix::unistd::write(__fd, __buf)) diff --git a/tests/unit/out/refcount/snprintf.rs b/tests/unit/out/refcount/snprintf.rs index e2aecd64f..66d677f32 100644 --- a/tests/unit/out/refcount/snprintf.rs +++ b/tests/unit/out/refcount/snprintf.rs @@ -17,7 +17,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"x=%d y=%u").to_rust_string(), + &Ptr::::from_string_literal(b"x=%d y=%u").to_rust_string(), &[(-3_i32).into(), (7_u32).into()], ); let __b = __s.as_bytes(); @@ -35,7 +35,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"x=-3 y=7").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"x=-3 y=7").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -52,8 +52,8 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%s").to_rust_string(), - &[(Ptr::from_string_literal(b"hello")).into()], + &Ptr::::from_string_literal(b"%s").to_rust_string(), + &[(Ptr::::from_string_literal(b"hello")).into()], ); let __b = __s.as_bytes(); if 4_usize > 0 { @@ -70,7 +70,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"hel").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"hel").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -87,7 +87,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%05d|%x|%X").to_rust_string(), + &Ptr::::from_string_literal(b"%05d|%x|%X").to_rust_string(), &[(42).into(), (255).into(), (255).into()], ); let __b = __s.as_bytes(); @@ -105,7 +105,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"00042|ff|FF").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"00042|ff|FF").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -122,7 +122,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%.2f").to_rust_string(), + &Ptr::::from_string_literal(b"%.2f").to_rust_string(), &[(3.14159E+0).into()], ); let __b = __s.as_bytes(); @@ -140,7 +140,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"3.14").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"3.14").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -157,8 +157,8 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%-6s|").to_rust_string(), - &[(Ptr::from_string_literal(b"ab")).into()], + &Ptr::::from_string_literal(b"%-6s|").to_rust_string(), + &[(Ptr::::from_string_literal(b"ab")).into()], ); let __b = __s.as_bytes(); if ::std::mem::size_of::<[u8; 32]>() > 0 { @@ -175,7 +175,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"ab |").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"ab |").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -192,7 +192,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%c%%").to_rust_string(), + &Ptr::::from_string_literal(b"%c%%").to_rust_string(), &[(65).into()], ); let __b = __s.as_bytes(); @@ -210,7 +210,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"A%").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"A%").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -227,7 +227,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%+d % d").to_rust_string(), + &Ptr::::from_string_literal(b"%+d % d").to_rust_string(), &[(5).into(), (5).into()], ); let __b = __s.as_bytes(); @@ -245,7 +245,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"+5 5").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"+5 5").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -262,7 +262,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%ld %lu %zu").to_rust_string(), + &Ptr::::from_string_literal(b"%ld %lu %zu").to_rust_string(), &[(-1_i64).into(), (1_u64).into(), (9 as usize).into()], ); let __b = __s.as_bytes(); @@ -280,7 +280,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"-1 1 9").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"-1 1 9").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -297,7 +297,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%e").to_rust_string(), + &Ptr::::from_string_literal(b"%e").to_rust_string(), &[(1.2345678E+3).into()], ); let __b = __s.as_bytes(); @@ -315,7 +315,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"1.234568e+03").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"1.234568e+03").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -332,7 +332,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%g").to_rust_string(), + &Ptr::::from_string_literal(b"%g").to_rust_string(), &[(1.234567E+6).into()], ); let __b = __s.as_bytes(); @@ -350,7 +350,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"1.23457e+06").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"1.23457e+06").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -368,7 +368,7 @@ fn main_0() -> i32 { assert!( ((({ let __s = libcc2rs::format_c( - &Ptr::from_string_literal(b"%d").to_rust_string(), + &Ptr::::from_string_literal(b"%d").to_rust_string(), &[(123).into()], ); let __b = __s.as_bytes(); @@ -414,7 +414,7 @@ fn main_0() -> i32 { assert!( ((({ let mut __it1 = (buf.as_pointer() as Ptr).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b" 3.3").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b" 3.3").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); diff --git a/tests/unit/out/refcount/stdcopy_ostream.rs b/tests/unit/out/refcount/stdcopy_ostream.rs index e34142521..43a67b243 100644 --- a/tests/unit/out/refcount/stdcopy_ostream.rs +++ b/tests/unit/out/refcount/stdcopy_ostream.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let str: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"Hello, world!\n") + Ptr::::from_string_literal(b"Hello, world!\n") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/stdio.rs b/tests/unit/out/refcount/stdio.rs index a30dc3dcf..f87a0fa17 100644 --- a/tests/unit/out/refcount/stdio.rs +++ b/tests/unit/out/refcount/stdio.rs @@ -31,7 +31,7 @@ pub fn test_fputc_0() { } pub fn test_fputs_1() { { - let __bytes: Vec = Ptr::from_string_literal(b"hello") + let __bytes: Vec = Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .collect(); match libcc2rs::c_stdout().with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -46,7 +46,9 @@ pub fn test_fputs_1() { _ => -1, } }; - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"from variable"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( + b"from variable", + ))); { let __bytes: Vec = (*s.borrow()).to_c_string_iterator().collect(); match libcc2rs::c_stdout().with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -86,7 +88,7 @@ pub fn test_fputs_1() { } pub fn test_puts_2() { { - let mut __bytes: Vec = Ptr::from_string_literal(b"puts hello") + let mut __bytes: Vec = Ptr::::from_string_literal(b"puts hello") .to_c_string_iterator() .collect(); __bytes.push(b'\n'); @@ -95,7 +97,9 @@ pub fn test_puts_2() { false => -1, } }; - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"puts variable"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( + b"puts variable", + ))); { let mut __bytes: Vec = (*s.borrow()).to_c_string_iterator().collect(); __bytes.push(b'\n'); @@ -109,13 +113,13 @@ pub fn test_fileno_3() { assert!((((libcc2rs::c_stdin().with(|__f| __f.fd) == 0) as i32) != 0)); assert!((((libcc2rs::c_stdout().with(|__f| __f.fd) == 1) as i32) != 0)); assert!((((libcc2rs::c_stderr().with(|__f| __f.fd) == 2) as i32) != 0)); - let file: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let file: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_fileno_test.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*file.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), diff --git a/tests/unit/out/refcount/stdio_nofd.rs b/tests/unit/out/refcount/stdio_nofd.rs index b5dd9a2b8..789e7c8d5 100644 --- a/tests/unit/out/refcount/stdio_nofd.rs +++ b/tests/unit/out/refcount/stdio_nofd.rs @@ -7,13 +7,13 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn test_fputc_fputs_0() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_puts.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -32,7 +32,7 @@ pub fn test_fputc_fputs_0() { ); assert!( ((({ - let __bytes: Vec = Ptr::from_string_literal(b"BCD\n") + let __bytes: Vec = Ptr::::from_string_literal(b"BCD\n") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -52,7 +52,7 @@ pub fn test_fputc_fputs_0() { ); (*fp.borrow_mut()) = match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -89,7 +89,7 @@ pub fn test_fputc_fputs_0() { assert!( (((((buf.as_pointer() as Ptr::) as Ptr::) .to_any() - .memcmp(&Ptr::from_string_literal(b"ABCD\n").to_any(), 5_usize) + .memcmp(&Ptr::::from_string_literal(b"ABCD\n").to_any(), 5_usize) == 0) as i32) != 0) ); @@ -115,7 +115,7 @@ pub fn test_fputc_fputs_0() { pub fn test_puts_1() { assert!( ((({ - let mut __bytes: Vec = Ptr::from_string_literal(b"hello from puts") + let mut __bytes: Vec = Ptr::::from_string_literal(b"hello from puts") .to_c_string_iterator() .collect(); __bytes.push(b'\n'); @@ -128,13 +128,13 @@ pub fn test_puts_1() { ); } pub fn test_fgets_getc_2() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_gets.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -143,7 +143,7 @@ pub fn test_fgets_getc_2() { assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); assert!( ((({ - let __bytes: Vec = Ptr::from_string_literal(b"line1\nline2\n") + let __bytes: Vec = Ptr::::from_string_literal(b"line1\nline2\n") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -163,7 +163,7 @@ pub fn test_fgets_getc_2() { ); (*fp.borrow_mut()) = match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -211,7 +211,10 @@ pub fn test_fgets_getc_2() { assert!( (((((buf.as_pointer() as Ptr::) as Ptr::) .to_any() - .memcmp(&Ptr::from_string_literal(b"line1\n").to_any(), 7_usize) + .memcmp( + &Ptr::::from_string_literal(b"line1\n").to_any(), + 7_usize + ) == 0) as i32) != 0) ); @@ -255,7 +258,7 @@ pub fn test_fgets_getc_2() { assert!( (((((buf.as_pointer() as Ptr::) as Ptr::) .to_any() - .memcmp(&Ptr::from_string_literal(b"ine").to_any(), 4_usize) + .memcmp(&Ptr::::from_string_literal(b"ine").to_any(), 4_usize) == 0) as i32) != 0) ); @@ -298,7 +301,7 @@ pub fn test_fgets_getc_2() { assert!( (((((buf.as_pointer() as Ptr::) as Ptr::) .to_any() - .memcmp(&Ptr::from_string_literal(b"2\n").to_any(), 3_usize) + .memcmp(&Ptr::::from_string_literal(b"2\n").to_any(), 3_usize) == 0) as i32) != 0) ); @@ -359,13 +362,13 @@ pub fn test_fgets_getc_2() { ); } pub fn test_freopen_3() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_reopen.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -374,7 +377,7 @@ pub fn test_freopen_3() { assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); assert!( ((({ - let __bytes: Vec = Ptr::from_string_literal(b"hello") + let __bytes: Vec = Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -395,7 +398,7 @@ pub fn test_freopen_3() { } match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => { __stream.write(__f); @@ -428,7 +431,7 @@ pub fn test_freopen_3() { assert!( (((((buf.as_pointer() as Ptr::) as Ptr::) .to_any() - .memcmp(&Ptr::from_string_literal(b"hello").to_any(), 5_usize) + .memcmp(&Ptr::::from_string_literal(b"hello").to_any(), 5_usize) == 0) as i32) != 0) ); @@ -452,13 +455,13 @@ pub fn test_freopen_3() { ); } pub fn test_fseeko_4() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_seek.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -467,7 +470,7 @@ pub fn test_fseeko_4() { assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); assert!( ((({ - let __bytes: Vec = Ptr::from_string_literal(b"hello world") + let __bytes: Vec = Ptr::::from_string_literal(b"hello world") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -487,7 +490,7 @@ pub fn test_fseeko_4() { ); (*fp.borrow_mut()) = match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -523,7 +526,7 @@ pub fn test_fseeko_4() { assert!( (((((buf.as_pointer() as Ptr::) as Ptr::) .to_any() - .memcmp(&Ptr::from_string_literal(b"world").to_any(), 5_usize) + .memcmp(&Ptr::::from_string_literal(b"world").to_any(), 5_usize) == 0) as i32) != 0) ); @@ -563,16 +566,16 @@ pub fn test_fseeko_4() { ); } pub fn test_rename_5() { - let from: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let from: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_from.tmp", ))); - let to: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let to: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_to.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*from.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -581,7 +584,7 @@ pub fn test_rename_5() { assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); assert!( ((({ - let __bytes: Vec = Ptr::from_string_literal(b"data") + let __bytes: Vec = Ptr::::from_string_literal(b"data") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -615,7 +618,7 @@ pub fn test_rename_5() { assert!( ((((match CFile::open( &(*from.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string() + &Ptr::::from_string_literal(b"rb").to_rust_string() ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -625,7 +628,7 @@ pub fn test_rename_5() { ); (*fp.borrow_mut()) = match CFile::open( &(*to.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), + &Ptr::::from_string_literal(b"rb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -664,13 +667,13 @@ pub fn test_rename_5() { ); } pub fn test_setvbuf_6() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stdio_nofd_vbuf.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -680,7 +683,7 @@ pub fn test_setvbuf_6() { assert!((((0 == 0) as i32) != 0)); assert!( ((({ - let __bytes: Vec = Ptr::from_string_literal(b"x") + let __bytes: Vec = Ptr::::from_string_literal(b"x") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { diff --git a/tests/unit/out/refcount/strdup.rs b/tests/unit/out/refcount/strdup.rs index 0b9565304..fc9588c7c 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.rs @@ -36,13 +36,13 @@ pub fn main() { } fn main_0() -> i32 { let d: Value> = Rc::new(RefCell::new(libcc2rs::strdup_refcount( - Ptr::from_string_literal(b"hello"), + Ptr::::from_string_literal(b"hello"), ))); assert!((((!((*d.borrow()).is_null())) as i32) != 0)); assert!( ((({ let mut __it1 = (*d.borrow()).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"hello").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"hello").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -57,7 +57,7 @@ fn main_0() -> i32 { != 0) ); libcc2rs::free_refcount(((*d.borrow()).clone() as Ptr).to_any()); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"world"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"world"))); let buf: Value> = Rc::new(RefCell::new(Box::new([ (('a' as i32) as u8), (('b' as i32) as u8), diff --git a/tests/unit/out/refcount/string.rs b/tests/unit/out/refcount/string.rs index a3055f1f1..0ad42c244 100644 --- a/tests/unit/out/refcount/string.rs +++ b/tests/unit/out/refcount/string.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let s1: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"hello") + Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), @@ -39,7 +39,7 @@ fn main_0() -> i32 { .iter() .copied() .take((*s1.borrow()).len().saturating_sub(1)) - .eq(Ptr::from_string_literal(b"hello").to_c_string_iterator()) + .eq(Ptr::::from_string_literal(b"hello").to_c_string_iterator()) ); let p1: Value> = Rc::new(RefCell::new((s1.as_pointer() as Ptr))); assert!(((((*p1.borrow()).offset((0) as isize).read()) as i32) == (('h' as u8) as i32))); @@ -120,7 +120,7 @@ fn main_0() -> i32 { let mut __tmp1 = (*s1.borrow())[(1_usize) as usize ..::std::cmp::min( (1_usize + { - let __lookup: Vec = Ptr::from_string_literal(b"l") + let __lookup: Vec = Ptr::::from_string_literal(b"l") .to_c_string_iterator() .collect(); (*s1.borrow()) @@ -151,7 +151,7 @@ fn main_0() -> i32 { let s5: Value> = Rc::new(RefCell::new({ let mut r = (*s1.borrow()).clone(); r.pop(); - r.extend(Ptr::from_string_literal(b", world").to_c_string_iterator()); + r.extend(Ptr::::from_string_literal(b", world").to_c_string_iterator()); r.push(0); r })); @@ -202,7 +202,7 @@ fn main_0() -> i32 { .iter() .copied() .take((*string.borrow()).len().saturating_sub(1)) - .eq(Ptr::from_string_literal(b"bar").to_c_string_iterator()) + .eq(Ptr::::from_string_literal(b"bar").to_c_string_iterator()) ); { (*string.borrow_mut()).pop(); @@ -227,7 +227,7 @@ fn main_0() -> i32 { .iter() .copied() .take((*string.borrow()).len().saturating_sub(1)) - .eq(Ptr::from_string_literal(b"bar").to_c_string_iterator()) + .eq(Ptr::::from_string_literal(b"bar").to_c_string_iterator()) ); { (*string.borrow_mut()).pop(); @@ -287,7 +287,7 @@ fn main_0() -> i32 { let result: Value> = Rc::new(RefCell::new({ let mut r = (*string.borrow()).clone(); r.pop(); - r.extend(Ptr::from_string_literal(b" foo").to_c_string_iterator()); + r.extend(Ptr::::from_string_literal(b" foo").to_c_string_iterator()); r.push(0); r })); @@ -413,7 +413,7 @@ fn main_0() -> i32 { == (('o' as u8) as i32)) ); let pos: Value = Rc::new(RefCell::new({ - let __lookup: Vec = Ptr::from_string_literal(b"b") + let __lookup: Vec = Ptr::::from_string_literal(b"b") .to_c_string_iterator() .collect(); (*result.borrow()) @@ -424,7 +424,7 @@ fn main_0() -> i32 { })); assert!(((*pos.borrow()) == 0_usize)); (*pos.borrow_mut()) = { - let __lookup: Vec = Ptr::from_string_literal(b"f") + let __lookup: Vec = Ptr::::from_string_literal(b"f") .to_c_string_iterator() .collect(); (*result.borrow()) @@ -435,7 +435,7 @@ fn main_0() -> i32 { }; assert!(((*pos.borrow()) == 5_usize)); (*pos.borrow_mut()) = { - let __lookup: Vec = Ptr::from_string_literal(b"o") + let __lookup: Vec = Ptr::::from_string_literal(b"o") .to_c_string_iterator() .collect(); (*result.borrow()) @@ -446,7 +446,7 @@ fn main_0() -> i32 { }; assert!(((*pos.borrow()) == 7_usize)); (*pos.borrow_mut()) = { - let __lookup: Vec = Ptr::from_string_literal(b"x") + let __lookup: Vec = Ptr::::from_string_literal(b"x") .to_c_string_iterator() .collect(); (*result.borrow()) @@ -457,7 +457,7 @@ fn main_0() -> i32 { }; assert!(((*pos.borrow()) == ((-1_i64 as u64) as usize))); let string_to_cast: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"cast") + Ptr::::from_string_literal(b"cast") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), diff --git a/tests/unit/out/refcount/string2.rs b/tests/unit/out/refcount/string2.rs index d44276d44..6780b04fc 100644 --- a/tests/unit/out/refcount/string2.rs +++ b/tests/unit/out/refcount/string2.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new( - Ptr::from_string_literal(b"foo") + Ptr::::from_string_literal(b"foo") .to_c_string_iterator() .chain(std::iter::once(0)) .collect::>(), @@ -29,7 +29,7 @@ fn main_0() -> i32 { .iter() .copied() .take((*arr.borrow()).len().saturating_sub(1)) - .eq(Ptr::from_string_literal(b"fbo").to_c_string_iterator()) + .eq(Ptr::::from_string_literal(b"fbo").to_c_string_iterator()) ); return 0; } diff --git a/tests/unit/out/refcount/string_escape.rs b/tests/unit/out/refcount/string_escape.rs index aeab049aa..445494aa3 100644 --- a/tests/unit/out/refcount/string_escape.rs +++ b/tests/unit/out/refcount/string_escape.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let special: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let special: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"\x07\x08\t\n\x0b\x0c\r !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\xff", ))); thread_local!( diff --git a/tests/unit/out/refcount/string_h.rs b/tests/unit/out/refcount/string_h.rs index 849a0da6d..285b26b32 100644 --- a/tests/unit/out/refcount/string_h.rs +++ b/tests/unit/out/refcount/string_h.rs @@ -159,7 +159,7 @@ pub fn test_memmove_3() { ); } pub fn test_strchr_4() { - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).reinterpret_cast::(); let __t = ('w' as i32) as u8; @@ -197,17 +197,21 @@ pub fn test_strchr_4() { } pub fn test_strlen_5() { assert!( - (((Ptr::from_string_literal(b"").to_c_string_iterator().count() == 0_usize) as i32) != 0) + (((Ptr::::from_string_literal(b"") + .to_c_string_iterator() + .count() + == 0_usize) as i32) + != 0) ); assert!( - (((Ptr::from_string_literal(b"hello") + (((Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .count() == 5_usize) as i32) != 0) ); assert!( - (((Ptr::from_string_literal(b"hello world") + (((Ptr::::from_string_literal(b"hello world") .to_c_string_iterator() .count() == 11_usize) as i32) @@ -222,7 +226,7 @@ pub fn test_strlen_5() { assert!( ((({ let mut __it1 = (*second.borrow()).to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"two").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"two").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -257,8 +261,8 @@ pub fn test_strlen_5() { pub fn test_strcmp_6() { assert!( ((({ - let mut __it1 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it1 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -274,8 +278,8 @@ pub fn test_strcmp_6() { ); assert!( ((({ - let mut __it1 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"abd").to_c_string_iterator(); + let mut __it1 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"abd").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -291,8 +295,8 @@ pub fn test_strcmp_6() { ); assert!( ((({ - let mut __it1 = Ptr::from_string_literal(b"abd").to_c_string_iterator(); - let mut __it2 = Ptr::from_string_literal(b"abc").to_c_string_iterator(); + let mut __it1 = Ptr::::from_string_literal(b"abd").to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"abc").to_c_string_iterator(); loop { let __c1 = __it1.next(); let __c2 = __it2.next(); @@ -306,8 +310,8 @@ pub fn test_strcmp_6() { } > 0) as i32) != 0) ); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abc"))); - let q: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abd"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abc"))); + let q: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abd"))); let buf: Value> = Rc::new(RefCell::new(Box::new([ (('a' as i32) as u8), (('b' as i32) as u8), @@ -370,10 +374,10 @@ pub fn test_strncmp_7() { assert!( ((({ let __n = 3_usize; - let mut __it1 = Ptr::from_string_literal(b"abcdef") + let mut __it1 = Ptr::::from_string_literal(b"abcdef") .to_c_string_iterator() .take(__n); - let mut __it2 = Ptr::from_string_literal(b"abcxyz") + let mut __it2 = Ptr::::from_string_literal(b"abcxyz") .to_c_string_iterator() .take(__n); loop { @@ -392,10 +396,10 @@ pub fn test_strncmp_7() { assert!( ((({ let __n = 4_usize; - let mut __it1 = Ptr::from_string_literal(b"abcdef") + let mut __it1 = Ptr::::from_string_literal(b"abcdef") .to_c_string_iterator() .take(__n); - let mut __it2 = Ptr::from_string_literal(b"abcxyz") + let mut __it2 = Ptr::::from_string_literal(b"abcxyz") .to_c_string_iterator() .take(__n); loop { @@ -414,10 +418,10 @@ pub fn test_strncmp_7() { assert!( ((({ let __n = 4_usize; - let mut __it1 = Ptr::from_string_literal(b"abcxyz") + let mut __it1 = Ptr::::from_string_literal(b"abcxyz") .to_c_string_iterator() .take(__n); - let mut __it2 = Ptr::from_string_literal(b"abcdef") + let mut __it2 = Ptr::::from_string_literal(b"abcdef") .to_c_string_iterator() .take(__n); loop { @@ -433,8 +437,8 @@ pub fn test_strncmp_7() { } > 0) as i32) != 0) ); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abcdef"))); - let q: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"abcxyz"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abcdef"))); + let q: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"abcxyz"))); let buf: Value> = Rc::new(RefCell::new(Box::new([ (('a' as i32) as u8), (('b' as i32) as u8), @@ -573,7 +577,7 @@ pub fn test_memchr_8() { ); } pub fn test_strrchr_9() { - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).reinterpret_cast::(); let __t = ('l' as i32) as u8; @@ -657,8 +661,8 @@ pub fn test_strrchr_9() { pub fn test_strcspn_10() { assert!( ((({ - let __set = Ptr::from_string_literal(b"el"); - Ptr::from_string_literal(b"hello") + let __set = Ptr::::from_string_literal(b"el"); + Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -667,8 +671,8 @@ pub fn test_strcspn_10() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"xyz"); - Ptr::from_string_literal(b"abc") + let __set = Ptr::::from_string_literal(b"xyz"); + Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -677,16 +681,16 @@ pub fn test_strcspn_10() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"abc"); - Ptr::from_string_literal(b"") + let __set = Ptr::::from_string_literal(b"abc"); + Ptr::::from_string_literal(b"") .to_c_string_iterator() .take_while(|__c| !__set.to_c_string_iterator().any(|__r| __r == *__c)) .count() } == 0_usize) as i32) != 0) ); - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); - let rej: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"el"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); + let rej: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"el"))); assert!( ((({ let __set = (*rej.borrow()).clone(); @@ -701,8 +705,8 @@ pub fn test_strcspn_10() { pub fn test_strspn_11() { assert!( ((({ - let __set = Ptr::from_string_literal(b"hel"); - Ptr::from_string_literal(b"hello") + let __set = Ptr::::from_string_literal(b"hel"); + Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -711,8 +715,8 @@ pub fn test_strspn_11() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"xyz"); - Ptr::from_string_literal(b"abc") + let __set = Ptr::::from_string_literal(b"xyz"); + Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() @@ -721,16 +725,16 @@ pub fn test_strspn_11() { ); assert!( ((({ - let __set = Ptr::from_string_literal(b"a"); - Ptr::from_string_literal(b"aaa") + let __set = Ptr::::from_string_literal(b"a"); + Ptr::::from_string_literal(b"aaa") .to_c_string_iterator() .take_while(|__c| __set.to_c_string_iterator().any(|__r| __r == *__c)) .count() } == 3_usize) as i32) != 0) ); - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); - let acc: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hel"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); + let acc: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hel"))); assert!( ((({ let __set = (*acc.borrow()).clone(); @@ -743,9 +747,9 @@ pub fn test_strspn_11() { ); } pub fn test_strstr_12() { - let h: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let h: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ - let __needle = Ptr::from_string_literal(b"world"); + let __needle = Ptr::::from_string_literal(b"world"); let mut __p = (*h.borrow()).reinterpret_cast::(); loop { let mut __h = __p.to_c_string_iterator(); @@ -771,7 +775,7 @@ pub fn test_strstr_12() { ); assert!( (((({ - let __needle = Ptr::from_string_literal(b"xyz"); + let __needle = Ptr::::from_string_literal(b"xyz"); let mut __p = (*h.borrow()).reinterpret_cast::(); loop { let mut __h = __p.to_c_string_iterator(); @@ -800,7 +804,7 @@ pub fn test_strstr_12() { ]))); assert!( ((({ - let __needle = Ptr::from_string_literal(b"ll"); + let __needle = Ptr::::from_string_literal(b"ll"); let mut __p = (buf.as_pointer() as Ptr); loop { let mut __h = __p.to_c_string_iterator(); @@ -820,10 +824,10 @@ pub fn test_strstr_12() { ); } pub fn test_strpbrk_13() { - let s: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello world"))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello world"))); let r: Value> = Rc::new(RefCell::new({ let __s = (*s.borrow()).reinterpret_cast::(); - let __set = Ptr::from_string_literal(b"wo"); + let __set = Ptr::::from_string_literal(b"wo"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -843,7 +847,7 @@ pub fn test_strpbrk_13() { assert!( (((({ let __s = (*s.borrow()).reinterpret_cast::(); - let __set = Ptr::from_string_literal(b"xyz"); + let __set = Ptr::::from_string_literal(b"xyz"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -864,7 +868,7 @@ pub fn test_strpbrk_13() { assert!( ((({ let __s = (buf.as_pointer() as Ptr); - let __set = Ptr::from_string_literal(b"b"); + let __set = Ptr::::from_string_literal(b"b"); match __s .to_c_string_iterator() .position(|__c| __set.to_c_string_iterator().any(|__r| __r == __c)) @@ -879,10 +883,10 @@ pub fn test_strpbrk_13() { pub fn test_strcasecmp_14() { assert!( ((({ - let mut __it1 = Ptr::from_string_literal(b"HELLO") + let mut __it1 = Ptr::::from_string_literal(b"HELLO") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); - let mut __it2 = Ptr::from_string_literal(b"hello") + let mut __it2 = Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); loop { @@ -900,10 +904,10 @@ pub fn test_strcasecmp_14() { ); assert!( ((({ - let mut __it1 = Ptr::from_string_literal(b"abc") + let mut __it1 = Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); - let mut __it2 = Ptr::from_string_literal(b"abd") + let mut __it2 = Ptr::::from_string_literal(b"abd") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); loop { @@ -921,10 +925,10 @@ pub fn test_strcasecmp_14() { ); assert!( ((({ - let mut __it1 = Ptr::from_string_literal(b"abd") + let mut __it1 = Ptr::::from_string_literal(b"abd") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); - let mut __it2 = Ptr::from_string_literal(b"abc") + let mut __it2 = Ptr::::from_string_literal(b"abc") .to_c_string_iterator() .map(|__c| __c.to_ascii_lowercase()); loop { @@ -940,8 +944,8 @@ pub fn test_strcasecmp_14() { } > 0) as i32) != 0) ); - let p: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"FOO"))); - let q: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"foo"))); + let p: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"FOO"))); + let q: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"foo"))); assert!( ((({ let mut __it1 = (*p.borrow()) diff --git a/tests/unit/out/refcount/string_literal_interior_null.rs b/tests/unit/out/refcount/string_literal_interior_null.rs index 37998b439..d6fb13622 100644 --- a/tests/unit/out/refcount/string_literal_interior_null.rs +++ b/tests/unit/out/refcount/string_literal_interior_null.rs @@ -19,7 +19,7 @@ pub fn sum_bytes_0(buf: Ptr, len: u32) -> i32 { } thread_local!( pub static g_packet_1: Value> = - Rc::new(RefCell::new(Ptr::from_string_literal(b"\x01\0"))); + Rc::new(RefCell::new(Ptr::::from_string_literal(b"\x01\0"))); ); pub fn main() { __cpp2rust_init_globals(); @@ -27,7 +27,7 @@ pub fn main() { } fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new( - ({ sum_bytes_0(Ptr::from_string_literal(b"\x01\0"), 2_u32) }), + ({ sum_bytes_0(Ptr::::from_string_literal(b"\x01\0"), 2_u32) }), )); let b: Value = Rc::new(RefCell::new( ({ sum_bytes_0((g_packet_1.with(|rc| rc.borrow().clone())).clone(), 2_u32) }), diff --git a/tests/unit/out/refcount/string_literal_ptr_init.rs b/tests/unit/out/refcount/string_literal_ptr_init.rs index cc1bd1679..0e62c4d09 100644 --- a/tests/unit/out/refcount/string_literal_ptr_init.rs +++ b/tests/unit/out/refcount/string_literal_ptr_init.rs @@ -53,12 +53,12 @@ pub fn probe_two_0() -> i32 { thread_local!( pub static table_1: Value> = Rc::new(RefCell::new(Box::new([ label { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"first"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"first"))), probe: Rc::new(RefCell::new(FnPtr:: i32>::null())), mask: Rc::new(RefCell::new((1 << 4))), }, label { - name: Rc::new(RefCell::new(Ptr::from_string_literal(b"second"))), + name: Rc::new(RefCell::new(Ptr::::from_string_literal(b"second"))), probe: Rc::new(RefCell::new((FnPtr:: i32>::new(probe_two_0)))), mask: Rc::new(RefCell::new((1 << 5))), }, @@ -125,8 +125,9 @@ fn main_0() -> i32 { == 32) as i32) != 0) ); - let tail: Value> = - Rc::new(RefCell::new((Ptr::from_string_literal(b"ab.cd").offset(2)))); + let tail: Value> = Rc::new(RefCell::new( + (Ptr::::from_string_literal(b"ab.cd").offset(2)), + )); assert!( ((((((*tail.borrow()).offset((0) as isize).read()) as i32) == ('.' as i32)) as i32) != 0) ); @@ -144,7 +145,7 @@ fn main_0() -> i32 { .clone() .to_any() } else { - Ptr::from_string_literal(b"").to_any() + Ptr::::from_string_literal(b"").to_any() })); assert!( (((((((*p.borrow()).reinterpret_cast::()) @@ -161,7 +162,7 @@ fn main_0() -> i32 { .clone() .to_any() } else { - Ptr::from_string_literal(b"").to_any() + Ptr::::from_string_literal(b"").to_any() }; assert!( (((((((*p.borrow()).reinterpret_cast::()) diff --git a/tests/unit/out/refcount/string_literals.rs b/tests/unit/out/refcount/string_literals.rs index 60a91e3e9..d95b1c1eb 100644 --- a/tests/unit/out/refcount/string_literals.rs +++ b/tests/unit/out/refcount/string_literals.rs @@ -18,24 +18,25 @@ pub fn main() { } fn main_0() -> i32 { let immutable_strings: Value]>> = Rc::new(RefCell::new(Box::new([ - Ptr::from_string_literal(b"a"), - Ptr::from_string_literal(b"b"), - Ptr::from_string_literal(b"c"), + Ptr::::from_string_literal(b"a"), + Ptr::::from_string_literal(b"b"), + Ptr::::from_string_literal(b"c"), ]))); let immutable_string: Value> = - Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); + Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); let mutable_string_arr: Value> = Rc::new(RefCell::new(Box::from(*b"papanasi\0"))); let immutable_string_arr: Value> = Rc::new(RefCell::new(Box::from(*b"papanasi\0"))); - let immutable_empty: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b""))); + let immutable_empty: Value> = + Rc::new(RefCell::new(Ptr::::from_string_literal(b""))); let mutable_empty_arr: Value> = Rc::new(RefCell::new(vec![0u8; 1].into_boxed_slice())); let immutable_empty_arr: Value> = Rc::new(RefCell::new(vec![0u8; 1].into_boxed_slice())); ({ foo_mut_0((mutable_string_arr.as_pointer() as Ptr)) }); - ({ foo_const_1(Ptr::from_string_literal(b"world")) }); + ({ foo_const_1(Ptr::::from_string_literal(b"world")) }); ({ foo_const_1((*immutable_string.borrow()).clone()) }); ({ foo_const_1((immutable_string_arr.as_pointer() as Ptr)) }); - ({ foo_const_1(Ptr::from_string_literal(b"")) }); + ({ foo_const_1(Ptr::::from_string_literal(b"")) }); ({ foo_const_1((*immutable_empty.borrow()).clone()) }); ({ foo_const_1((immutable_empty_arr.as_pointer() as Ptr)) }); let inited_through_init_list: Value> = diff --git a/tests/unit/out/refcount/string_literals_c.rs b/tests/unit/out/refcount/string_literals_c.rs index 799970b24..8693f38d4 100644 --- a/tests/unit/out/refcount/string_literals_c.rs +++ b/tests/unit/out/refcount/string_literals_c.rs @@ -18,35 +18,37 @@ pub fn main() { } fn main_0() -> i32 { let mutable_strings: Value]>> = Rc::new(RefCell::new(Box::new([ - Ptr::from_string_literal(b"a"), - Ptr::from_string_literal(b"b"), - Ptr::from_string_literal(b"c"), + Ptr::::from_string_literal(b"a"), + Ptr::::from_string_literal(b"b"), + Ptr::::from_string_literal(b"c"), ]))); let immutable_strings: Value]>> = Rc::new(RefCell::new(Box::new([ - Ptr::from_string_literal(b"a"), - Ptr::from_string_literal(b"b"), - Ptr::from_string_literal(b"c"), + Ptr::::from_string_literal(b"a"), + Ptr::::from_string_literal(b"b"), + Ptr::::from_string_literal(b"c"), ]))); - let mutable_string: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); + let mutable_string: Value> = + Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); let immutable_string: Value> = - Rc::new(RefCell::new(Ptr::from_string_literal(b"hello"))); + Rc::new(RefCell::new(Ptr::::from_string_literal(b"hello"))); let mutable_string_arr: Value> = Rc::new(RefCell::new(Box::from(*b"papanasi\0"))); let immutable_string_arr: Value> = Rc::new(RefCell::new(Box::from(*b"papanasi\0"))); - let mutable_empty: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b""))); - let immutable_empty: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b""))); + let mutable_empty: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b""))); + let immutable_empty: Value> = + Rc::new(RefCell::new(Ptr::::from_string_literal(b""))); let mutable_empty_arr: Value> = Rc::new(RefCell::new(vec![0u8; 1].into_boxed_slice())); let immutable_empty_arr: Value> = Rc::new(RefCell::new(vec![0u8; 1].into_boxed_slice())); - ({ foo_mut_0(Ptr::from_string_literal(b"world")) }); + ({ foo_mut_0(Ptr::::from_string_literal(b"world")) }); ({ foo_mut_0((*mutable_string.borrow()).clone()) }); ({ foo_mut_0((mutable_string_arr.as_pointer() as Ptr)) }); - ({ foo_const_1(Ptr::from_string_literal(b"world")) }); + ({ foo_const_1(Ptr::::from_string_literal(b"world")) }); ({ foo_const_1((*mutable_string.borrow()).clone()) }); ({ foo_const_1((*immutable_string.borrow()).clone()) }); ({ foo_const_1((mutable_string_arr.as_pointer() as Ptr)) }); ({ foo_const_1((immutable_string_arr.as_pointer() as Ptr)) }); - ({ foo_const_1(Ptr::from_string_literal(b"")) }); + ({ foo_const_1(Ptr::::from_string_literal(b"")) }); ({ foo_const_1((*mutable_empty.borrow()).clone()) }); ({ foo_const_1((*immutable_empty.borrow()).clone()) }); ({ foo_const_1((mutable_empty_arr.as_pointer() as Ptr)) }); diff --git a/tests/unit/out/refcount/string_literals_concat.rs b/tests/unit/out/refcount/string_literals_concat.rs index 4c19974d0..4e899208f 100644 --- a/tests/unit/out/refcount/string_literals_concat.rs +++ b/tests/unit/out/refcount/string_literals_concat.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let joined: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let joined: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"alpha\nbeta\ngamma\n", ))); assert!(((((*joined.borrow()).offset((0) as isize).read()) as i32) == (('a' as u8) as i32))); @@ -23,7 +23,7 @@ fn main_0() -> i32 { assert!((((*arr.borrow())[(5) as usize] as i32) == (('r' as u8) as i32))); assert!((((*arr.borrow())[(6) as usize] as i32) == (('\0' as u8) as i32))); let split_pieces: Value> = - Rc::new(RefCell::new(Ptr::from_string_literal(b"abcdefghi"))); + Rc::new(RefCell::new(Ptr::::from_string_literal(b"abcdefghi"))); assert!( ((((*split_pieces.borrow()).offset((0) as isize).read()) as i32) == (('a' as u8) as i32)) ); diff --git a/tests/unit/out/refcount/string_literals_concat_c.rs b/tests/unit/out/refcount/string_literals_concat_c.rs index 9eb38e846..7f5a8bc58 100644 --- a/tests/unit/out/refcount/string_literals_concat_c.rs +++ b/tests/unit/out/refcount/string_literals_concat_c.rs @@ -17,7 +17,7 @@ fn main_0() -> i32 { assert!((((((*arr.borrow())[(5) as usize] as i32) == ('r' as i32)) as i32) != 0)); assert!((((((*arr.borrow())[(6) as usize] as i32) == ('\0' as i32)) as i32) != 0)); let split_pieces: Value> = - Rc::new(RefCell::new(Ptr::from_string_literal(b"abcdefghi"))); + Rc::new(RefCell::new(Ptr::::from_string_literal(b"abcdefghi"))); assert!( ((((((*split_pieces.borrow()).offset((0) as isize).read()) as i32) == ('a' as i32)) as i32) diff --git a/tests/unit/out/refcount/string_literals_return.rs b/tests/unit/out/refcount/string_literals_return.rs index feabaa41a..ccd353fb2 100644 --- a/tests/unit/out/refcount/string_literals_return.rs +++ b/tests/unit/out/refcount/string_literals_return.rs @@ -7,17 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn get_greeting_0() -> Ptr { - return Ptr::from_string_literal(b"hello"); + return Ptr::::from_string_literal(b"hello"); } pub fn get_empty_1() -> Ptr { - return Ptr::from_string_literal(b""); + return Ptr::::from_string_literal(b""); } pub fn get_branch_2(x: i32) -> Ptr { let x: Value = Rc::new(RefCell::new(x)); if ((*x.borrow()) > 0) { - return Ptr::from_string_literal(b"positive"); + return Ptr::::from_string_literal(b"positive"); } - return Ptr::from_string_literal(b"non-positive"); + return Ptr::::from_string_literal(b"non-positive"); } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/string_literals_return_c.rs b/tests/unit/out/refcount/string_literals_return_c.rs index 22a10fff6..48df112f3 100644 --- a/tests/unit/out/refcount/string_literals_return_c.rs +++ b/tests/unit/out/refcount/string_literals_return_c.rs @@ -7,17 +7,17 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn get_greeting_0() -> Ptr { - return Ptr::from_string_literal(b"hello"); + return Ptr::::from_string_literal(b"hello"); } pub fn get_empty_1() -> Ptr { - return Ptr::from_string_literal(b""); + return Ptr::::from_string_literal(b""); } pub fn get_branch_2(x: i32) -> Ptr { let x: Value = Rc::new(RefCell::new(x)); if ((((*x.borrow()) > 0) as i32) != 0) { - return Ptr::from_string_literal(b"positive"); + return Ptr::::from_string_literal(b"positive"); } - return Ptr::from_string_literal(b"non-positive"); + return Ptr::::from_string_literal(b"non-positive"); } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/sys_stat.rs b/tests/unit/out/refcount/sys_stat.rs index 059caa119..2ebc6648d 100644 --- a/tests/unit/out/refcount/sys_stat.rs +++ b/tests/unit/out/refcount/sys_stat.rs @@ -7,13 +7,13 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn test_stat_0() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_stat_test.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -21,7 +21,7 @@ pub fn test_stat_0() { )); assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); { - let __bytes: Vec = Ptr::from_string_literal(b"hello") + let __bytes: Vec = Ptr::::from_string_literal(b"hello") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { @@ -62,13 +62,13 @@ pub fn test_stat_0() { }; } pub fn test_fstat_1() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_fstat_test.tmp", ))); let fp: Value> = Rc::new(RefCell::new( match CFile::open( &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), + &Ptr::::from_string_literal(b"wb").to_rust_string(), ) { Some(__f) => Ptr::alloc(__f), None => Ptr::null(), @@ -76,7 +76,7 @@ pub fn test_fstat_1() { )); assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); { - let __bytes: Vec = Ptr::from_string_literal(b"hello world") + let __bytes: Vec = Ptr::::from_string_literal(b"hello world") .to_c_string_iterator() .collect(); match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { diff --git a/tests/unit/out/refcount/sys_time.rs b/tests/unit/out/refcount/sys_time.rs index fedcc56bc..c3c73d52c 100644 --- a/tests/unit/out/refcount/sys_time.rs +++ b/tests/unit/out/refcount/sys_time.rs @@ -171,7 +171,7 @@ pub fn test_strftime_5() { let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); let __text = match __dt { Ok(__d) => jiff::fmt::strtime::format( - Ptr::from_string_literal(b"%Y-%m-%d %H:%M:%S") + Ptr::::from_string_literal(b"%Y-%m-%d %H:%M:%S") .to_rust_string() .as_str(), __d, @@ -197,7 +197,7 @@ pub fn test_strftime_5() { let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); let __text = match __dt { Ok(__d) => jiff::fmt::strtime::format( - Ptr::from_string_literal(b"%a, %d %b %Y %T") + Ptr::::from_string_literal(b"%a, %d %b %Y %T") .to_rust_string() .as_str(), __d, @@ -223,7 +223,7 @@ pub fn test_strftime_5() { let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); let __text = match __dt { Ok(__d) => jiff::fmt::strtime::format( - Ptr::from_string_literal(b"day %j 100%%") + Ptr::::from_string_literal(b"day %j 100%%") .to_rust_string() .as_str(), __d, @@ -249,7 +249,9 @@ pub fn test_strftime_5() { let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); let __text = match __dt { Ok(__d) => jiff::fmt::strtime::format( - Ptr::from_string_literal(b"%e").to_rust_string().as_str(), + Ptr::::from_string_literal(b"%e") + .to_rust_string() + .as_str(), __d, ) .unwrap_or_default(), @@ -276,7 +278,7 @@ pub fn test_strftime_5() { let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); let __text = match __dt { Ok(__d) => jiff::fmt::strtime::format( - Ptr::from_string_literal(b"%Y-%m-%d") + Ptr::::from_string_literal(b"%Y-%m-%d") .to_rust_string() .as_str(), __d, diff --git a/tests/unit/out/refcount/termios.rs b/tests/unit/out/refcount/termios.rs index e3bb7ee4a..75aba5b3d 100644 --- a/tests/unit/out/refcount/termios.rs +++ b/tests/unit/out/refcount/termios.rs @@ -11,7 +11,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( + let path: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal( b"cpp2rust_termios_test.tmp", ))); let fd: Value = Rc::new(RefCell::new({ diff --git a/tests/unit/out/refcount/union_tagged_many_arms.rs b/tests/unit/out/refcount/union_tagged_many_arms.rs index 0a2f0986b..6ded4a320 100644 --- a/tests/unit/out/refcount/union_tagged_many_arms.rs +++ b/tests/unit/out/refcount/union_tagged_many_arms.rs @@ -112,7 +112,7 @@ fn main_0() -> i32 { (*(*c.borrow()).tag.borrow_mut()) = Tag_enum_T_TEXT; (*(*c.borrow()).payload.borrow_mut()) .text() - .write(Ptr::from_string_literal(b"hello")); + .write(Ptr::::from_string_literal(b"hello")); assert!( (((((((*(*c.borrow()).payload.borrow()).text().read()) .offset((0) as isize) diff --git a/tests/unit/out/refcount/union_tagged_struct_arms.rs b/tests/unit/out/refcount/union_tagged_struct_arms.rs index 5d795225b..3a2d418b6 100644 --- a/tests/unit/out/refcount/union_tagged_struct_arms.rs +++ b/tests/unit/out/refcount/union_tagged_struct_arms.rs @@ -198,9 +198,9 @@ pub fn main() { fn main_0() -> i32 { thread_local!( static items_4: Value]>> = Rc::new(RefCell::new(Box::new([ - Ptr::from_string_literal(b"a"), - Ptr::from_string_literal(b"b"), - Ptr::from_string_literal(b"c"), + Ptr::::from_string_literal(b"a"), + Ptr::::from_string_literal(b"b"), + Ptr::::from_string_literal(b"c"), ]))); ); let p_list: Value = >::default(); diff --git a/tests/unit/out/refcount/user_defined_same_as_libc.rs b/tests/unit/out/refcount/user_defined_same_as_libc.rs index 5ff492969..bc1cfd57d 100644 --- a/tests/unit/out/refcount/user_defined_same_as_libc.rs +++ b/tests/unit/out/refcount/user_defined_same_as_libc.rs @@ -21,8 +21,8 @@ fn main_0() -> i32 { let fp: Value> = Rc::new(RefCell::new( ({ fopen_0( - Ptr::from_string_literal(b"irrelevant-file"), - Ptr::from_string_literal(b"r"), + Ptr::::from_string_literal(b"irrelevant-file"), + Ptr::::from_string_literal(b"r"), ) }), )); diff --git a/tests/unit/out/refcount/va_arg_conditional.rs b/tests/unit/out/refcount/va_arg_conditional.rs index c2a0c4943..0050699f6 100644 --- a/tests/unit/out/refcount/va_arg_conditional.rs +++ b/tests/unit/out/refcount/va_arg_conditional.rs @@ -23,13 +23,13 @@ pub fn main() { } fn main_0() -> i32 { assert!( - (((({ conditional_log_0(1, Ptr::from_string_literal(b"%d"), &[(42).into(),]) }) == 42) + (((({ conditional_log_0(1, Ptr::::from_string_literal(b"%d"), &[(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"), &[(99).into(),]) }) + == -1_i32) as i32) != 0) ); return 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 188fa6543..8ae87c7f0 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -50,7 +50,7 @@ pub fn dispatch_0(option: i32, __args: &[VaArg]) -> i32 { __v if __v == (opt_OPT_STRING_OUT as i32) => { let out: Value>> = Rc::new(RefCell::new((*ap.borrow_mut()).arg::>>())); - (*out.borrow()).write(Ptr::from_string_literal(b"hello")); + (*out.borrow()).write(Ptr::::from_string_literal(b"hello")); (*result.borrow_mut()) = 1; break 'switch; } diff --git a/tests/unit/out/refcount/va_arg_printf.rs b/tests/unit/out/refcount/va_arg_printf.rs index 3d106702a..924844341 100644 --- a/tests/unit/out/refcount/va_arg_printf.rs +++ b/tests/unit/out/refcount/va_arg_printf.rs @@ -39,11 +39,11 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let dummy: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"dummy"))); + let dummy: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"dummy"))); assert!( (((({ logf_1( - Ptr::from_string_literal(b"hello %d %d"), + Ptr::::from_string_literal(b"hello %d %d"), &[ (10).into(), ((*dummy.borrow()).to_c_string_iterator().count()).into(), @@ -55,7 +55,7 @@ fn main_0() -> i32 { assert!( (((({ logf_1( - Ptr::from_string_literal(b"x %d %d"), + Ptr::::from_string_literal(b"x %d %d"), &[(1).into(), (2).into()], ) }) == 3) as i32) @@ -64,7 +64,7 @@ fn main_0() -> i32 { assert!( (((({ lenf_2( - Ptr::from_string_literal(b"%s"), + Ptr::::from_string_literal(b"%s"), &[((*dummy.borrow()).clone()).into()], ) }) == 5) as i32) @@ -73,12 +73,12 @@ fn main_0() -> i32 { assert!( (((({ lenf_2( - Ptr::from_string_literal(b"%s"), + Ptr::::from_string_literal(b"%s"), &[ (if ((((*dummy.borrow()).offset((0) as isize).read()) as i32) != 0) { (*dummy.borrow()).clone() } else { - Ptr::from_string_literal(b"") + Ptr::::from_string_literal(b"") }) .into(), ], diff --git a/tests/unit/out/refcount/va_arg_snprintf.rs b/tests/unit/out/refcount/va_arg_snprintf.rs index 2d02e04da..22e2a4d10 100644 --- a/tests/unit/out/refcount/va_arg_snprintf.rs +++ b/tests/unit/out/refcount/va_arg_snprintf.rs @@ -30,7 +30,7 @@ fn main_0() -> i32 { extract_first_0( (buf.as_pointer() as Ptr), 1, - Ptr::from_string_literal(b"%d"), + Ptr::::from_string_literal(b"%d"), &[(42).into()], ) }) == 42) as i32) @@ -42,7 +42,7 @@ fn main_0() -> i32 { extract_first_0( (buf.as_pointer() as Ptr), 1, - Ptr::from_string_literal(b"%d"), + Ptr::::from_string_literal(b"%d"), &[(65).into()], ) }) == 65) as i32) diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index 8c269fb10..6da947639 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -55,7 +55,7 @@ fn main_0() -> i32 { ({ set_error_0( (ctx.as_pointer()), - Ptr::from_string_literal(b"error %d"), + Ptr::::from_string_literal(b"error %d"), &[(42).into()], ) }); @@ -64,7 +64,7 @@ fn main_0() -> i32 { ({ set_error_0( (ctx.as_pointer()), - Ptr::from_string_literal(b"error %d"), + Ptr::::from_string_literal(b"error %d"), &[(99).into()], ) }); From c7e8013ff552224870b4ec51af229ee046f5f133 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:01:38 +0100 Subject: [PATCH 02/10] Add from_string_literal for wide chars --- libcc2rs/src/cstr.rs | 66 +++++++++++++++++++-------------- libcc2rs/src/libc_shims/time.rs | 2 +- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/libcc2rs/src/cstr.rs b/libcc2rs/src/cstr.rs index 807fd5974..fd3a42306 100644 --- a/libcc2rs/src/cstr.rs +++ b/libcc2rs/src/cstr.rs @@ -27,32 +27,49 @@ impl fmt::Display for Ptr { } } -type StringLiteralMap = HashMap<&'static [u8], Rc>>>; +macro_rules! impl_string_literal { + ($t:ty, $cache:ident) => { + thread_local! { + static $cache: RefCell>>>> = + RefCell::new(HashMap::new()); + } -thread_local! { - static STRING_LITERALS: RefCell = RefCell::new(HashMap::new()); -} + impl Ptr> { + #[inline] + pub fn from_string_literal_array(s: &'static [$t]) -> Self { + $cache.with(|literals| { + let mut literals = literals.borrow_mut(); + let weak = Rc::downgrade(literals.entry(s).or_insert_with(|| { + Rc::new(RefCell::new({ + let mut v = s.to_vec(); + v.push(0); + v.into_boxed_slice() + })) + })); + Ptr { + offset: 0, + kind: PtrKind::StackSingle(weak), + } + }) + } + } -impl Ptr> { - #[inline] - pub fn from_string_literal_array(s: &'static [u8]) -> Self { - STRING_LITERALS.with(|literals| { - let mut literals = literals.borrow_mut(); - let weak = Rc::downgrade(literals.entry(s).or_insert_with(|| { - Rc::new(RefCell::new({ - let mut v = s.to_vec(); - v.push(0); - v.into_boxed_slice() - })) - })); - Ptr { - offset: 0, - kind: PtrKind::StackSingle(weak), + impl Ptr<$t> { + #[inline] + pub fn from_string_literal(s: &'static [$t]) -> Self { + Ptr::>::from_string_literal_array(s) + .to_strong() + .as_pointer() } - }) - } + } + }; } +impl_string_literal!(u8, STRING_LITERALS_U8); +impl_string_literal!(u16, STRING_LITERALS_U16); +impl_string_literal!(u32, STRING_LITERALS_U32); +impl_string_literal!(i32, STRING_LITERALS_I32); + impl Ptr { #[allow(clippy::explicit_counter_loop)] pub fn memcpy(&self, src: &Self, len: usize) { @@ -104,13 +121,6 @@ impl Ptr { 0 } - #[inline] - pub fn from_string_literal(s: &'static [u8]) -> Self { - Ptr::>::from_string_literal_array(s) - .to_strong() - .as_pointer() - } - pub fn to_c_string_iterator(&self) -> CStringIterator { CStringIterator { ptr: self.clone() } } diff --git a/libcc2rs/src/libc_shims/time.rs b/libcc2rs/src/libc_shims/time.rs index a1e6fd5ce..e53a896de 100644 --- a/libcc2rs/src/libc_shims/time.rs +++ b/libcc2rs/src/libc_shims/time.rs @@ -37,7 +37,7 @@ impl Tm { let zone: &'static [u8] = b"GMT"; #[cfg(target_os = "macos")] let zone: &'static [u8] = b"UTC"; - *tm.tm_zone.borrow_mut() = Ptr::from_string_literal(zone); + *tm.tm_zone.borrow_mut() = Ptr::::from_string_literal(zone); tm } From a6ca350ab70391e8dc8a0874450fc86aa37ebb10 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:01:47 +0100 Subject: [PATCH 03/10] Update rules --- rules/locale/tgt_refcount.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/locale/tgt_refcount.rs b/rules/locale/tgt_refcount.rs index 0e432f581..3fb096d89 100644 --- a/rules/locale/tgt_refcount.rs +++ b/rules/locale/tgt_refcount.rs @@ -8,5 +8,5 @@ use libcc2rs::*; // TODO: we need to track ourselves the locale settings and change the behavior of the relevant // functions based on the set locale. fn f1(a0: i32, a1: Ptr) -> Ptr { - Ptr::from_string_literal(b"C") + Ptr::::from_string_literal(b"C") } From 9e0b9dd46f186ee512d06da47ee1b12fea351478 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:04:11 +0100 Subject: [PATCH 04/10] Call from_string_literal with turbofish --- .../converter/models/converter_refcount.cpp | 11 +++- tests/unit/wide_char.cpp | 58 +++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/unit/wide_char.cpp diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index e139bf48b..9cd66d614 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1272,7 +1272,8 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { return false; } if (IsStringLiteralExpr(sub_expr)) { - StrCat(std::format("Ptr::from_string_literal({})", + auto code_unit = GetStringLiteralCodeUnit(sub_expr); + StrCat(std::format("Ptr::<{}>::from_string_literal({})", code_unit, ToString(sub_expr->IgnoreParens()))); computed_expr_type_ = ComputedExprType::FreshPointer; return false; @@ -2144,7 +2145,9 @@ std::string ConverterRefCount::ConvertVarInitValue(clang::QualType qual_type, } if (qual_type.getNonReferenceType()->isArrayType()) { if (IsStringLiteralExpr(expr)) { - return std::format("Ptr::from_string_literal_array({})", + auto code_unit = GetStringLiteralCodeUnit(expr); + return std::format("Ptr::>::from_string_literal_array({})", + code_unit, ToString(expr->IgnoreParens()->IgnoreImplicit())); } return std::format("({} as {})", ConvertFreshPointer(expr), @@ -2414,7 +2417,9 @@ void ConverterRefCount::ConvertArraySubscript(clang::Expr *base, { PushParen paren(*this, is_inner_boxed); if (IsStringLiteralExpr(base)) { - StrCat(std::format("Ptr::from_string_literal({}).offset({})", + auto code_unit = GetStringLiteralCodeUnit(base); + StrCat(std::format("Ptr::<{}>::from_string_literal({}).offset({})", + code_unit, ToString(base->IgnoreParens()->IgnoreImplicit()), ConvertSubscriptIndex(idx))); } else { diff --git a/tests/unit/wide_char.cpp b/tests/unit/wide_char.cpp new file mode 100644 index 000000000..176dddb3a --- /dev/null +++ b/tests/unit/wide_char.cpp @@ -0,0 +1,58 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 + +#include +#include + +constexpr const char *get(const char *s) { return s; } +constexpr const wchar_t *get(const wchar_t *s) { return s; } +constexpr const char8_t *get(const char8_t *s) { return s; } +constexpr const char16_t *get(const char16_t *s) { return s; } +constexpr const char32_t *get(const char32_t *s) { return s; } + +constexpr char second(const char (&s)[3]) { return s[1]; } +constexpr wchar_t second(const wchar_t (&s)[3]) { return s[1]; } +constexpr char8_t second(const char8_t (&s)[3]) { return s[1]; } +constexpr char16_t second(const char16_t (&s)[3]) { return s[1]; } +constexpr char32_t second(const char32_t (&s)[3]) { return s[1]; } + +int main() { + const char *c = "A"; + const wchar_t *w = L"AĂ"; + const char8_t *b = u8"Ă"; + const char16_t *s = u"AĂ"; + const char32_t *l = U"AĂ"; + + assert(c[0] == 'A'); + assert(b[0] == 0xC4 && b[1] == 0x82); + assert(w[1] == 0x102); + assert(s[1] == 0x102); + assert(l[1] == 0x102); + assert(w[2] == 0 && s[2] == 0 && l[2] == 0); + + assert(get("A")[0] == 'A'); + assert(get(L"Ă")[0] == 0x102); + assert(get(u8"Ă")[0] == 0xC4); + assert(get(u"Ă")[0] == 0x102); + assert(get(U"Ă")[0] == 0x102); + + assert(second("AB") == 'B'); + assert(second(L"AĂ") == 0x102); + assert(second(u8"Ă") == 0x82); + assert(second(u"AĂ") == 0x102); + assert(second(U"AĂ") == 0x102); + + const std::size_t nw = sizeof(L"abc") / sizeof(wchar_t) - 1; + const std::size_t nb = sizeof(u8"abc") / sizeof(char8_t) - 1; + const std::size_t ns = sizeof(u"abc") / sizeof(char16_t) - 1; + const std::size_t nl = sizeof(U"abc") / sizeof(char32_t) - 1; + assert(nw == 3 && nb == 3 && ns == 3 && nl == 3); + + const wchar_t pw[4] = L"Ă"; + const char16_t ps[4] = u"Ă"; + assert(pw[0] == 0x102 && pw[1] == 0 && pw[3] == 0); + assert(ps[0] == 0x102 && ps[1] == 0 && ps[3] == 0); + + const wchar_t ew[2] = L""; + assert(ew[0] == 0 && ew[1] == 0); + return 0; +} From 77a16d59f413451e1b7025b78c4fdf52541292ad Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:05:20 +0100 Subject: [PATCH 05/10] Add wide char test --- tests/unit/out/refcount/wide_char.rs | 197 +++++++++++++++++++++++++++ tests/unit/out/unsafe/wide_char.rs | 121 ++++++++++++++++ 2 files changed, 318 insertions(+) create mode 100644 tests/unit/out/refcount/wide_char.rs create mode 100644 tests/unit/out/unsafe/wide_char.rs diff --git a/tests/unit/out/refcount/wide_char.rs b/tests/unit/out/refcount/wide_char.rs new file mode 100644 index 000000000..e8b91ea23 --- /dev/null +++ b/tests/unit/out/refcount/wide_char.rs @@ -0,0 +1,197 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn get_0(s: Ptr) -> Ptr { + let s: Value> = Rc::new(RefCell::new(s)); + return (*s.borrow()).clone(); +} +pub fn get_1(s: Ptr) -> Ptr { + let s: Value> = Rc::new(RefCell::new(s)); + return (*s.borrow()).clone(); +} +pub fn get_2(s: Ptr) -> Ptr { + let s: Value> = Rc::new(RefCell::new(s)); + return (*s.borrow()).clone(); +} +pub fn get_3(s: Ptr) -> Ptr { + let s: Value> = Rc::new(RefCell::new(s)); + return (*s.borrow()).clone(); +} +pub fn get_4(s: Ptr) -> Ptr { + let s: Value> = Rc::new(RefCell::new(s)); + return (*s.borrow()).clone(); +} +pub fn second_5(s: Ptr>) -> u8 { + return ((s.to_strong().as_pointer() as Ptr) + .offset((1) as isize) + .read()); +} +pub fn second_6(s: Ptr>) -> i32 { + return ((s.to_strong().as_pointer() as Ptr) + .offset((1) as isize) + .read()); +} +pub fn second_7(s: Ptr>) -> u8 { + return ((s.to_strong().as_pointer() as Ptr) + .offset((1) as isize) + .read()); +} +pub fn second_8(s: Ptr>) -> u16 { + return ((s.to_strong().as_pointer() as Ptr) + .offset((1) as isize) + .read()); +} +pub fn second_9(s: Ptr>) -> u32 { + return ((s.to_strong().as_pointer() as Ptr) + .offset((1) as isize) + .read()); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let c: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(b"A"))); + let w: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(&[ + 65 as i32, 258 as i32, 0 as i32, + ]))); + let b: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(&[ + 196 as u8, 130 as u8, 0 as u8, + ]))); + let s: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(&[ + 65 as u16, 258 as u16, 0 as u16, + ]))); + let l: Value> = Rc::new(RefCell::new(Ptr::::from_string_literal(&[ + 65 as u32, 258 as u32, 0 as u32, + ]))); + assert!(((((*c.borrow()).offset((0) as isize).read()) as i32) == (('A' as u8) as i32))); + assert!( + ((((*b.borrow()).offset((0) as isize).read()) as i32) == 196) + && ((((*b.borrow()).offset((1) as isize).read()) as i32) == 130) + ); + assert!((((*w.borrow()).offset((1) as isize).read()) == 258)); + assert!(((((*s.borrow()).offset((1) as isize).read()) as i32) == 258)); + assert!((((*l.borrow()).offset((1) as isize).read()) == 258_u32)); + assert!( + ((((*w.borrow()).offset((2) as isize).read()) == 0) + && ((((*s.borrow()).offset((2) as isize).read()) as i32) == 0)) + && (((*l.borrow()).offset((2) as isize).read()) == 0_u32) + ); + assert!( + (((({ get_0(Ptr::::from_string_literal(b"A"),) }) + .offset((0) as isize) + .read()) as i32) + == (('A' as u8) as i32)) + ); + assert!( + ((({ get_1(Ptr::::from_string_literal(&[258 as i32, 0 as i32,]),) }) + .offset((0) as isize) + .read()) + == 258) + ); + assert!( + (((({ + get_2(Ptr::::from_string_literal(&[ + 196 as u8, 130 as u8, 0 as u8, + ])) + }) + .offset((0) as isize) + .read()) as i32) + == 196) + ); + assert!( + (((({ get_3(Ptr::::from_string_literal(&[258 as u16, 0 as u16,]),) }) + .offset((0) as isize) + .read()) as i32) + == 258) + ); + assert!( + ((({ get_4(Ptr::::from_string_literal(&[258 as u32, 0 as u32,]),) }) + .offset((0) as isize) + .read()) + == 258_u32) + ); + assert!( + ((({ second_5(Ptr::>::from_string_literal_array(b"AB"),) }) as i32) + == (('B' as u8) as i32)) + ); + assert!( + (({ + second_6(Ptr::>::from_string_literal_array(&[ + 65 as i32, 258 as i32, 0 as i32, + ])) + }) == 258) + ); + assert!( + ((({ + second_7(Ptr::>::from_string_literal_array(&[ + 196 as u8, 130 as u8, 0 as u8, + ])) + }) as i32) + == 130) + ); + assert!( + ((({ + second_8(Ptr::>::from_string_literal_array(&[ + 65 as u16, 258 as u16, 0 as u16, + ])) + }) as i32) + == 258) + ); + assert!( + (({ + second_9(Ptr::>::from_string_literal_array(&[ + 65 as u32, 258 as u32, 0 as u32, + ])) + }) == 258_u32) + ); + let nw: Value = Rc::new(RefCell::new( + ((::std::mem::size_of::<[i32; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize), + )); + let nb: Value = Rc::new(RefCell::new( + ((::std::mem::size_of::<[u8; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize), + )); + let ns: Value = Rc::new(RefCell::new( + ((::std::mem::size_of::<[u16; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize), + )); + let nl: Value = Rc::new(RefCell::new( + ((::std::mem::size_of::<[u32; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize), + )); + assert!( + ((((*nw.borrow()) == 3_usize) && ((*nb.borrow()) == 3_usize)) + && ((*ns.borrow()) == 3_usize)) + && ((*nl.borrow()) == 3_usize) + ); + let pw: Value> = Rc::new(RefCell::new(Box::from([ + 258 as i32, 0 as i32, 0 as i32, 0 as i32, + ]))); + let ps: Value> = Rc::new(RefCell::new(Box::from([ + 258 as u16, 0 as u16, 0 as u16, 0 as u16, + ]))); + assert!( + (((*pw.borrow())[(0) as usize] == 258) && ((*pw.borrow())[(1) as usize] == 0)) + && ((*pw.borrow())[(3) as usize] == 0) + ); + assert!( + ((((*ps.borrow())[(0) as usize] as i32) == 258) + && (((*ps.borrow())[(1) as usize] as i32) == 0)) + && (((*ps.borrow())[(3) as usize] as i32) == 0) + ); + let ew: Value> = Rc::new(RefCell::new(Box::from([0 as i32, 0 as i32]))); + assert!(((*ew.borrow())[(0) as usize] == 0) && ((*ew.borrow())[(1) as usize] == 0)); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/wide_char.rs b/tests/unit/out/unsafe/wide_char.rs new file mode 100644 index 000000000..228a43878 --- /dev/null +++ b/tests/unit/out/unsafe/wide_char.rs @@ -0,0 +1,121 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn get_0(mut s: *const libc::c_char) -> *const libc::c_char { + return s; +} +pub unsafe fn get_1(mut s: *const i32) -> *const i32 { + return s; +} +pub unsafe fn get_2(mut s: *const u8) -> *const u8 { + return s; +} +pub unsafe fn get_3(mut s: *const u16) -> *const u16 { + return s; +} +pub unsafe fn get_4(mut s: *const u32) -> *const u32 { + return s; +} +pub unsafe fn second_5(s: *const [libc::c_char; 3]) -> libc::c_char { + return (*s)[(1) as usize]; +} +pub unsafe fn second_6(s: *const [i32; 3]) -> i32 { + return (*s)[(1) as usize]; +} +pub unsafe fn second_7(s: *const [u8; 3]) -> u8 { + return (*s)[(1) as usize]; +} +pub unsafe fn second_8(s: *const [u16; 3]) -> u16 { + return (*s)[(1) as usize]; +} +pub unsafe fn second_9(s: *const [u32; 3]) -> u32 { + return (*s)[(1) as usize]; +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut c: *const libc::c_char = c"A".as_ptr(); + let mut w: *const i32 = (&[65 as i32, 258 as i32, 0 as i32]).as_ptr(); + let mut b: *const u8 = (&[196 as u8, 130 as u8, 0 as u8]).as_ptr(); + let mut s: *const u16 = (&[65 as u16, 258 as u16, 0 as u16]).as_ptr(); + let mut l: *const u32 = (&[65 as u32, 258 as u32, 0 as u32]).as_ptr(); + assert!((((*c.offset((0) as isize)) as i32) == (('A' as libc::c_char) as i32))); + assert!( + (((*b.offset((0) as isize)) as i32) == (196)) + && (((*b.offset((1) as isize)) as i32) == (130)) + ); + assert!(((*w.offset((1) as isize)) == (258))); + assert!((((*s.offset((1) as isize)) as i32) == (258))); + assert!(((*l.offset((1) as isize)) == (258_u32))); + assert!( + (((*w.offset((2) as isize)) == (0)) && (((*s.offset((2) as isize)) as i32) == (0))) + && ((*l.offset((2) as isize)) == (0_u32)) + ); + assert!( + (((*(unsafe { get_0(c"A".as_ptr(),) }).offset((0) as isize)) as i32) + == (('A' as libc::c_char) as i32)) + ); + assert!( + ((*(unsafe { get_1((&[258 as i32, 0 as i32,]).as_ptr(),) }).offset((0) as isize)) == (258)) + ); + assert!( + (((*(unsafe { get_2((&[196 as u8, 130 as u8, 0 as u8,]).as_ptr(),) }).offset((0) as isize)) + as i32) + == (196)) + ); + assert!( + (((*(unsafe { get_3((&[258 as u16, 0 as u16,]).as_ptr(),) }).offset((0) as isize)) as i32) + == (258)) + ); + assert!( + ((*(unsafe { get_4((&[258 as u32, 0 as u32,]).as_ptr(),) }).offset((0) as isize)) + == (258_u32)) + ); + assert!( + (((unsafe { second_5(&std::mem::transmute(*b"AB\0"),) }) as i32) + == (('B' as libc::c_char) as i32)) + ); + assert!(((unsafe { second_6(&(&[65 as i32, 258 as i32, 0 as i32,]),) }) == (258))); + assert!((((unsafe { second_7(&(&[196 as u8, 130 as u8, 0 as u8,]),) }) as i32) == (130))); + assert!((((unsafe { second_8(&(&[65 as u16, 258 as u16, 0 as u16,]),) }) as i32) == (258))); + assert!(((unsafe { second_9(&(&[65 as u32, 258 as u32, 0 as u32,]),) }) == (258_u32))); + let nw: usize = ((::std::mem::size_of::<[i32; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize); + let nb: usize = ((::std::mem::size_of::<[u8; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize); + let ns: usize = ((::std::mem::size_of::<[u16; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize); + let nl: usize = ((::std::mem::size_of::<[u32; 4]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) as usize) + .wrapping_sub(1_usize); + assert!( + ((((nw) == (3_usize)) && ((nb) == (3_usize))) && ((ns) == (3_usize))) + && ((nl) == (3_usize)) + ); + let pw: [i32; 4] = [258 as i32, 0 as i32, 0 as i32, 0 as i32]; + let ps: [u16; 4] = [258 as u16, 0 as u16, 0 as u16, 0 as u16]; + assert!( + (((pw[(0) as usize]) == (258)) && ((pw[(1) as usize]) == (0))) + && ((pw[(3) as usize]) == (0)) + ); + assert!( + (((ps[(0) as usize] as i32) == (258)) && ((ps[(1) as usize] as i32) == (0))) + && ((ps[(3) as usize] as i32) == (0)) + ); + let ew: [i32; 2] = [0 as i32, 0 as i32]; + assert!(((ew[(0) as usize]) == (0)) && ((ew[(1) as usize]) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} From 1ed5626fe55cce3d22ff7a6df2d85c23fe181151 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:07:10 +0100 Subject: [PATCH 06/10] Add correct cast on wide char literal --- cpp2rust/converter/converter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index cf33029e6..09e31700c 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2210,6 +2210,13 @@ bool Converter::VisitFloatingLiteral(clang::FloatingLiteral *expr) { } bool Converter::VisitCharacterLiteral(clang::CharacterLiteral *expr) { + if (expr->getKind() != clang::CharacterLiteralKind::Ascii) { + PushParen paren(*this); + StrCat(std::to_string(expr->getValue()), keyword::kAs, + ToStringBase(expr->getType())); + computed_expr_type_ = ComputedExprType::FreshValue; + return false; + } auto uc = static_cast(expr->getValue()); std::string ch = GetEscapedCharLiteral(expr->getValue()); ch = (uc > 0x7F ? "b'" : "'") + std::move(ch) + '\''; From 1bc9b5e94401d071df47a1c4209843bf33a7c4bc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:19:52 +0100 Subject: [PATCH 07/10] Translate wide strings --- cpp2rust/converter/converter.cpp | 28 ++++++++++++++++++ cpp2rust/converter/converter.h | 2 ++ .../converter/models/converter_refcount.cpp | 29 +++++++++++++++++++ .../converter/models/converter_refcount.h | 2 ++ tests/unit/out/unsafe/wide_char.rs | 24 +++++++-------- 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 09e31700c..1c2c89071 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2281,7 +2281,35 @@ std::string Converter::GetEscapedStringLiteral(clang::Expr *expr, return out; } +std::string Converter::GetCodeUnitArrayLiteral(const clang::StringLiteral *expr, + uint64_t pad) { + auto elem_type = + ToStringBase(ctx_.getAsArrayType(expr->getType())->getElementType()); + std::string out = "["; + for (unsigned i = 0; i < expr->getLength(); ++i) { + out += std::format("{} as {}, ", expr->getCodeUnit(i), elem_type); + } + for (uint64_t i = 0; i < pad; ++i) { + out += std::format("0 as {}, ", elem_type); + } + return out + ']'; +} + bool Converter::VisitStringLiteral(clang::StringLiteral *expr) { + if (expr->getCharByteWidth() != 1 || + expr->getKind() == clang::StringLiteralKind::UTF8) { + uint64_t pad = 1; + if (!curr_init_type_.empty() && curr_init_type_.back()->isArrayType()) { + if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { + uint64_t arr_size = arr_ty->getSize().getZExtValue(); + pad = arr_size > expr->getLength() ? arr_size - expr->getLength() : 0; + } + } + StrCat(GetCodeUnitArrayLiteral(expr, pad)); + computed_expr_type_ = ComputedExprType::FreshValue; + return false; + } + auto init_type = curr_init_type_.empty() ? clang::QualType() : curr_init_type_.back().getNonReferenceType(); diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 9387ee749..b659bf380 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -349,6 +349,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitCharacterLiteral(clang::CharacterLiteral *expr); std::string GetEscapedCharLiteral(char character) const; + std::string GetCodeUnitArrayLiteral(const clang::StringLiteral *expr, + uint64_t pad); std::string GetEscapedUTF8CharLiteral(clang::Expr *expr) const; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9cd66d614..753b10a18 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -86,6 +86,19 @@ void ConverterRefCount::PendingDeref::set_unchecked(std::string str, bool fresh, type = ComputedExprType::Pending; } +std::string +ConverterRefCount::GetStringLiteralCodeUnit(const clang::Expr *expr) { + const auto *literal = clang::dyn_cast( + expr->IgnoreParens()->IgnoreImplicit()); + if (literal == nullptr || + (literal->getCharByteWidth() == 1 && + literal->getKind() != clang::StringLiteralKind::UTF8)) { + return "u8"; + } + return ToStringBase( + ctx_.getAsArrayType(literal->getType())->getElementType()); +} + std::string ConverterRefCount::GetInnerType(clang::QualType type) { PushConversionKind push(*this, ConversionKind::Unboxed); auto str = ToString(type); @@ -1179,6 +1192,22 @@ bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) { } bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) { + if (expr->getCharByteWidth() != 1 || + expr->getKind() == clang::StringLiteralKind::UTF8) { + uint64_t pad = 1; + if (!curr_init_type_.empty() && curr_init_type_.back()->isArrayType()) { + if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { + uint64_t arr_size = arr_ty->getSize().getZExtValue(); + pad = arr_size > expr->getLength() ? arr_size - expr->getLength() : 0; + } + StrCat(std::format("Box::from({})", GetCodeUnitArrayLiteral(expr, pad))); + } else { + StrCat(std::format("&{}", GetCodeUnitArrayLiteral(expr, pad))); + } + computed_expr_type_ = ComputedExprType::FreshValue; + return false; + } + if (!curr_init_type_.empty() && curr_init_type_.back()->isArrayType()) { uint64_t pad = 1; if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 41fa971a0..f63ef841a 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -267,6 +267,8 @@ class ConverterRefCount final : public Converter { std::string GetInnerType(clang::QualType type); + std::string GetStringLiteralCodeUnit(const clang::Expr *expr); + std::string ConvertFreshLValue(clang::Expr *expr); std::string ConvertObject(clang::Expr *expr); std::string ConvertFreshObject(clang::Expr *expr) override; diff --git a/tests/unit/out/unsafe/wide_char.rs b/tests/unit/out/unsafe/wide_char.rs index 228a43878..bdaa27b4c 100644 --- a/tests/unit/out/unsafe/wide_char.rs +++ b/tests/unit/out/unsafe/wide_char.rs @@ -44,10 +44,10 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut c: *const libc::c_char = c"A".as_ptr(); - let mut w: *const i32 = (&[65 as i32, 258 as i32, 0 as i32]).as_ptr(); - let mut b: *const u8 = (&[196 as u8, 130 as u8, 0 as u8]).as_ptr(); - let mut s: *const u16 = (&[65 as u16, 258 as u16, 0 as u16]).as_ptr(); - let mut l: *const u32 = (&[65 as u32, 258 as u32, 0 as u32]).as_ptr(); + let mut w: *const i32 = [65 as i32, 258 as i32, 0 as i32].as_ptr(); + let mut b: *const u8 = [196 as u8, 130 as u8, 0 as u8].as_ptr(); + let mut s: *const u16 = [65 as u16, 258 as u16, 0 as u16].as_ptr(); + let mut l: *const u32 = [65 as u32, 258 as u32, 0 as u32].as_ptr(); assert!((((*c.offset((0) as isize)) as i32) == (('A' as libc::c_char) as i32))); assert!( (((*b.offset((0) as isize)) as i32) == (196)) @@ -65,29 +65,29 @@ unsafe fn main_0() -> i32 { == (('A' as libc::c_char) as i32)) ); assert!( - ((*(unsafe { get_1((&[258 as i32, 0 as i32,]).as_ptr(),) }).offset((0) as isize)) == (258)) + ((*(unsafe { get_1([258 as i32, 0 as i32,].as_ptr(),) }).offset((0) as isize)) == (258)) ); assert!( - (((*(unsafe { get_2((&[196 as u8, 130 as u8, 0 as u8,]).as_ptr(),) }).offset((0) as isize)) + (((*(unsafe { get_2([196 as u8, 130 as u8, 0 as u8,].as_ptr(),) }).offset((0) as isize)) as i32) == (196)) ); assert!( - (((*(unsafe { get_3((&[258 as u16, 0 as u16,]).as_ptr(),) }).offset((0) as isize)) as i32) + (((*(unsafe { get_3([258 as u16, 0 as u16,].as_ptr(),) }).offset((0) as isize)) as i32) == (258)) ); assert!( - ((*(unsafe { get_4((&[258 as u32, 0 as u32,]).as_ptr(),) }).offset((0) as isize)) + ((*(unsafe { get_4([258 as u32, 0 as u32,].as_ptr(),) }).offset((0) as isize)) == (258_u32)) ); assert!( (((unsafe { second_5(&std::mem::transmute(*b"AB\0"),) }) as i32) == (('B' as libc::c_char) as i32)) ); - assert!(((unsafe { second_6(&(&[65 as i32, 258 as i32, 0 as i32,]),) }) == (258))); - assert!((((unsafe { second_7(&(&[196 as u8, 130 as u8, 0 as u8,]),) }) as i32) == (130))); - assert!((((unsafe { second_8(&(&[65 as u16, 258 as u16, 0 as u16,]),) }) as i32) == (258))); - assert!(((unsafe { second_9(&(&[65 as u32, 258 as u32, 0 as u32,]),) }) == (258_u32))); + assert!(((unsafe { second_6(&[65 as i32, 258 as i32, 0 as i32,],) }) == (258))); + assert!((((unsafe { second_7(&[196 as u8, 130 as u8, 0 as u8,],) }) as i32) == (130))); + assert!((((unsafe { second_8(&[65 as u16, 258 as u16, 0 as u16,],) }) as i32) == (258))); + assert!(((unsafe { second_9(&[65 as u32, 258 as u32, 0 as u32,],) }) == (258_u32))); let nw: usize = ((::std::mem::size_of::<[i32; 4]>() as usize) .wrapping_div((::std::mem::size_of::() as usize)) as usize) .wrapping_sub(1_usize); From 94f7ef703e820ea31c62aa31c9d3843df4a96d66 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:25:22 +0100 Subject: [PATCH 08/10] Add wide chars in test --- tests/unit/out/refcount/wide_char.rs | 61 ++++++++++++++++++++++++++++ tests/unit/out/unsafe/wide_char.rs | 44 ++++++++++++++++++++ tests/unit/wide_char.cpp | 21 ++++++++++ 3 files changed, 126 insertions(+) diff --git a/tests/unit/out/refcount/wide_char.rs b/tests/unit/out/refcount/wide_char.rs index e8b91ea23..9c4682920 100644 --- a/tests/unit/out/refcount/wide_char.rs +++ b/tests/unit/out/refcount/wide_char.rs @@ -192,6 +192,67 @@ fn main_0() -> i32 { ); let ew: Value> = Rc::new(RefCell::new(Box::from([0 as i32, 0 as i32]))); assert!(((*ew.borrow())[(0) as usize] == 0) && ((*ew.borrow())[(1) as usize] == 0)); + let wc: Value = Rc::new(RefCell::new((258 as i32))); + let bc: Value = Rc::new(RefCell::new((65 as u8))); + let sc: Value = Rc::new(RefCell::new((258 as u16))); + let lc: Value = Rc::new(RefCell::new((258 as u32))); + assert!( + ((((*wc.borrow()) == 258) && (((*bc.borrow()) as i32) == 65)) + && (((*sc.borrow()) as i32) == 258)) + && ((*lc.borrow()) == 258_u32) + ); + assert!( + (((::std::mem::size_of::() == ::std::mem::size_of::()) + && (::std::mem::size_of::() == 1_usize)) + && (::std::mem::size_of::() == 2_usize)) + && (::std::mem::size_of::() == 4_usize) + ); + assert!( + ((((*w.borrow()).offset((1) as isize).read()) == (258 as i32)) + && ((((*s.borrow()).offset((1) as isize).read()) as i32) == ((258 as u16) as i32))) + && (((*l.borrow()).offset((1) as isize).read()) == (258 as u32)) + ); + assert!( + ((((*b.borrow()).offset((0) as isize).read()) as i32) == ((196 as u8) as i32)) + && ((((*b.borrow()).offset((1) as isize).read()) as i32) == ((130 as u8) as i32)) + ); + assert!( + (({ + second_6(Ptr::>::from_string_literal_array(&[ + 65 as i32, 258 as i32, 0 as i32, + ])) + }) == (258 as i32)) + && ((({ + second_8(Ptr::>::from_string_literal_array(&[ + 65 as u16, 258 as u16, 0 as u16, + ])) + }) as i32) + == ((258 as u16) as i32)) + ); + assert!( + ((({ get_4(Ptr::::from_string_literal(&[258 as u32, 0 as u32,]),) }) + .offset((0) as isize) + .read()) + == (258 as u32)) + && ((({ get_4(Ptr::::from_string_literal(&[258 as u32, 0 as u32,]),) }) + .offset((1) as isize) + .read()) + == (0 as u32)) + ); + assert!((((10 as i32) == 10) && (((9 as u16) as i32) == 9)) && ((92 as u32) == 92_u32)); + assert!((((97 as i32) + 1) == (98 as i32))); + assert!(((122 as u32).wrapping_sub((97 as u32)) == 25_u32)); + let wa: Value> = Rc::new(RefCell::new(Box::new([ + (65 as i32), + (258 as i32), + (0 as i32), + ]))); + assert!( + (((*wa.borrow())[(0) as usize] == 65) && ((*wa.borrow())[(1) as usize] == 258)) + && ((*wa.borrow())[(2) as usize] == 0) + ); + (*wa.borrow_mut())[(0) as usize] = (66 as i32); + assert!(((*wa.borrow())[(0) as usize] == (('B' as u8) as i32))); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/wide_char.rs b/tests/unit/out/unsafe/wide_char.rs index bdaa27b4c..d79416f7c 100644 --- a/tests/unit/out/unsafe/wide_char.rs +++ b/tests/unit/out/unsafe/wide_char.rs @@ -116,6 +116,50 @@ unsafe fn main_0() -> i32 { ); let ew: [i32; 2] = [0 as i32, 0 as i32]; assert!(((ew[(0) as usize]) == (0)) && ((ew[(1) as usize]) == (0))); + let mut wc: i32 = (258 as i32); + let mut bc: u8 = (65 as u8); + let mut sc: u16 = (258 as u16); + let mut lc: u32 = (258 as u32); + assert!( + ((((wc) == (258)) && ((bc as i32) == (65))) && ((sc as i32) == (258))) + && ((lc) == (258_u32)) + ); + assert!( + ((((::std::mem::size_of::()) == (::std::mem::size_of::())) + && ((::std::mem::size_of::()) == (1_usize))) + && ((::std::mem::size_of::()) == (2_usize))) + && ((::std::mem::size_of::()) == (4_usize)) + ); + assert!( + (((*w.offset((1) as isize)) == (258 as i32)) + && (((*s.offset((1) as isize)) as i32) == ((258 as u16) as i32))) + && ((*l.offset((1) as isize)) == (258 as u32)) + ); + assert!( + (((*b.offset((0) as isize)) as i32) == ((196 as u8) as i32)) + && (((*b.offset((1) as isize)) as i32) == ((130 as u8) as i32)) + ); + assert!( + ((unsafe { second_6(&[65 as i32, 258 as i32, 0 as i32,],) }) == (258 as i32)) + && (((unsafe { second_8(&[65 as u16, 258 as u16, 0 as u16,],) }) as i32) + == ((258 as u16) as i32)) + ); + assert!( + ((*(unsafe { get_4([258 as u32, 0 as u32,].as_ptr(),) }).offset((0) as isize)) + == (258 as u32)) + && ((*(unsafe { get_4([258 as u32, 0 as u32,].as_ptr(),) }).offset((1) as isize)) + == (0 as u32)) + ); + assert!((((10 as i32) == (10)) && (((9 as u16) as i32) == (9))) && ((92 as u32) == (92_u32))); + assert!((((97 as i32) + (1)) == (98 as i32))); + assert!((((122 as u32).wrapping_sub((97 as u32))) == (25_u32))); + let mut wa: [i32; 3] = [(65 as i32), (258 as i32), (0 as i32)]; + assert!( + (((wa[(0) as usize]) == (65)) && ((wa[(1) as usize]) == (258))) + && ((wa[(2) as usize]) == (0)) + ); + wa[(0) as usize] = (66 as i32); + assert!(((wa[(0) as usize]) == (('B' as libc::c_char) as i32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/wide_char.cpp b/tests/unit/wide_char.cpp index 176dddb3a..c7822151a 100644 --- a/tests/unit/wide_char.cpp +++ b/tests/unit/wide_char.cpp @@ -54,5 +54,26 @@ int main() { const wchar_t ew[2] = L""; assert(ew[0] == 0 && ew[1] == 0); + + wchar_t wc = L'Ă'; + char8_t bc = u8'A'; + char16_t sc = u'Ă'; + char32_t lc = U'Ă'; + assert(wc == 0x102 && bc == 0x41 && sc == 0x102 && lc == 0x102); + assert(sizeof(L'a') == sizeof(wchar_t) && sizeof(u8'a') == 1 && + sizeof(u'a') == 2 && sizeof(U'a') == 4); + + assert(w[1] == L'Ă' && s[1] == u'Ă' && l[1] == U'Ă'); + assert(b[0] == u8'\xC4' && b[1] == u8'\x82'); + assert(second(L"AĂ") == L'Ă' && second(u"AĂ") == u'Ă'); + assert(get(U"Ă")[0] == U'Ă' && get(U"Ă")[1] == U'\0'); + + assert(L'\n' == 10 && u'\t' == 9 && U'\\' == 92); + assert(L'a' + 1 == L'b'); + assert(U'z' - U'a' == 25); + wchar_t wa[3] = {L'A', L'Ă', L'\0'}; + assert(wa[0] == 0x41 && wa[1] == 0x102 && wa[2] == 0); + wa[0] = L'B'; + assert(wa[0] == 'B'); return 0; } From c8a00f1d071747f61793bc9e36d31b061c8c950b Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 19 Sep 2026 20:33:11 +0100 Subject: [PATCH 09/10] format --- cpp2rust/converter/converter.cpp | 35 +++++++------- cpp2rust/converter/converter.h | 4 +- cpp2rust/converter/converter_lib.cpp | 5 ++ cpp2rust/converter/converter_lib.h | 2 + .../converter/models/converter_refcount.cpp | 46 +++++++------------ .../converter/models/converter_refcount.h | 2 - 6 files changed, 44 insertions(+), 50 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 1c2c89071..9c51eab99 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2281,31 +2281,32 @@ std::string Converter::GetEscapedStringLiteral(clang::Expr *expr, return out; } -std::string Converter::GetCodeUnitArrayLiteral(const clang::StringLiteral *expr, - uint64_t pad) { +bool Converter::IsArrayInitContext() const { + return !curr_init_type_.empty() && curr_init_type_.back()->isArrayType(); +} + +std::string +Converter::GetCodeUnitArrayLiteral(const clang::StringLiteral *expr) { auto elem_type = ToStringBase(ctx_.getAsArrayType(expr->getType())->getElementType()); - std::string out = "["; - for (unsigned i = 0; i < expr->getLength(); ++i) { - out += std::format("{} as {}, ", expr->getCodeUnit(i), elem_type); + uint64_t len = expr->getLength(); + uint64_t total = len + 1; + if (IsArrayInitContext()) { + if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { + total = std::max(arr_ty->getSize().getZExtValue(), len); + } } - for (uint64_t i = 0; i < pad; ++i) { - out += std::format("0 as {}, ", elem_type); + std::string out = "["; + for (uint64_t i = 0; i < total; ++i) { + out += std::format("{} as {}, ", i < len ? expr->getCodeUnit(i) : 0, + elem_type); } return out + ']'; } bool Converter::VisitStringLiteral(clang::StringLiteral *expr) { - if (expr->getCharByteWidth() != 1 || - expr->getKind() == clang::StringLiteralKind::UTF8) { - uint64_t pad = 1; - if (!curr_init_type_.empty() && curr_init_type_.back()->isArrayType()) { - if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { - uint64_t arr_size = arr_ty->getSize().getZExtValue(); - pad = arr_size > expr->getLength() ? arr_size - expr->getLength() : 0; - } - } - StrCat(GetCodeUnitArrayLiteral(expr, pad)); + if (IsCodeUnitStringLiteral(expr)) { + StrCat(GetCodeUnitArrayLiteral(expr)); computed_expr_type_ = ComputedExprType::FreshValue; return false; } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index b659bf380..35c3f274b 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -349,8 +349,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitCharacterLiteral(clang::CharacterLiteral *expr); std::string GetEscapedCharLiteral(char character) const; - std::string GetCodeUnitArrayLiteral(const clang::StringLiteral *expr, - uint64_t pad); + std::string GetCodeUnitArrayLiteral(const clang::StringLiteral *expr); + bool IsArrayInitContext() const; std::string GetEscapedUTF8CharLiteral(clang::Expr *expr) const; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 0dbb2fd11..d327061a0 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -149,6 +149,11 @@ bool IsStringLiteralExpr(const clang::Expr *expr) { clang::isa(stripped); } +bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr) { + return expr->getCharByteWidth() != 1 || + expr->getKind() == clang::StringLiteralKind::UTF8; +} + bool IsUserDefinedDecl(const clang::Decl *decl) { const auto &ctx = decl->getASTContext(); const auto &src_mgr = ctx.getSourceManager(); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 709940a70..47e658966 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -46,6 +46,8 @@ bool IsUnionArrayMember(const clang::Expr *base); bool IsStringLiteralExpr(const clang::Expr *expr); +bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr); + bool IsUserDefinedDecl(const clang::Decl *decl); bool RefersToUserDefinedDecl(const clang::Expr *expr); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 753b10a18..fc4569325 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -86,19 +86,6 @@ void ConverterRefCount::PendingDeref::set_unchecked(std::string str, bool fresh, type = ComputedExprType::Pending; } -std::string -ConverterRefCount::GetStringLiteralCodeUnit(const clang::Expr *expr) { - const auto *literal = clang::dyn_cast( - expr->IgnoreParens()->IgnoreImplicit()); - if (literal == nullptr || - (literal->getCharByteWidth() == 1 && - literal->getKind() != clang::StringLiteralKind::UTF8)) { - return "u8"; - } - return ToStringBase( - ctx_.getAsArrayType(literal->getType())->getElementType()); -} - std::string ConverterRefCount::GetInnerType(clang::QualType type) { PushConversionKind push(*this, ConversionKind::Unboxed); auto str = ToString(type); @@ -1192,23 +1179,15 @@ bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) { } bool ConverterRefCount::VisitStringLiteral(clang::StringLiteral *expr) { - if (expr->getCharByteWidth() != 1 || - expr->getKind() == clang::StringLiteralKind::UTF8) { - uint64_t pad = 1; - if (!curr_init_type_.empty() && curr_init_type_.back()->isArrayType()) { - if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { - uint64_t arr_size = arr_ty->getSize().getZExtValue(); - pad = arr_size > expr->getLength() ? arr_size - expr->getLength() : 0; - } - StrCat(std::format("Box::from({})", GetCodeUnitArrayLiteral(expr, pad))); - } else { - StrCat(std::format("&{}", GetCodeUnitArrayLiteral(expr, pad))); - } + if (IsCodeUnitStringLiteral(expr)) { + auto arr = GetCodeUnitArrayLiteral(expr); + StrCat(IsArrayInitContext() ? std::format("Box::from({})", arr) + : '&' + arr); computed_expr_type_ = ComputedExprType::FreshValue; return false; } - if (!curr_init_type_.empty() && curr_init_type_.back()->isArrayType()) { + if (IsArrayInitContext()) { uint64_t pad = 1; if (auto *arr_ty = ctx_.getAsConstantArrayType(curr_init_type_.back())) { uint64_t arr_size = arr_ty->getSize().getZExtValue(); @@ -1301,7 +1280,10 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { return false; } if (IsStringLiteralExpr(sub_expr)) { - auto code_unit = GetStringLiteralCodeUnit(sub_expr); + auto code_unit = ToStringBase( + ctx_.getAsArrayType( + sub_expr->IgnoreParens()->IgnoreImplicit()->getType()) + ->getElementType()); StrCat(std::format("Ptr::<{}>::from_string_literal({})", code_unit, ToString(sub_expr->IgnoreParens()))); computed_expr_type_ = ComputedExprType::FreshPointer; @@ -2174,7 +2156,10 @@ std::string ConverterRefCount::ConvertVarInitValue(clang::QualType qual_type, } if (qual_type.getNonReferenceType()->isArrayType()) { if (IsStringLiteralExpr(expr)) { - auto code_unit = GetStringLiteralCodeUnit(expr); + auto code_unit = ToStringBase( + ctx_.getAsArrayType( + expr->IgnoreParens()->IgnoreImplicit()->getType()) + ->getElementType()); return std::format("Ptr::>::from_string_literal_array({})", code_unit, ToString(expr->IgnoreParens()->IgnoreImplicit())); @@ -2446,7 +2431,10 @@ void ConverterRefCount::ConvertArraySubscript(clang::Expr *base, { PushParen paren(*this, is_inner_boxed); if (IsStringLiteralExpr(base)) { - auto code_unit = GetStringLiteralCodeUnit(base); + auto code_unit = ToStringBase( + ctx_.getAsArrayType( + base->IgnoreParens()->IgnoreImplicit()->getType()) + ->getElementType()); StrCat(std::format("Ptr::<{}>::from_string_literal({}).offset({})", code_unit, ToString(base->IgnoreParens()->IgnoreImplicit()), diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index f63ef841a..41fa971a0 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -267,8 +267,6 @@ class ConverterRefCount final : public Converter { std::string GetInnerType(clang::QualType type); - std::string GetStringLiteralCodeUnit(const clang::Expr *expr); - std::string ConvertFreshLValue(clang::Expr *expr); std::string ConvertObject(clang::Expr *expr); std::string ConvertFreshObject(clang::Expr *expr) override; From 5faab22ccce883d4809051236666d2becd903212 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 20 Sep 2026 11:03:12 +0100 Subject: [PATCH 10/10] fix --- cpp2rust/converter/converter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 9c51eab99..ef7b453db 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2296,12 +2296,13 @@ Converter::GetCodeUnitArrayLiteral(const clang::StringLiteral *expr) { total = std::max(arr_ty->getSize().getZExtValue(), len); } } - std::string out = "["; + std::string out = '['; for (uint64_t i = 0; i < total; ++i) { out += std::format("{} as {}, ", i < len ? expr->getCodeUnit(i) : 0, elem_type); } - return out + ']'; + out += ']'; + return out; } bool Converter::VisitStringLiteral(clang::StringLiteral *expr) {