-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Native: improve thread state switches for NSSet/NSDictionary adapters
^KT-54119 (cherry picked from commit 39c73e2)
- Loading branch information
1 parent
1abfeb9
commit 1244679
Showing
6 changed files
with
161 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package kt54119 | ||
|
||
class KT54119KotlinKey | ||
|
||
private typealias Foo = KT54119KotlinKey | ||
|
||
fun callContains(set: Set<*>) = set.contains(Foo()) | ||
|
||
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") | ||
fun callGetElement(set: Set<*>) = (set as kotlin.native.internal.KonanSet<Any?>).getElement(Foo()) | ||
|
||
fun callContainsKey(map: Map<*, *>) = map.containsKey(Foo()) | ||
|
||
fun callContainsValue(map: Map<*, *>) = map.containsValue(Foo()) | ||
|
||
fun callGet(map: Map<*, *>) = map.get(Foo()) | ||
|
||
fun callGetOrThrowConcurrentModification(map: Map<*, *>) = map.hashCode() // calls getOrThrowConcurrentModification under the hood. | ||
fun callContainsEntry(map: Map<*, *>) = map.entries.contains(map.entries.first()) |
51 changes: 51 additions & 0 deletions
51
kotlin-native/backend.native/tests/objcexport/kt54119.swift
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,51 @@ | ||
/* | ||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
import Foundation | ||
import Kt | ||
|
||
// See https://youtrack.jetbrains.com/issue/KT-54119/Native-runtime-assertion-failed-due-to-missing-thread-state-switch | ||
|
||
private func testSetContains() throws { | ||
try assertFalse(Kt54119Kt.callContains(set: ["111"])) | ||
} | ||
|
||
private func testSetGetElement() throws { | ||
try assertNil(Kt54119Kt.callGetElement(set: [222])) | ||
} | ||
|
||
private func testMapContainsKey() throws { | ||
try assertFalse(Kt54119Kt.callContainsKey(map: ["abc" : "def"])) | ||
} | ||
|
||
private func testMapContainsValue() throws { | ||
try assertFalse(Kt54119Kt.callContainsValue(map: [KT54119KotlinKey() : 1])) | ||
} | ||
|
||
private func testMapGet() throws { | ||
try assertNil(Kt54119Kt.callGet(map: [0 : 0])) | ||
} | ||
|
||
private func testMapGetOrThrowConcurrentModification() throws { | ||
Kt54119Kt.callGetOrThrowConcurrentModification(map: [KT54119KotlinKey() : 2]) | ||
} | ||
|
||
private func testMapContainsEntry() throws { | ||
try assertTrue(Kt54119Kt.callContainsEntry(map: [KT54119KotlinKey() : 3])) | ||
} | ||
|
||
class Kt54119Tests : SimpleTestProvider { | ||
override init() { | ||
super.init() | ||
|
||
test("testSetContains", testSetContains) | ||
test("testSetGetElement", testSetGetElement) | ||
test("testMapContainsKey", testMapContainsKey) | ||
test("testMapContainsValue", testMapContainsValue) | ||
test("testMapGet", testMapGet) | ||
test("testMapGetOrThrowConcurrentModification", testMapGetOrThrowConcurrentModification) | ||
test("testMapContainsEntry", testMapContainsEntry) | ||
} | ||
} |
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