gemini-code-assist[bot] commented on code in PR #77:
URL: https://github.com/apache/tvm-ffi/pull/77#discussion_r2393099588
##########
include/tvm/ffi/memory.h:
##########
@@ -115,6 +115,7 @@ class ObjAllocatorBase {
TVMFFIObject* ffi_ptr = details::ObjectUnsafe::GetHeader(ptr);
ffi_ptr->combined_ref_count = kCombinedRefCountBothOne;
ffi_ptr->type_index = T::RuntimeTypeIndex();
+ ffi_ptr->__padding = 0;
Review Comment:

This change highlights existing code duplication for header initialization
between `MakeObjectPtr` and `MakeArrayObjectPtr` (at line 140). To improve
maintainability, consider extracting this logic into a private helper function.
When refactoring, you could also make the initialization more robust. To
fully guarantee deterministic memory as intended, it's safer to zero out the
entire `TVMFFIObject` struct with `std::memset` before setting the fields. This
protects against any compiler-inserted padding, not just the explicit
`__padding` field.
An implementation could look like this:
```cpp
private:
template <typename Handler>
static void InitHeader(Object* ptr, int32_t type_index) {
TVMFFIObject* ffi_ptr = details::ObjectUnsafe::GetHeader(ptr);
std::memset(ffi_ptr, 0, sizeof(*ffi_ptr));
ffi_ptr->combined_ref_count = kCombinedRefCountBothOne;
ffi_ptr->type_index = type_index;
ffi_ptr->deleter = Handler::Deleter();
}
```
##########
include/tvm/ffi/memory.h:
##########
@@ -136,6 +137,7 @@ class ObjAllocatorBase {
TVMFFIObject* ffi_ptr = details::ObjectUnsafe::GetHeader(ptr);
ffi_ptr->combined_ref_count = kCombinedRefCountBothOne;
ffi_ptr->type_index = ArrayType::RuntimeTypeIndex();
+ ffi_ptr->__padding = 0;
Review Comment:

As mentioned in the comment for `MakeObjectPtr`, this change adds to
duplicated code. This logic should be consolidated into a shared helper
function to improve maintainability.
--
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]