Tadeas Kriz
12/17/2024, 2:21 PMstaticCFunction call? I'm trying to declare expect fun <R> staticCFunction(function: () -> R): CPointer<CFunction<() -> R>> in commonMain, but when I try to declare actual fun <R> staticCFunction(function: () -> R): CPointer<CFunction<() -> R>> = kotlinx.cinterop.staticCFunction(function) in iosMain, I'm getting kotlinx.cinterop.staticCFunction must take an unbound, non-capturing function or lambda error. I tried putting in the internal annotations @VolatileLambda on function and @TypedIntrinsic(IntrinsicType.INTEROP_STATIC_C_FUNCTION) on the actual fun staticCFunction but it didn't help.
Is there anything I could do to make this work?ephemient
12/17/2024, 3:11 PMstaticCFunction are strict because it really needs to be static at build time, it can't create a closure thereTadeas Kriz
12/17/2024, 3:18 PMexpect/actual it also doesn't workTadeas Kriz
12/17/2024, 3:19 PMinline fun so that it'd actually be using staticCFunction directly but that also doesn't workTadeas Kriz
12/17/2024, 4:35 PMIrGetValueImpl but expects IrFunctionReference or IrFunctionExpression. Which sounds like staticCFunction has to always be called directly and can't be delegated.ephemient
12/17/2024, 5:07 PMstaticCFunction(::function)
where function is a static function (e.g. top-level) or equivalent lambda. it may not capture anything because there is a C function pointer cannot hold anything additionalTadeas Kriz
12/17/2024, 5:09 PMinline fun callStaticCFunction(noinline function: () -> Unit) {
staticCFunction(function)
}
even if you call callStaticCFunction(::function) and all the other requirements are metLandry Norris
12/17/2024, 7:17 PMTadeas Kriz
12/17/2024, 7:19 PMfunction is global Kotlin function and it works when I call staticCFunction(::function) directly, because of how the backend checker is verifying the IR. I don't really capture anything in my callStaticCFunction, but it'd require the backend checker to do more extensive check which would probably slow down the compileAlexander Hinze
12/22/2024, 1:10 PM