tqchen commented on code in PR #49:
URL: https://github.com/apache/tvm-ffi/pull/49#discussion_r2373481398
##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -264,28 +266,42 @@ cdef inline object make_ret_opaque_object(TVMFFIAny
result):
cdef inline object make_ret_object(TVMFFIAny result):
global TYPE_INDEX_TO_INFO
- cdef int32_t tindex
- cdef object cls
- tindex = result.type_index
-
- if tindex < len(TYPE_INDEX_TO_CLS):
- cls = TYPE_INDEX_TO_CLS[tindex]
- if cls is not None:
- if issubclass(cls, PyNativeObject):
- obj = Object.__new__(Object)
- (<Object>obj).chandle = result.v_obj
- return cls.__from_tvm_ffi_object__(cls, obj)
+ cdef int32_t type_index
+ cdef str type_key
+ cdef object cls, obj, type_info
+ type_index = result.type_index
+
+ if type_index < len(TYPE_INDEX_TO_CLS) and (cls :=
TYPE_INDEX_TO_CLS[type_index]) is not None:
+ if issubclass(cls, PyNativeObject):
+ obj = Object.__new__(Object)
+ (<Object>obj).chandle = result.v_obj
+ return cls.__from_tvm_ffi_object__(cls, obj)
+ else:
obj = cls.__new__(cls)
(<Object>obj).chandle = result.v_obj
return obj
-
- # object is not found in registered entry
- # in this case we need to report an warning
- type_key = _type_index_to_key(tindex)
- warnings.warn(f"Returning type `{type_key}` which is not registered via
register_object, fallback to Object")
- obj = _CLASS_OBJECT.__new__(_CLASS_OBJECT)
- (<Object>obj).chandle = result.v_obj
- return obj
+ else:
+ # object is not found in registered entry
+ # in this case we need to report an warning
+
+ from .utils import prototype_py
+
Review Comment:
i feel we do not need exec to create a new type, instead we can use `type`
function?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]