cyx-6 commented on code in PR #593:
URL: https://github.com/apache/tvm-ffi/pull/593#discussion_r3585762143
##########
include/tvm/ffi/object.h:
##########
@@ -1152,6 +1152,16 @@ struct ObjectUnsafe {
return const_cast<TVMFFIObject*>(&(src->header_));
}
+ /*!
+ * \brief Recover the TVMFFIObjectAllocHeader for a TVMFFIObject pointer.
+ * \param ptr The pointer to the space of the object.
+ * \return The header set by the allocator that produced ``ptr``.
+ */
+ TVM_FFI_INLINE static TVMFFIObjectAllocHeader*
GetObjectAllocHeaderFromPtr(void* ptr) {
+ return reinterpret_cast<TVMFFIObjectAllocHeader*>(static_cast<char*>(ptr) -
+
sizeof(TVMFFIObjectAllocHeader));
Review Comment:
I think yes, as `Object` is non-polymorphic (no vptr) and `header_` is its
first member at offset 0, so the header lands at `ptr - sizeof(header)` purely
by the allocator's placement contract, not C++ layout; added a note saying so.
--
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]