[K2/N] Export C adapters for non-root packages

^KT-56182

Merge-request: KT-MR-10160
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-05-19 11:40:59 +00:00
committed by Space Team
parent c57c34525f
commit 363c56e226
13 changed files with 313 additions and 17 deletions
@@ -0,0 +1,28 @@
#include "testlib_api.h"
#include <thread>
int main() {
auto t = std::thread([] {
auto lib = testlib_symbols();
lib->kotlin.root.knlibrary.subpackage.enableMemoryChecker();
// Initialize A and B.Companion and get their stable pointers.
auto a = lib->kotlin.root.knlibrary.subpackage.A._instance();
auto bCompanion = lib->kotlin.root.knlibrary.subpackage.B.Companion._instance();
// Now, dispose of the stable pointers.
lib->DisposeStablePointer(bCompanion.pinned);
lib->DisposeStablePointer(a.pinned);
// A and B.Companion now are owned by the global references only.
});
// This causes Kotlin runtime full deinitialization, because `t` is the only thread
// with the Kotlin runtime. So, all the globals will get deinitialized and memory
// leak checker will get executed (because .kt code is compiled with -g).
t.join();
return 0;
}