Skip to content

Commit f506ece

Browse files
committed
add confined arena constructor with current thread
1 parent e6acb16 commit f506ece

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Samples/JExtractJNISampleApp/src/main/java/com/example/swift/HelloJava2SwiftJNI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void examples() {
4141

4242
MySwiftClass.method();
4343

44-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
44+
try (var arena = new ConfinedSwiftMemorySession()) {
4545
MySwiftClass myClass = MySwiftClass.init(10, 5, arena);
4646
MySwiftClass myClass2 = MySwiftClass.init(arena);
4747

Samples/JExtractJNISampleApp/src/test/java/com/example/swift/MySwiftClassTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@
2222
public class MySwiftClassTest {
2323
@Test
2424
void init_noParameters() {
25-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
25+
try (var arena = new ConfinedSwiftMemorySession()) {
2626
MySwiftClass c = MySwiftClass.init(arena);
2727
assertNotNull(c);
2828
}
2929
}
3030

3131
@Test
3232
void init_withParameters() {
33-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
33+
try (var arena = new ConfinedSwiftMemorySession()) {
3434
MySwiftClass c = MySwiftClass.init(1337, 42, arena);
3535
assertNotNull(c);
3636
}
3737
}
3838

3939
@Test
4040
void sum() {
41-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
41+
try (var arena = new ConfinedSwiftMemorySession()) {
4242
MySwiftClass c = MySwiftClass.init(20, 10, arena);
4343
assertEquals(30, c.sum());
4444
}
4545
}
4646

4747
@Test
4848
void xMultiplied() {
49-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
49+
try (var arena = new ConfinedSwiftMemorySession()) {
5050
MySwiftClass c = MySwiftClass.init(20, 10, arena);
5151
assertEquals(200, c.xMultiplied(10));
5252
}
5353
}
5454

5555
@Test
5656
void throwingFunction() {
57-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
57+
try (var arena = new ConfinedSwiftMemorySession()) {
5858
MySwiftClass c = MySwiftClass.init(20, 10, arena);
5959
Exception exception = assertThrows(Exception.class, () -> c.throwingFunction());
6060

@@ -64,15 +64,15 @@ void throwingFunction() {
6464

6565
@Test
6666
void constant() {
67-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
67+
try (var arena = new ConfinedSwiftMemorySession()) {
6868
MySwiftClass c = MySwiftClass.init(20, 10, arena);
6969
assertEquals(100, c.getConstant());
7070
}
7171
}
7272

7373
@Test
7474
void mutable() {
75-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
75+
try (var arena = new ConfinedSwiftMemorySession()) {
7676
MySwiftClass c = MySwiftClass.init(20, 10, arena);
7777
assertEquals(0, c.getMutable());
7878
c.setMutable(42);
@@ -82,15 +82,15 @@ void mutable() {
8282

8383
@Test
8484
void product() {
85-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
85+
try (var arena = new ConfinedSwiftMemorySession()) {
8686
MySwiftClass c = MySwiftClass.init(20, 10, arena);
8787
assertEquals(200, c.getProduct());
8888
}
8989
}
9090

9191
@Test
9292
void throwingVariable() {
93-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
93+
try (var arena = new ConfinedSwiftMemorySession()) {
9494
MySwiftClass c = MySwiftClass.init(20, 10, arena);
9595

9696
Exception exception = assertThrows(Exception.class, () -> c.getThrowingVariable());
@@ -101,7 +101,7 @@ void throwingVariable() {
101101

102102
@Test
103103
void mutableDividedByTwo() {
104-
try (var arena = new ConfinedSwiftMemorySession(Thread.currentThread())) {
104+
try (var arena = new ConfinedSwiftMemorySession()) {
105105
MySwiftClass c = MySwiftClass.init(20, 10, arena);
106106
assertEquals(0, c.getMutableDividedByTwo());
107107
c.setMutable(20);

SwiftKitCore/src/main/java/org/swift/swiftkit/core/ConfinedSwiftMemorySession.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class ConfinedSwiftMemorySession implements ClosableSwiftArena {
2828

2929
final ConfinedResourceList resources;
3030

31+
public ConfinedSwiftMemorySession() {
32+
this(Thread.currentThread());
33+
}
34+
3135
public ConfinedSwiftMemorySession(Thread owner) {
3236
this.owner = owner;
3337
this.state = new AtomicInteger(ACTIVE);

0 commit comments

Comments
 (0)