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
+6
-2
@@ -107,7 +107,7 @@ class SimpleBridgeGeneratorImpl(
|
|||||||
"JNIEXPORT $cReturnType JNICALL $functionName ($joinedCParameters)"
|
"JNIEXPORT $cReturnType JNICALL $functionName ($joinedCParameters)"
|
||||||
}
|
}
|
||||||
KotlinPlatform.NATIVE -> {
|
KotlinPlatform.NATIVE -> {
|
||||||
val functionName = pkgName.replace('.', '_') + "_$kotlinFunctionName"
|
val functionName = pkgName.replace(INVALID_CLANG_IDENTIFIER_REGEX, "_") + "_$kotlinFunctionName"
|
||||||
kotlinLines.add("@SymbolName(${functionName.quoteAsKotlinLiteral()})")
|
kotlinLines.add("@SymbolName(${functionName.quoteAsKotlinLiteral()})")
|
||||||
"$cReturnType $functionName ($joinedCParameters)"
|
"$cReturnType $functionName ($joinedCParameters)"
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ class SimpleBridgeGeneratorImpl(
|
|||||||
val joinedCParameters = cFunctionParameters.joinToString { (name, type) -> "$type $name" }
|
val joinedCParameters = cFunctionParameters.joinToString { (name, type) -> "$type $name" }
|
||||||
val cReturnType = returnType.nativeType
|
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()})")
|
kotlinLines.add("@konan.internal.ExportForCppRuntime(${symbolName.quoteAsKotlinLiteral()})")
|
||||||
val cFunctionHeader = "$cReturnType $symbolName($joinedCParameters)"
|
val cFunctionHeader = "$cReturnType $symbolName($joinedCParameters)"
|
||||||
|
|
||||||
@@ -237,4 +237,8 @@ class SimpleBridgeGeneratorImpl(
|
|||||||
nativeBacked !in excludedClients
|
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() }})")
|
out("@file:Suppress(${suppress.joinToString { it.quoteAsKotlinLiteral() }})")
|
||||||
if (pkgName != "") {
|
if (pkgName != "") {
|
||||||
out("package $pkgName")
|
val packageName = pkgName.split(".").joinToString("."){
|
||||||
|
if(it.matches(VALID_PACKAGE_NAME_REGEX)){
|
||||||
|
it
|
||||||
|
}else{
|
||||||
|
"`$it`"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out("package $packageName")
|
||||||
out("")
|
out("")
|
||||||
}
|
}
|
||||||
if (platform == KotlinPlatform.NATIVE) {
|
if (platform == KotlinPlatform.NATIVE) {
|
||||||
@@ -1012,4 +1019,8 @@ class StubGenerator(
|
|||||||
|
|
||||||
val mappingBridgeGenerator: MappingBridgeGenerator =
|
val mappingBridgeGenerator: MappingBridgeGenerator =
|
||||||
MappingBridgeGeneratorImpl(declarationMapper, simpleBridgeGenerator)
|
MappingBridgeGeneratorImpl(declarationMapper, simpleBridgeGenerator)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val VALID_PACKAGE_NAME_REGEX = "[a-zA-Z1-9_.]".toRegex()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user