Skip to content

Commit aa80ed6

Browse files
committed
Merge branch 'master' into ast-matcher
2 parents 6b9ccc3 + 4850ba3 commit aa80ed6

3 files changed

Lines changed: 34 additions & 33 deletions

File tree

‎tests/unit/lambda_to_fn_ptr.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ADDITIONAL_COMPILE_FLAGS: -std=c++23
2-
// no-compile
32
#include <assert.h>
43
#include <stdarg.h>
54

‎tests/unit/out/refcount/lambda_to_fn_ptr.rs‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,26 @@ fn main_0() -> i32 {
7171
assert!((({ call_nttp_1(5,) }) == 4));
7272
assert!((({ call_nttp_2(5,) }) == 50));
7373
assert!((({ call_nttp_3(5,) }) == 105));
74-
let sum: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(FnPtr::<fn(i32) -> i32>::new(
75-
|n: i32| -> i32 {
76-
{
77-
let __args: Value<Box<[VaArg]>> = Rc::new(RefCell::new(__args.into()));
78-
let n: Value<i32> = Rc::new(RefCell::new(n));
79-
let ap: Value<Ptr<VaArg>> = Rc::new(RefCell::new(Ptr::<VaArg>::default()));
80-
(*ap.borrow_mut()) = __args.as_pointer();
81-
let s: Value<i32> = Rc::new(RefCell::new(0));
82-
let mut i: i32 = 0;
83-
'loop_: while (i < (*n.borrow())) {
84-
(*s.borrow_mut()) += (*ap.borrow_mut()).arg::<i32>();
85-
i.postfix_inc();
74+
let sum: Value<FnPtr<fn(i32, Box<[VaArg]>) -> i32>> =
75+
Rc::new(RefCell::new(FnPtr::<fn(i32, Box<[VaArg]>) -> i32>::new(
76+
|n: i32, __args: Box<[VaArg]>| -> i32 {
77+
{
78+
let __args: Value<Box<[VaArg]>> = Rc::new(RefCell::new(__args.into()));
79+
let n: Value<i32> = Rc::new(RefCell::new(n));
80+
let ap: Value<Ptr<VaArg>> = Rc::new(RefCell::new(Ptr::<VaArg>::default()));
81+
(*ap.borrow_mut()) = __args.as_pointer();
82+
let s: Value<i32> = Rc::new(RefCell::new(0));
83+
let mut i: i32 = 0;
84+
'loop_: while (i < (*n.borrow())) {
85+
(*s.borrow_mut()) += (*ap.borrow_mut()).arg::<i32>();
86+
i.postfix_inc();
87+
}
88+
return (*s.borrow());
8689
}
87-
return (*s.borrow());
88-
}
89-
},
90-
)));
91-
assert!((({ (*sum.borrow()).call(2, &[(5).into(), (5).into(),]) }) == 10));
92-
assert!((({ (*sum.borrow()).call(3, &[(1).into(), (2).into(), (3).into(),]) }) == 6));
90+
},
91+
)));
92+
assert!((({ (*sum.borrow()).call(2, Box::new([(5).into(), (5).into(),])) }) == 10));
93+
assert!((({ (*sum.borrow()).call(3, Box::new([(1).into(), (2).into(), (3).into(),])) }) == 6));
9394
return 0;
9495
}
9596
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/lambda_to_fn_ptr.rs‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,22 @@ unsafe fn main_0() -> i32 {
8686
assert!(((unsafe { call_nttp_1(5,) }) == (4)));
8787
assert!(((unsafe { call_nttp_2(5,) }) == (50)));
8888
assert!(((unsafe { call_nttp_3(5,) }) == (105)));
89-
let mut sum: FnPtr<fn(i32) -> i32> = FnPtr::<fn(i32) -> i32>::new(|mut n: i32| -> i32 {
90-
unsafe {
91-
let mut ap: *const VaArg = ::std::ptr::null();
92-
ap = __args.as_ptr();
93-
let mut s: i32 = 0;
94-
let mut i: i32 = 0;
95-
'loop_: while ((i) < (n)) {
96-
s += ap.arg::<i32>();
97-
i.postfix_inc();
89+
let mut sum: FnPtr<fn(i32, Box<[VaArg]>) -> i32> =
90+
FnPtr::<fn(i32, Box<[VaArg]>) -> i32>::new(|mut n: i32, __args: Box<[VaArg]>| -> i32 {
91+
unsafe {
92+
let mut ap: *const VaArg = ::std::ptr::null();
93+
ap = __args.as_ptr();
94+
let mut s: i32 = 0;
95+
let mut i: i32 = 0;
96+
'loop_: while ((i) < (n)) {
97+
s += ap.arg::<i32>();
98+
i.postfix_inc();
99+
}
100+
return s;
98101
}
99-
return s;
100-
}
101-
});
102-
assert!(((unsafe { sum.call(2, &[(5).into(), (5).into(),]) }) == (10)));
103-
assert!(((unsafe { sum.call(3, &[(1).into(), (2).into(), (3).into(),]) }) == (6)));
102+
});
103+
assert!(((unsafe { sum.call(2, Box::new([(5).into(), (5).into(),])) }) == (10)));
104+
assert!(((unsafe { sum.call(3, Box::new([(1).into(), (2).into(), (3).into(),])) }) == (6)));
104105
return 0;
105106
}
106107
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)