diff --git a/kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp b/kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp index 60d1bc8750f..32ff138ba85 100644 --- a/kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp +++ b/kotlin-native/backend.native/tests/interop/incomplete_types/library.cpp @@ -1,21 +1,24 @@ +#include #include "library.h" extern "C" { struct S { - const char* name; + std::string name; }; -struct S s = { +S s = { .name = "initial" }; void setContent(struct S* s, const char* name) { + // Note that copy here is intentional: we use it as a workaround + // for short lifetime of copy of the passed Kotlin string. s->name = name; } const char* getContent(struct S* s) { - return s->name; + return s->name.c_str(); } union U { diff --git a/kotlin-native/backend.native/tests/interop/incomplete_types/main.kt b/kotlin-native/backend.native/tests/interop/incomplete_types/main.kt index 8118c449c29..11ac83e16d1 100644 --- a/kotlin-native/backend.native/tests/interop/incomplete_types/main.kt +++ b/kotlin-native/backend.native/tests/interop/incomplete_types/main.kt @@ -9,7 +9,8 @@ fun main() { assertEquals("initial", getContent(s.ptr)?.toKString()) setContent(s.ptr, "yo") - assertEquals("yo", getContent(s.ptr)?.toKString()) + val ptr = getContent(s.ptr) + assertEquals("yo", ptr?.toKString()) assertEquals(0.0, getDouble(u.ptr)) setDouble(u.ptr, Double.MIN_VALUE)