Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions extension/android/jni/jni_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
Expand Down Expand Up @@ -363,6 +363,8 @@

std::vector<EValue> evalues;
std::vector<TensorPtr> tensors;
std::vector<std::unique_ptr<std::string>> strings;
std::vector<std::unique_ptr<executorch::aten::ArrayRef<char>>> string_refs;

static const auto typeCodeField =
JEValue::javaClassStatic()->getField<jint>("mTypeCode");
Expand All @@ -373,6 +375,24 @@
if (typeCode == JEValue::kTypeCodeTensor) {
tensors.emplace_back(JEValue::JEValueToTensorImpl(jevalue));
evalues.emplace_back(tensors.back());
} else if (typeCode == JEValue::kTypeCodeString) {
static const auto toStrMethod =
JEValue::javaClassStatic()
->getMethod<facebook::jni::local_ref<jstring>()>("toStr");
auto jstr = toStrMethod(jevalue);
if (!jstr) {
jni_helper::throwExecutorchException(
static_cast<uint32_t>(Error::InvalidArgument),
"String EValue input at index " + std::to_string(i) +
" is null");
return {};
}
auto str = std::make_unique<std::string>(jstr->toStdString());
auto ref = std::make_unique<executorch::aten::ArrayRef<char>>(
str->data(), str->size());
evalues.emplace_back(ref.get());
Comment thread
psiddh marked this conversation as resolved.
strings.push_back(std::move(str));
string_refs.push_back(std::move(ref));
} else if (typeCode == JEValue::kTypeCodeInt) {
static const auto toIntMethod =
JEValue::javaClassStatic()->getMethod<jlong()>("toInt");
Comment thread
psiddh marked this conversation as resolved.
Expand All @@ -385,6 +405,12 @@
static const auto toBoolMethod =
JEValue::javaClassStatic()->getMethod<jboolean()>("toBool");
evalues.emplace_back(static_cast<bool>(toBoolMethod(jevalue)));
} else {
std::stringstream ss;
ss << "Unsupported input EValue type code: " << typeCode;
jni_helper::throwExecutorchException(
static_cast<uint32_t>(Error::InvalidArgument), ss.str());
return {};
}
}

Expand Down
Loading