forked from JetBrains/kotlin-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate StablePtr to KRefSharedHolder (JetBrains#3966)
This PR also fixes tests from JetBrains#3969
- Loading branch information
Showing
7 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
backend.native/tests/runtime/memory/stable_ref_cross_thread_check.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license | ||
* that can be found in the LICENSE file. | ||
*/ | ||
|
||
package runtime.memory.stable_ref_cross_thread_check | ||
|
||
import kotlin.test.* | ||
|
||
import kotlin.native.concurrent.* | ||
import kotlinx.cinterop.* | ||
|
||
@Test | ||
fun runTest1() { | ||
val worker = Worker.start() | ||
|
||
val future = worker.execute(TransferMode.SAFE, { }) { | ||
StableRef.create(Any()) | ||
} | ||
val ref = future.result | ||
assertFailsWith<IncorrectDereferenceException> { | ||
val value = ref.get() | ||
println(value.toString()) | ||
} | ||
|
||
worker.requestTermination().result | ||
} | ||
|
||
@Test | ||
fun runTest2() { | ||
val worker = Worker.start() | ||
|
||
val mainThreadRef = StableRef.create(Any()) | ||
// Simulate this going through interop as raw C pointer. | ||
val pointerValue: Long = mainThreadRef.asCPointer().toLong() | ||
val future = worker.execute(TransferMode.SAFE, { pointerValue }) { | ||
val pointer: COpaquePointer = it.toCPointer()!! | ||
assertFailsWith<IncorrectDereferenceException> { | ||
// Even attempting to convert a pointer to StableRef should fail. | ||
val otherThreadRef: StableRef<Any> = pointer.asStableRef() | ||
println(otherThreadRef.toString()) | ||
} | ||
Unit | ||
} | ||
future.result | ||
|
||
worker.requestTermination().result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters