Unverified Commit 2942278a by Tianqi Chen Committed by GitHub

[RUNTIME] Quick fix PackedFunc String passing (#5266)

parent df8a6f3b
......@@ -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) {
......@@ -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) {
......
......@@ -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"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment