Hi everyone! I’m working on a library to expose K...
# kotlin-native
r
Hi everyone! I’m working on a library to expose Kotlin/Native bindings and have a question about handling variadic C functions on Linux native. Specifically, I’m dealing with functions like these: C function:
Copy code
void g_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...) G_GNUC_PRINTF(3, 4);
Kotlin/Native cinterop:
Copy code
fun g_log(log_domain: String?, log_level: Int, format: String?, vararg variadicArguments: Any?): Unit
And:
Copy code
void g_logv(const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args) G_GNUC_PRINTF(3, 0);
Kotlin/Native cinterop:
Copy code
fun g_logv(log_domain: String?, log_level: Int, format: String?, args: CPointer<platform.posix.__va_list_tag>?): Unit
I’m aware of KT-56164, which states that there’s currently no official support. However, I wanted to check here to see if anyone has found a workaround or a way to support these functions, even if it’s a bit hacky. I’m currently focusing on Linux, so a solution specific to this platform would be fine. Any insights or advice would be greatly appreciated!
l
You could create a set of wrapper functions, log1, log2, log3, etc. Each taking the appropriate number of arguments.
Although I note that the datatypes can differe as well, so that might not be feasible.
r
yeah I considered but supporting both CPointer and promitive types doesn't seem doable