cyx-6 commented on code in PR #593:
URL: https://github.com/apache/tvm-ffi/pull/593#discussion_r3585777922
##########
src/ffi/extra/dataclass.cc:
##########
@@ -2041,16 +2044,20 @@ void PyClassRegisterTypeAttrColumns(int32_t type_index,
int32_t total_size) {
RegisterFFIInit(type_index);
// Step 2. Register `__ffi_new__`
Function new_fn = Function::FromTyped([type_index, total_size]() ->
ObjectRef {
- void* obj_ptr = std::calloc(1, static_cast<size_t>(total_size));
- if (!obj_ptr) {
- TVM_FFI_THROW(RuntimeError) << "Failed to allocate " << total_size << "
bytes for type "
- << TypeIndexToTypeKey(type_index);
- }
+ // Route through the custom-allocator registry so the prepended
+ // TVMFFIObjectAllocHeader is in place for PyClassDeleter's Weak
+ // branch. Then memset to zero-init the T payload (mirrors the
+ // original calloc-based path).
+ size_t alloc_size = static_cast<size_t>(total_size);
+ TVMFFICustomAllocator* alloc = TVMFFIGetCustomAllocator();
+ void* obj_ptr =
+ alloc->allocate(alloc_size, alignof(::std::max_align_t), type_index,
alloc->context);
+ std::memset(obj_ptr, 0, alloc_size);
Review Comment:
yes and added
--
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]