Generate reverse interop stubs (#1065)

This commit is contained in:
Nikolay Igotti
2017-11-30 18:09:40 +03:00
committed by GitHub
parent 6492682b28
commit 8ae1a156b7
6 changed files with 588 additions and 7 deletions
+10
View File
@@ -694,6 +694,16 @@ OBJ_GETTER(CreateStringFromUtf8, const char* utf8, uint32_t lengthBytes) {
RETURN_RESULT_OF(utf8ToUtf16, utf8, lengthBytes);
}
char* CreateCStringFromString(KConstRef kref) {
KString kstring = kref->array();
const KChar* utf16 = CharArrayAddressOfElementAt(kstring, 0);
KStdString utf8;
utf8::unchecked::utf16to8(utf16, utf16 + kstring->count_, back_inserter(utf8));
char* result = reinterpret_cast<char*>(konan::calloc(1, utf8.size() + 1));
::memcpy(result, utf8.c_str(), utf8.size());
return result;
}
// String.kt
KInt Kotlin_String_compareTo(KString thiz, KString other) {
int result = memcmp(
+1
View File
@@ -28,6 +28,7 @@ extern "C" {
OBJ_GETTER(CreateStringFromCString, const char* cstring);
OBJ_GETTER(CreateStringFromUtf8, const char* utf8, uint32_t size);
char* CreateCStringFromString(KConstRef kstring);
#ifdef __cplusplus
}