|
15 | 15 | package org.swift.swiftkit;
|
16 | 16 |
|
17 | 17 | import com.example.swift.MySwiftClass;
|
| 18 | +import com.example.swift.MySwiftStruct; |
18 | 19 | import org.junit.jupiter.api.BeforeAll;
|
19 | 20 | import org.junit.jupiter.api.Test;
|
20 | 21 | import org.junit.jupiter.api.condition.DisabledIf;
|
@@ -47,8 +48,44 @@ public void arena_releaseClassOnClose_class_ok() {
|
47 | 48 | release(obj.$memorySegment());
|
48 | 49 | assertEquals(1, retainCount(obj.$memorySegment()));
|
49 | 50 | }
|
| 51 | + } |
| 52 | + |
| 53 | + // FIXME: The destroy witness table call hangs on x86_64 platforms during the destroy witness table call |
| 54 | + // See: https://github.com/swiftlang/swift-java/issues/97 |
| 55 | + @Test |
| 56 | + public void arena_markAsDestroyed_preventUseAfterFree_class() { |
| 57 | + MySwiftClass unsafelyEscapedOutsideArenaScope = null; |
| 58 | + |
| 59 | + try (var arena = SwiftArena.ofConfined()) { |
| 60 | + var obj = new MySwiftClass(arena,1, 2); |
| 61 | + unsafelyEscapedOutsideArenaScope = obj; |
| 62 | + } |
| 63 | + |
| 64 | + try { |
| 65 | + unsafelyEscapedOutsideArenaScope.echoIntMethod(1); |
| 66 | + fail("Expected exception to be thrown! Object was suposed to be dead."); |
| 67 | + } catch (IllegalStateException ex) { |
| 68 | + return; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + // FIXME: The destroy witness table call hangs on x86_64 platforms during the destroy witness table call |
| 73 | + // See: https://github.com/swiftlang/swift-java/issues/97 |
| 74 | + @Test |
| 75 | + public void arena_markAsDestroyed_preventUseAfterFree_struct() { |
| 76 | + MySwiftStruct unsafelyEscapedOutsideArenaScope = null; |
50 | 77 |
|
51 |
| - // TODO: should we zero out the $memorySegment perhaps? |
| 78 | + try (var arena = SwiftArena.ofConfined()) { |
| 79 | + var s = new MySwiftStruct(arena,1, 2); |
| 80 | + unsafelyEscapedOutsideArenaScope = s; |
| 81 | + } |
| 82 | + |
| 83 | + try { |
| 84 | + unsafelyEscapedOutsideArenaScope.echoIntMethod(1); |
| 85 | + fail("Expected exception to be thrown! Object was suposed to be dead."); |
| 86 | + } catch (IllegalStateException ex) { |
| 87 | + return; |
| 88 | + } |
52 | 89 | }
|
53 | 90 |
|
54 | 91 | @Test
|
|
0 commit comments