Native: rewrite Kotlin_Interop_getObjCClass in Objective-C
This allows calling it in "Native" thread state.
This commit is contained in:
committed by
Space
parent
dc27391cc7
commit
2e8c25aeff
@@ -133,19 +133,6 @@ internal annotation class ObjCMethodImp(val selector: String, val encoding: Stri
|
|||||||
@TypedIntrinsic(IntrinsicType.OBJC_GET_SELECTOR)
|
@TypedIntrinsic(IntrinsicType.OBJC_GET_SELECTOR)
|
||||||
internal external fun objCGetSelector(selector: String): COpaquePointer
|
internal external fun objCGetSelector(selector: String): COpaquePointer
|
||||||
|
|
||||||
@kotlin.native.internal.ExportForCppRuntime("Kotlin_Interop_getObjCClass")
|
|
||||||
private fun getObjCClassByName(name: NativePtr): NativePtr {
|
|
||||||
val result = objc_lookUpClass(name)
|
|
||||||
if (result == nativeNullPtr) {
|
|
||||||
val className = interpretCPointer<ByteVar>(name)!!.toKString()
|
|
||||||
val message = """Objective-C class '$className' not found.
|
|
||||||
|Ensure that the containing framework or library was linked.""".trimMargin()
|
|
||||||
|
|
||||||
throw RuntimeException(message)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
@kotlin.native.internal.ExportForCompiler
|
@kotlin.native.internal.ExportForCompiler
|
||||||
private fun allocObjCObject(clazz: NativePtr): NativePtr {
|
private fun allocObjCObject(clazz: NativePtr): NativePtr {
|
||||||
val rawResult = objc_allocWithZone(clazz)
|
val rawResult = objc_allocWithZone(clazz)
|
||||||
@@ -219,6 +206,3 @@ external fun objc_retain(ptr: NativePtr): NativePtr
|
|||||||
|
|
||||||
@GCUnsafeCall("Kotlin_objc_release")
|
@GCUnsafeCall("Kotlin_objc_release")
|
||||||
external fun objc_release(ptr: NativePtr)
|
external fun objc_release(ptr: NativePtr)
|
||||||
|
|
||||||
@GCUnsafeCall("Kotlin_objc_lookUpClass")
|
|
||||||
external fun objc_lookUpClass(name: NativePtr): NativePtr
|
|
||||||
|
|||||||
@@ -173,7 +173,11 @@ void releaseAsAssociatedObjectImp(id self, SEL _cmd, ReleaseMode mode) {
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
Class Kotlin_Interop_getObjCClass(const char* name);
|
Class Kotlin_Interop_getObjCClass(const char* name) {
|
||||||
|
Class result = objc_lookUpClass(name);
|
||||||
|
RuntimeCheck(result != nil, "Objective-C class '%s' not found. Ensure that the containing framework or library was linked.", name);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
const TypeInfo* GetObjCKotlinTypeInfo(ObjHeader* obj) RUNTIME_NOTHROW;
|
const TypeInfo* GetObjCKotlinTypeInfo(ObjHeader* obj) RUNTIME_NOTHROW;
|
||||||
|
|
||||||
@@ -391,10 +395,6 @@ void Kotlin_objc_release(id ptr) {
|
|||||||
objc_release(ptr);
|
objc_release(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Class Kotlin_objc_lookUpClass(const char* name) {
|
|
||||||
return objc_lookUpClass(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
#else // KONAN_OBJC_INTEROP
|
#else // KONAN_OBJC_INTEROP
|
||||||
@@ -426,11 +426,6 @@ void Kotlin_objc_release(void* ptr) {
|
|||||||
RuntimeAssert(false, "Objective-C interop is disabled");
|
RuntimeAssert(false, "Objective-C interop is disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Kotlin_objc_lookUpClass(const char* name) {
|
|
||||||
RuntimeAssert(false, "Objective-C interop is disabled");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
#endif // KONAN_OBJC_INTEROP
|
#endif // KONAN_OBJC_INTEROP
|
||||||
|
|||||||
@@ -14,15 +14,6 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
Class Kotlin_Interop_getObjCClass(const char* name) {
|
|
||||||
Class result = objc_lookUpClass(name);
|
|
||||||
if (result == nil) {
|
|
||||||
// GTest can display error messages of C++ exceptions so we use them instead of ObjC ones.
|
|
||||||
throw std::invalid_argument("Incorrect class name");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
RUNTIME_NORETURN OBJ_GETTER0(Kotlin_NSEnumeratorAsKIterator_create) {
|
RUNTIME_NORETURN OBJ_GETTER0(Kotlin_NSEnumeratorAsKIterator_create) {
|
||||||
throw std::runtime_error("Not implemented for tests");
|
throw std::runtime_error("Not implemented for tests");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user