From a8951f9fcb47e27e452af1a0f129827ffb83a815 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Fri, 17 Aug 2018 15:21:14 +0300 Subject: [PATCH] Fix ThreadLocal marking for mutable objects --- .../org/jetbrains/kotlin/KonanTest.groovy | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index a055356bfe1..028773c1b71 100644 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -710,14 +710,18 @@ class RunExternalTestGroup extends RunStandaloneKonanTest { } static String markMutableObjects(String text) { - def idx = text.indexOf("object ") - // FIXME: find only those who has vars inside - if (idx != -1) { - def lineBeforeIdx = text.substring(0, idx).lastIndexOf("\n") - text = text.substring(0, lineBeforeIdx) + "\n@kotlin.native.ThreadLocal" + text.substring(lineBeforeIdx) + def lines = text.readLines() + def result = new ArrayList(lines.size()) + lines.forEach { line -> + // FIXME: find only those who has vars inside + // Find object declarations and companion objects + if (line.matches("(?m)^\\s*object [a-zA-Z_][a-zA-Z0-9_]*\\s*.*") + || line.matches("(?m)^\\s*companion object.*")) { + result += "@kotlin.native.ThreadLocal" + } + result += line } - - return text + return result.join(System.lineSeparator()) } List createTestFiles() {