Skip to content

Commit 9a7b148

Browse files
authored
[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.
1 parent e58cb27 commit 9a7b148

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/runtime/crt/common/crt_runtime_api.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,21 @@ int ModuleGetFunction(TVMValue* args, int* type_codes, int num_args, TVMValue* r
349349

350350
ret_value[0].v_handle = NULL;
351351
ret_type_codes[0] = kTVMNullptr;
352-
if (num_args != 3 || type_codes[0] != kTVMModuleHandle || type_codes[1] != kTVMStr ||
353-
type_codes[2] != kDLInt) {
354-
return 0;
352+
if (num_args != 3) {
353+
TVMAPISetLastError("ModuleGetFunction expects exactly 3 arguments");
354+
return kTvmErrorFunctionCallNumArguments;
355+
}
356+
if (type_codes[0] != kTVMModuleHandle) {
357+
TVMAPISetLastError("ModuleGetFunction expects first argument to be a Module");
358+
return kTvmErrorFunctionCallWrongArgType;
359+
}
360+
if (type_codes[1] != kTVMStr) {
361+
TVMAPISetLastError("ModuleGetFunction expects second argument to be a string");
362+
return kTvmErrorFunctionCallWrongArgType;
363+
}
364+
if (type_codes[2] != kDLInt) {
365+
TVMAPISetLastError("ModuleGetFunction expects third argument to be an integer");
366+
return kTvmErrorFunctionCallWrongArgType;
355367
}
356368

357369
mod = (TVMModuleHandle)args[0].v_handle;

0 commit comments

Comments
 (0)