From 3388ca2536cea9a89dd687d10e4befc1ec10b6d1 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Wed, 19 May 2021 07:31:12 +0000 Subject: [PATCH] Support ObjC blocks in the new MM --- kotlin-native/backend.native/tests/build.gradle | 6 +++--- kotlin-native/runtime/src/mm/cpp/Memory.cpp | 7 +++++++ kotlin-native/runtime/src/mm/cpp/Stubs.cpp | 4 ---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 5ab71a6c38d..7baf0d06e51 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4759,7 +4759,7 @@ Task frameworkTest(String name, Closure configurator) { if (isAppleTarget(project)) { frameworkTest('testObjCExport') { - enabled = !isExperimentalMM // Experimental MM doesn't support ObjC blocks and thread state switching for ObjC interop yet. + enabled = !isExperimentalMM // Experimental MM does not support Obj-C weaks and thread state switching for ObjC interop yet. final String frameworkName = 'Kt' final String dir = "$testOutputFramework/testObjCExport" final File lazyHeader = file("$dir/$target-lazy.h") @@ -4808,7 +4808,7 @@ if (isAppleTarget(project)) { } frameworkTest('testObjCExportNoGenerics') { - enabled = !isExperimentalMM // Experimental MM doesn't support ObjC blocks and thread state switching for ObjC interop yet. + enabled = !isExperimentalMM // Experimental MM does not support Obj-C weaks and thread state switching for ObjC interop yet. final String frameworkName = 'KtNoGenerics' final String frameworkArtifactName = 'Kt' final String dir = "$testOutputFramework/testObjCExportNoGenerics" @@ -4861,7 +4861,7 @@ if (isAppleTarget(project)) { } frameworkTest('testObjCExportStatic') { - enabled = !isExperimentalMM // Experimental MM doesn't support ObjC blocks and thread state switching for ObjC interop yet. + enabled = !isExperimentalMM // Experimental MM does not support Obj-C weaks and thread state switching for ObjC interop yet. final String frameworkName = 'KtStatic' final String frameworkArtifactName = 'Kt' final String libraryName = frameworkName + "Library" diff --git a/kotlin-native/runtime/src/mm/cpp/Memory.cpp b/kotlin-native/runtime/src/mm/cpp/Memory.cpp index e918b2171af..025fc234fa8 100644 --- a/kotlin-native/runtime/src/mm/cpp/Memory.cpp +++ b/kotlin-native/runtime/src/mm/cpp/Memory.cpp @@ -444,6 +444,12 @@ extern "C" void EnsureNeverFrozen(ObjHeader* obj) { } } +extern "C" ForeignRefContext InitLocalForeignRef(ObjHeader* object) { + // TODO: Remove when legacy MM is gone. + // Nothing to do. + return nullptr; +} + extern "C" ForeignRefContext InitForeignRef(ObjHeader* object) { auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData(); auto* node = mm::StableRefRegistry::Instance().RegisterStableRef(threadData, object); @@ -451,6 +457,7 @@ extern "C" ForeignRefContext InitForeignRef(ObjHeader* object) { } extern "C" void DeinitForeignRef(ObjHeader* object, ForeignRefContext context) { + RuntimeAssert(context != nullptr, "DeinitForeignRef must not be called for InitLocalForeignRef"); auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData(); auto* node = FromForeignRefManager(context); RuntimeAssert(object == **node, "Must correspond to the same object"); diff --git a/kotlin-native/runtime/src/mm/cpp/Stubs.cpp b/kotlin-native/runtime/src/mm/cpp/Stubs.cpp index dbd57d73909..8316b67221f 100644 --- a/kotlin-native/runtime/src/mm/cpp/Stubs.cpp +++ b/kotlin-native/runtime/src/mm/cpp/Stubs.cpp @@ -21,8 +21,4 @@ RUNTIME_NOTHROW void ReleaseHeapRefNoCollect(const ObjHeader* object) { TODO(); } -ForeignRefContext InitLocalForeignRef(ObjHeader* object) { - TODO(); -} - } // extern "C"