Skip to content

Commit

Permalink
[RUNTIME] Quick fix PackedFunc String passing (apache#5266)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored and dpankratz committed Apr 24, 2020
1 parent df87292 commit 3761539
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit 3761539

Please sign in to comment.