Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RUNTIME] Quick fix PackedFunc String passing #5266

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions include/tvm/runtime/packed_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,11 @@ class TVMArgValue : public TVMPODValue_ {
}
}
operator tvm::runtime::String() const {
// directly use the std::string constructor for now.
return tvm::runtime::String(operator std::string());
if (IsObjectRef<tvm::runtime::String>()) {
return AsObjectRef<tvm::runtime::String>();
} else {
return tvm::runtime::String(operator std::string());
}
}
operator DLDataType() const {
if (type_code_ == kTVMStr) {
Expand Down Expand Up @@ -605,8 +608,11 @@ class TVMRetValue : public TVMPODValue_ {
return *ptr<std::string>();
}
operator tvm::runtime::String() const {
// directly use the std::string constructor for now.
return tvm::runtime::String(operator std::string());
if (IsObjectRef<tvm::runtime::String>()) {
return AsObjectRef<tvm::runtime::String>();
} else {
return tvm::runtime::String(operator std::string());
}
}
operator DLDataType() const {
if (type_code_ == kTVMStr) {
Expand Down
6 changes: 6 additions & 0 deletions tests/cpp/packed_func_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ TEST(PackedFunc, str) {
CHECK(y == "hello");
*rv = x;
})("hello");

PackedFunc([&](TVMArgs args, TVMRetValue* rv) {
CHECK(args.num_args == 1);
runtime::String s = args[0];
CHECK(s == "hello");
})(runtime::String("hello"));
}


Expand Down