Unverified Commit 2942278a by Tianqi Chen Committed by GitHub

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

parent df8a6f3b
...@@ -513,9 +513,12 @@ class TVMArgValue : public TVMPODValue_ { ...@@ -513,9 +513,12 @@ class TVMArgValue : public TVMPODValue_ {
} }
} }
operator tvm::runtime::String() const { operator tvm::runtime::String() const {
// directly use the std::string constructor for now. if (IsObjectRef<tvm::runtime::String>()) {
return AsObjectRef<tvm::runtime::String>();
} else {
return tvm::runtime::String(operator std::string()); return tvm::runtime::String(operator std::string());
} }
}
operator DLDataType() const { operator DLDataType() const {
if (type_code_ == kTVMStr) { if (type_code_ == kTVMStr) {
return String2DLDataType(operator std::string()); return String2DLDataType(operator std::string());
...@@ -605,9 +608,12 @@ class TVMRetValue : public TVMPODValue_ { ...@@ -605,9 +608,12 @@ class TVMRetValue : public TVMPODValue_ {
return *ptr<std::string>(); return *ptr<std::string>();
} }
operator tvm::runtime::String() const { operator tvm::runtime::String() const {
// directly use the std::string constructor for now. if (IsObjectRef<tvm::runtime::String>()) {
return AsObjectRef<tvm::runtime::String>();
} else {
return tvm::runtime::String(operator std::string()); return tvm::runtime::String(operator std::string());
} }
}
operator DLDataType() const { operator DLDataType() const {
if (type_code_ == kTVMStr) { if (type_code_ == kTVMStr) {
return String2DLDataType(operator std::string()); return String2DLDataType(operator std::string());
......
...@@ -95,6 +95,12 @@ TEST(PackedFunc, str) { ...@@ -95,6 +95,12 @@ TEST(PackedFunc, str) {
CHECK(y == "hello"); CHECK(y == "hello");
*rv = x; *rv = x;
})("hello"); })("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