Avoid recursive runtime init bug. (#3020)
This commit is contained in:
@@ -598,6 +598,12 @@ task array_to_any(type: RunKonanTest) {
|
||||
source = "codegen/basics/array_to_any.kt"
|
||||
}
|
||||
|
||||
task runtime_basic_init(type: RunStandaloneKonanTest) {
|
||||
source = "runtime/basic/init.kt"
|
||||
flags = ['-g']
|
||||
expectedExitStatus = 0
|
||||
}
|
||||
|
||||
task runtime_basic_exit(type: RunStandaloneKonanTest) {
|
||||
source = "runtime/basic/exit.kt"
|
||||
expectedExitStatus = 42
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
val x = initRuntimeIfNeeded()
|
||||
|
||||
fun main() {
|
||||
}
|
||||
@@ -79,13 +79,14 @@ RuntimeState* initRuntime() {
|
||||
SetKonanTerminateHandler();
|
||||
RuntimeState* result = konanConstructInstance<RuntimeState>();
|
||||
if (!result) return nullptr;
|
||||
RuntimeCheck(runtimeState == nullptr, "No active runtimes allowed");
|
||||
runtimeState = result;
|
||||
result->memoryState = InitMemory();
|
||||
bool firstRuntime = atomicAdd(&aliveRuntimesCount, 1) == 1;
|
||||
// Keep global variables in state as well.
|
||||
if (firstRuntime) {
|
||||
isMainThread = 1;
|
||||
konan::consoleInit();
|
||||
|
||||
InitOrDeinitGlobalVariables(INIT_GLOBALS);
|
||||
}
|
||||
InitOrDeinitGlobalVariables(INIT_THREAD_LOCAL_GLOBALS);
|
||||
@@ -117,7 +118,7 @@ void AppendToInitializersTail(InitNode *next) {
|
||||
|
||||
void Kotlin_initRuntimeIfNeeded() {
|
||||
if (runtimeState == nullptr) {
|
||||
runtimeState = initRuntime();
|
||||
initRuntime();
|
||||
RuntimeCheck(updateStatusIf(runtimeState, SUSPENDED, RUNNING), "Cannot transition state to RUNNING for init");
|
||||
// Register runtime deinit function at thread cleanup.
|
||||
konan::onThreadExit(Kotlin_deinitRuntimeIfNeeded);
|
||||
|
||||
Reference in New Issue
Block a user