diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt index 027a067ca6c..701a71cccbd 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/SimpleBridgeGeneratorImpl.kt @@ -107,7 +107,7 @@ class SimpleBridgeGeneratorImpl( "JNIEXPORT $cReturnType JNICALL $functionName ($joinedCParameters)" } KotlinPlatform.NATIVE -> { - val functionName = pkgName.replace('.', '_') + "_$kotlinFunctionName" + val functionName = pkgName.replace(INVALID_CLANG_IDENTIFIER_REGEX, "_") + "_$kotlinFunctionName" kotlinLines.add("@SymbolName(${functionName.quoteAsKotlinLiteral()})") "$cReturnType $functionName ($joinedCParameters)" } @@ -167,7 +167,7 @@ class SimpleBridgeGeneratorImpl( val joinedCParameters = cFunctionParameters.joinToString { (name, type) -> "$type $name" } val cReturnType = returnType.nativeType - val symbolName = pkgName.replace('.', '_') + "_$kotlinFunctionName" + val symbolName = pkgName.replace(INVALID_CLANG_IDENTIFIER_REGEX, "_") + "_$kotlinFunctionName" kotlinLines.add("@konan.internal.ExportForCppRuntime(${symbolName.quoteAsKotlinLiteral()})") val cFunctionHeader = "$cReturnType $symbolName($joinedCParameters)" @@ -237,4 +237,8 @@ class SimpleBridgeGeneratorImpl( nativeBacked !in excludedClients } } -} \ No newline at end of file + + companion object { + private val INVALID_CLANG_IDENTIFIER_REGEX = "[^a-zA-Z1-9_]".toRegex() + } +} diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt index bdd57c39d67..2383ec3ed82 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt @@ -891,7 +891,14 @@ class StubGenerator( out("@file:Suppress(${suppress.joinToString { it.quoteAsKotlinLiteral() }})") if (pkgName != "") { - out("package $pkgName") + val packageName = pkgName.split(".").joinToString("."){ + if(it.matches(VALID_PACKAGE_NAME_REGEX)){ + it + }else{ + "`$it`" + } + } + out("package $packageName") out("") } if (platform == KotlinPlatform.NATIVE) { @@ -1012,4 +1019,8 @@ class StubGenerator( val mappingBridgeGenerator: MappingBridgeGenerator = MappingBridgeGeneratorImpl(declarationMapper, simpleBridgeGenerator) + + companion object { + private val VALID_PACKAGE_NAME_REGEX = "[a-zA-Z1-9_.]".toRegex() + } }