From 562057cf6958d1b9bc346f9429e46e4a414a14b9 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Fri, 17 Aug 2018 17:46:14 +0300 Subject: [PATCH] Fix interop_zlib test by properly converting ByteArray to String. (#1899) * Fix interop_zlib test by properly converting ByteArray to String. * Fix samples build. --- runtime/src/main/cpp/KString.cpp | 16 ++++++++++++---- samples/settings.gradle | 5 ++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/runtime/src/main/cpp/KString.cpp b/runtime/src/main/cpp/KString.cpp index fb6e2b2b059..3629ad93938 100644 --- a/runtime/src/main/cpp/KString.cpp +++ b/runtime/src/main/cpp/KString.cpp @@ -758,19 +758,27 @@ const char* byteArrayAsCString(KConstRef thiz, KInt start, KInt size) { } OBJ_GETTER(Kotlin_ByteArray_stringFromUtf8OrThrow, KConstRef thiz, KInt start, KInt size) { - const char* rawString = byteArrayAsCString(thiz, start, size); if (size == 0) { RETURN_RESULT_OF0(TheEmptyString); } - RETURN_RESULT_OF(utf8ToUtf16OrThrow, rawString, size); + const char* rawString = byteArrayAsCString(thiz, start, size); + KInt realSize = 0; + while (rawString[realSize] != 0 && realSize < size) { + realSize++; + } + RETURN_RESULT_OF(utf8ToUtf16OrThrow, rawString, realSize); } OBJ_GETTER(Kotlin_ByteArray_stringFromUtf8, KConstRef thiz, KInt start, KInt size) { - const char* rawString = byteArrayAsCString(thiz, start, size); if (size == 0) { RETURN_RESULT_OF0(TheEmptyString); } - RETURN_RESULT_OF(utf8ToUtf16, rawString, size); + const char* rawString = byteArrayAsCString(thiz, start, size); + KInt realSize = 0; + while (rawString[realSize] != 0 && realSize < size) { + realSize++; + } + RETURN_RESULT_OF(utf8ToUtf16, rawString, realSize); } OBJ_GETTER(Kotlin_String_toUtf8, KString thiz, KInt start, KInt size) { diff --git a/samples/settings.gradle b/samples/settings.gradle index 585fd56cf19..2764583d521 100644 --- a/samples/settings.gradle +++ b/samples/settings.gradle @@ -10,9 +10,8 @@ include ':nonBlockingEchoServer' include ':opengl' include ':socket' include ':tetris' -// ML samples have non-trivial deps, disable from here. -// include ':tensorflow' -// include ':torch' +include ':tensorflow' +include ':torch' // Android native activity build requires Android SDK. // So temporary switching off for now, as it breaks the build // of other samples if SDK is not present.