This is an automated email from the ASF dual-hosted git repository.
lunderberg pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 9a7b148628 [Bugfix][CRT] Return error code on error from
ModuleGetFunction (#17097)
9a7b148628 is described below
commit 9a7b14862884c43e413b4acfc96e040a7af3689d
Author: Eric Lunderberg <[email protected]>
AuthorDate: Tue Jun 18 13:28:02 2024 -0500
[Bugfix][CRT] Return error code on error from ModuleGetFunction (#17097)
Prior to this commit, `ModuleGetFunction` returned zero if called with
an incorrect number of arguments, or with incorrect type codes. This
incorrectly indicated that the module was inspected, and did not
contain the requested function.
This commit corrects the implementation of `ModuleGetFunction` to
instead call set an error message with `TVMAPISetLastError`, then to
return an appropriate error code.
---
src/runtime/crt/common/crt_runtime_api.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/runtime/crt/common/crt_runtime_api.c
b/src/runtime/crt/common/crt_runtime_api.c
index 99b3201b95..57979b160e 100644
--- a/src/runtime/crt/common/crt_runtime_api.c
+++ b/src/runtime/crt/common/crt_runtime_api.c
@@ -349,9 +349,21 @@ int ModuleGetFunction(TVMValue* args, int* type_codes, int
num_args, TVMValue* r
ret_value[0].v_handle = NULL;
ret_type_codes[0] = kTVMNullptr;
- if (num_args != 3 || type_codes[0] != kTVMModuleHandle || type_codes[1] !=
kTVMStr ||
- type_codes[2] != kDLInt) {
- return 0;
+ if (num_args != 3) {
+ TVMAPISetLastError("ModuleGetFunction expects exactly 3 arguments");
+ return kTvmErrorFunctionCallNumArguments;
+ }
+ if (type_codes[0] != kTVMModuleHandle) {
+ TVMAPISetLastError("ModuleGetFunction expects first argument to be a
Module");
+ return kTvmErrorFunctionCallWrongArgType;
+ }
+ if (type_codes[1] != kTVMStr) {
+ TVMAPISetLastError("ModuleGetFunction expects second argument to be a
string");
+ return kTvmErrorFunctionCallWrongArgType;
+ }
+ if (type_codes[2] != kDLInt) {
+ TVMAPISetLastError("ModuleGetFunction expects third argument to be an
integer");
+ return kTvmErrorFunctionCallWrongArgType;
}
mod = (TVMModuleHandle)args[0].v_handle;