Skip to content

Commit 7ef46d2

Browse files
committed
Debug UTF-16 issue
1 parent ec1c431 commit 7ef46d2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

extension/android/jni/jni_layer_llama.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
#include <cassert>
1010
#include <chrono>
11+
#include <codecvt>
1112
#include <iostream>
13+
#include <locale>
1214
#include <memory>
1315
#include <sstream>
1416
#include <string>
@@ -21,6 +23,7 @@
2123
#include <executorch/runtime/platform/log.h>
2224
#include <executorch/runtime/platform/platform.h>
2325
#include <executorch/runtime/platform/runtime.h>
26+
#include <android/log.h>
2427

2528
#if defined(ET_USE_THREADPOOL)
2629
#include <executorch/extension/threadpool/cpuinfo_utils.h>
@@ -41,11 +44,15 @@ class ExecuTorchLlamaCallbackJni
4144
constexpr static const char* kJavaDescriptor =
4245
"Lorg/pytorch/executorch/LlamaCallback;";
4346

47+
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
48+
4449
void onResult(std::string result) const {
4550
static auto cls = ExecuTorchLlamaCallbackJni::javaClassStatic();
4651
static const auto method =
4752
cls->getMethod<void(facebook::jni::local_ref<jstring>)>("onResult");
48-
facebook::jni::local_ref<jstring> s = facebook::jni::make_jstring(result);
53+
std::u16string result_u16 = converter.from_bytes(result);
54+
__android_log_print(ANDROID_LOG_ERROR, "ExecuTorchDBG", "U16:%s", result_u16.c_str());
55+
facebook::jni::local_ref<jstring> s = facebook::jni::make_jstring(result_u16);
4956
method(self(), s);
5057
}
5158

0 commit comments

Comments
 (0)