https://kotlinlang.org logo
Title
j

jmullin

01/22/2018, 4:46 PM
So presently we can’t get a function pointer to a function that returns a struct by value. Two questions: is there a known workaround to this, and where does this feature sit on the priorities list (if anywhere currently)?
o

olonho

01/22/2018, 5:02 PM
Do you have a short code snippet for what you’re trying to achieve? Maybe creating an issue with more info would be helpful.
j

jmullin

01/22/2018, 5:07 PM
Sure. I believe this is what’s alluded to in the interop README under callbacks: https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md
From that README:
Note that some function types are not supported currently. For example, it is not possible to get pointer to function that receives or returns structs by value.
I’ll get a simplified snippet to illustrate.
fun returnsStructByValue(): CValue<foo_struct> {...}

fun attemptFunctionPointer() {
  // error: type CValue<foo_struct> is not supported in callback signature
  staticCFunction(::returnsStructByValue)
}
And in the interop headers:
typedef struct {
	void *foo;
} foo_struct;
o

olonho

01/22/2018, 5:34 PM
Sure, we just need to understand your usecase better.
j

jmullin

01/22/2018, 5:56 PM
At the moment my use case is only that I want to try interop with a library that uses a lot of callbacks returning structs by value. 😃 It’s Godot’s GDNative.
It’s been a long time since I’ve even brushed up against C, so it’s entirely possible I’m also just not understanding the nuances very well.
An example from their source of a struct that needs to be populated, containing a pointer to a function returning a struct by value: https://github.com/GodotNativeTools/godot_headers/blob/master/nativescript/godot_nativescript.h#L142