Separated native and jvm staticCFunction() because for native it needs not be inline now.

This commit is contained in:
Alexander Gorshenev
2017-04-13 13:58:18 +03:00
committed by alexander-gorshenev
parent a434e039b2
commit 8d2c6e4878
3 changed files with 28 additions and 13 deletions
@@ -55,4 +55,14 @@ fun <T : CPointed> interpretCPointer(rawValue: NativePtr) =
inline fun <reified T : CAdaptedFunctionType<*>> CAdaptedFunctionType.Companion.getInstanceOf(): T =
T::class.objectInstance!!
internal fun CPointer<*>.cPointerToString() = "CPointer(raw=0x%x)".format(rawValue)
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 F : Function<*>, reified T : CAdaptedFunctionType<F>> staticCFunction(body: F): CFunctionPointer<T> {
val type = CAdaptedFunctionType.getInstanceOf<T>()
return interpretPointed<CFunction<T>>(type.fromStatic(body)).ptr
}
@@ -405,15 +405,6 @@ interface CAdaptedFunctionType<F : Function<*>> : CFunctionType {
companion object
}
/**
* Returns a pointer to `T`-typed C function which calls given Kotlin *static* function.
* @see CAdaptedFunctionType.fromStatic
*/
inline fun <reified F : Function<*>, reified T : CAdaptedFunctionType<F>> staticCFunction(body: F): CFunctionPointer<T> {
val type = CAdaptedFunctionType.getInstanceOf<T>()
return interpretPointed<CFunction<T>>(type.fromStatic(body)).ptr
}
/**
* The C function.
*/
@@ -429,4 +420,4 @@ typealias CFunctionPointer<T> = CPointer<CFunction<T>>
* The variable containing a [CFunctionPointer].
* TODO: remove.
*/
typealias CFunctionPointerVar<T> = CPointerVarOf<CFunctionPointer<T>>
typealias CFunctionPointerVar<T> = CPointerVarOf<CFunctionPointer<T>>
@@ -35,6 +35,20 @@ fun <T : CVariable> typeOf(): CVariable.Type = throw Error("typeOf() is called w
@Intrinsic external fun CPointer<*>.getRawValue(): NativePtr
inline fun <reified T : CAdaptedFunctionType<*>> 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 <F : Function<*>, T : CAdaptedFunctionType<F>> staticCFunction(body: F): CFunctionPointer<T> {
val type = CAdaptedFunctionType.getInstanceOf<T>()
return interpretPointed<CFunction<T>>(type.fromStatic(body)).ptr
}
internal fun CPointer<*>.cPointerToString() = "CPointer(raw=$rawValue)"