From 2cb2f6fe03e9b1f42fc57e82a410d62a3fb7b60d Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Fri, 30 Aug 2019 10:53:49 +0300 Subject: [PATCH] Don't use heap-like slot for return in KotlinMutableSet/Dictionary Fix #3259 --- runtime/src/main/cpp/ObjCExportCollections.mm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/src/main/cpp/ObjCExportCollections.mm b/runtime/src/main/cpp/ObjCExportCollections.mm index cd265dfa0bd..1b7e03139fc 100644 --- a/runtime/src/main/cpp/ObjCExportCollections.mm +++ b/runtime/src/main/cpp/ObjCExportCollections.mm @@ -366,7 +366,9 @@ static inline id KSet_getElement(KRef set, id object) { -(instancetype)init { if (self = [super init]) { Kotlin_initRuntimeIfNeeded(); - Kotlin_MutableSet_createWithCapacity(8, self->setHolder.slotToInit()); + ObjHolder holder; + KRef set = Kotlin_MutableSet_createWithCapacity(8, holder.slot()); + self->setHolder.init(set); } return self; @@ -375,7 +377,9 @@ static inline id KSet_getElement(KRef set, id object) { - (instancetype)initWithCapacity:(NSUInteger)numItems { if (self = [super init]) { Kotlin_initRuntimeIfNeeded(); - Kotlin_MutableSet_createWithCapacity(objCCapacityToKotlin(numItems), self->setHolder.slotToInit()); + ObjHolder holder; + KRef set = Kotlin_MutableSet_createWithCapacity(objCCapacityToKotlin(numItems), holder.slot()); + self->setHolder.init(set); } return self; @@ -511,7 +515,9 @@ static inline id KMap_get(KRef map, id aKey) { -(instancetype)init { if (self = [super init]) { Kotlin_initRuntimeIfNeeded(); - Kotlin_MutableMap_createWithCapacity(8, self->mapHolder.slotToInit()); + ObjHolder holder; + KRef map = Kotlin_MutableMap_createWithCapacity(8, holder.slot()); + self->mapHolder.init(map); } return self; } @@ -525,7 +531,9 @@ static inline id KMap_get(KRef map, id aKey) { - (instancetype)initWithCapacity:(NSUInteger)numItems { if (self = [super init]) { Kotlin_initRuntimeIfNeeded(); - Kotlin_MutableMap_createWithCapacity(objCCapacityToKotlin(numItems), self->mapHolder.slotToInit()); + ObjHolder holder; + KRef map = Kotlin_MutableMap_createWithCapacity(objCCapacityToKotlin(numItems), holder.slot()); + self->mapHolder.init(map); } return self; }