escape invalid keyword chars in include file paths and package name (#1384)
This commit is contained in:
committed by
Nikolay Igotti
parent
cca9280093
commit
d7c49bfd46
+7
-3
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val INVALID_CLANG_IDENTIFIER_REGEX = "[^a-zA-Z1-9_]".toRegex()
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user