diff --git a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt index d5c143c2376..0e40bfe43b9 100644 --- a/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt +++ b/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmTypes.kt @@ -55,4 +55,14 @@ fun interpretCPointer(rawValue: NativePtr) = inline fun > CAdaptedFunctionType.Companion.getInstanceOf(): T = T::class.objectInstance!! -internal fun CPointer<*>.cPointerToString() = "CPointer(raw=0x%x)".format(rawValue) \ No newline at end of file +internal fun CPointer<*>.cPointerToString() = "CPointer(raw=0x%x)".format(rawValue) + +/** + * Returns a pointer to `T`-typed C function which calls given Kotlin *static* function. + * @see CAdaptedFunctionType.fromStatic + */ +inline fun , reified T : CAdaptedFunctionType> staticCFunction(body: F): CFunctionPointer { + val type = CAdaptedFunctionType.getInstanceOf() + return interpretPointed>(type.fromStatic(body)).ptr +} + diff --git a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt index ff9b742e17b..36a50335a3d 100644 --- a/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt +++ b/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt @@ -405,15 +405,6 @@ interface CAdaptedFunctionType> : CFunctionType { companion object } -/** - * Returns a pointer to `T`-typed C function which calls given Kotlin *static* function. - * @see CAdaptedFunctionType.fromStatic - */ -inline fun , reified T : CAdaptedFunctionType> staticCFunction(body: F): CFunctionPointer { - val type = CAdaptedFunctionType.getInstanceOf() - return interpretPointed>(type.fromStatic(body)).ptr -} - /** * The C function. */ @@ -429,4 +420,4 @@ typealias CFunctionPointer = CPointer> * The variable containing a [CFunctionPointer]. * TODO: remove. */ -typealias CFunctionPointerVar = CPointerVarOf> \ No newline at end of file +typealias CFunctionPointerVar = CPointerVarOf> diff --git a/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt b/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt index 02ea3d57384..10127207bdf 100644 --- a/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt +++ b/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeTypes.kt @@ -35,6 +35,20 @@ fun typeOf(): CVariable.Type = throw Error("typeOf() is called w @Intrinsic external fun CPointer<*>.getRawValue(): NativePtr inline fun > CAdaptedFunctionType.Companion.getInstanceOf(): T = - TODO("CAdaptedFunctionType.getInstanceOf") + TODO("CAdaptedFunctionType.getInstanceOf 11") + +internal fun CPointer<*>.cPointerToString() = "CPointer(raw=$rawValue)" + +/** + * Returns a pointer to `T`-typed C function which calls given Kotlin *static* function. + * @see CAdaptedFunctionType.fromStatic + */ +// TODO: This function is not inline, whereas the same name function in JvmTypes.kt +// is inline. We can't make it inline here, because native interop lowering +// expects to find and transform it. And native interop lowering is done after +// inline expansions. +fun , T : CAdaptedFunctionType> staticCFunction(body: F): CFunctionPointer { + val type = CAdaptedFunctionType.getInstanceOf() + return interpretPointed>(type.fromStatic(body)).ptr +} -internal fun CPointer<*>.cPointerToString() = "CPointer(raw=$rawValue)" \ No newline at end of file