Skip to content

Commit be3ec76

Browse files
committed
Add test for issue #28008 and update expected outputs
- Add c_addrOf_unmanaged_class.chpl test that verifies the fix works - Update c_ptr_class_type.good to reflect that c_addrOf(unmanaged) now equals c_ptrTo(unmanaged), changing line from false to true
1 parent 2e13188 commit be3ec76

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

test-issue-28008.chpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use CTypes;
2+
3+
class MyClass {
4+
var x: int = 21;
5+
}
6+
7+
proc main() {
8+
9+
var myOwned = new owned MyClass();
10+
var myBorrow = myOwned.borrow();
11+
var myUnmanaged = new unmanaged MyClass();
12+
defer { delete myUnmanaged; }
13+
14+
var addr1 = c_addrOf(myOwned);
15+
var addr2 = c_addrOf(myBorrow);
16+
var addr3 = c_addrOf(myUnmanaged);
17+
18+
19+
writeln(addr1.deref(), addr2.deref(), addr3.deref(), sep =" | "); // addr3.deref() fails
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test for issue #28008
2+
// c_addrOf on unmanaged class should work with wide pointers
3+
4+
use CTypes;
5+
6+
class MyClass {
7+
var x: int = 21;
8+
}
9+
10+
proc main() {
11+
12+
var myOwned = new owned MyClass();
13+
var myBorrow = myOwned.borrow();
14+
var myUnmanaged = new unmanaged MyClass();
15+
defer { delete myUnmanaged; }
16+
17+
var addr1 = c_addrOf(myOwned);
18+
var addr2 = c_addrOf(myBorrow);
19+
var addr3 = c_addrOf(myUnmanaged);
20+
21+
writeln(addr1.deref(), " | ", addr2.deref(), " | ", addr3.deref());
22+
23+
// Verify that c_addrOf on unmanaged class returns the same as c_ptrTo
24+
writeln(c_addrOf(myUnmanaged):string == c_ptrTo(myUnmanaged):string);
25+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{x = 21} | {x = 21} | {x = 21}
2+
true

test/types/cptr/c_ptr_class_type.good

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ true
1818
true
1919
true
2020

21-
false
21+
true
2222
5
2323
c_ptr(void)
2424
5
25+

0 commit comments

Comments
 (0)