Skip to content

Commit

Permalink
[Bugfix][CRT] Return error code on error from ModuleGetFunction (#17097)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lunderberg authored Jun 18, 2024
1 parent e58cb27 commit 9a7b148
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/runtime/crt/common/crt_runtime_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a7b148

Please sign in to comment.