Don't generate functional types for functions with long signatures (#2349)
The K/N stdlib doesn't contain basic classes (e.g. Functon0, Function1 etc) for functional types with >22 parameters. So we cannot convert functional pointers with such signatures into Kotlin functional types and have to replace them with opaque pointers. Fix for GitHub issue #2334.
This commit is contained in:
+18
-3
@@ -77,7 +77,7 @@ private class ObjCCategoryImpl(
|
||||
override val properties = mutableListOf<ObjCProperty>()
|
||||
}
|
||||
|
||||
internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
||||
internal class NativeIndexImpl(val library: NativeLibrary, val verbose: Boolean = false) : NativeIndex() {
|
||||
|
||||
private sealed class DeclarationID {
|
||||
data class USR(val usr: String) : DeclarationID()
|
||||
@@ -154,6 +154,12 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
||||
|
||||
override lateinit var includedHeaders: List<HeaderId>
|
||||
|
||||
private fun log(message: String) {
|
||||
if (verbose) {
|
||||
println(message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDeclarationId(cursor: CValue<CXCursor>): DeclarationID {
|
||||
val usr = clang_getCursorUSR(cursor).convertAndDispose()
|
||||
if (usr == "") {
|
||||
@@ -618,6 +624,15 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
||||
} else {
|
||||
val returnType = convertType(clang_getResultType(type))
|
||||
val numArgs = clang_getNumArgTypes(type)
|
||||
|
||||
// Ignore functions with long signatures since we have no basic class for such functional types in the stdlib.
|
||||
// TODO: Remove this limitation when functional types with long signatures are supported.
|
||||
if (numArgs > 22) {
|
||||
log("Warning: cannot generate a Kotlin functional type for a pointer to a function with more than 22 parameters. " +
|
||||
"An opaque pointer will be used instead.")
|
||||
return VoidType
|
||||
}
|
||||
|
||||
val paramTypes = (0..numArgs - 1).map {
|
||||
convertType(clang_getArgType(type, it))
|
||||
}
|
||||
@@ -902,8 +917,8 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
||||
|
||||
}
|
||||
|
||||
fun buildNativeIndexImpl(library: NativeLibrary): NativeIndex {
|
||||
val result = NativeIndexImpl(library)
|
||||
fun buildNativeIndexImpl(library: NativeLibrary, verbose: Boolean): NativeIndex {
|
||||
val result = NativeIndexImpl(library, verbose)
|
||||
indexDeclarations(result)
|
||||
findMacros(result)
|
||||
return result
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ data class NativeLibrary(val includes: List<String>,
|
||||
/**
|
||||
* Retrieves the definitions from given C header file using given compiler arguments (e.g. defines).
|
||||
*/
|
||||
fun buildNativeIndex(library: NativeLibrary): NativeIndex = buildNativeIndexImpl(library)
|
||||
fun buildNativeIndex(library: NativeLibrary, verbose: Boolean): NativeIndex = buildNativeIndexImpl(library, verbose)
|
||||
|
||||
/**
|
||||
* This class describes the IR of definitions from C header file(s).
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ private fun processCLib(args: Array<String>): Array<String>? {
|
||||
target = tool.target
|
||||
)
|
||||
|
||||
val nativeIndex = buildNativeIndex(library)
|
||||
val nativeIndex = buildNativeIndex(library, verbose)
|
||||
|
||||
val gen = StubGenerator(nativeIndex, configuration, libName, generateShims, verbose, flavor, imports)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user