-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
It would be great if the documentation of MallocSizeOfOps.malloc_size_of would explicitly list the safety requirements of this unsafe function. This would make clippy happy (see the missing_safety_doc lint) and would also make it easier to audit calls into the function (e.g. when auditing recent smallvec changes here).
It's a bit hard to reverse-engineer the safety requirements, because it is impossible to look at all the impls of the MallocSizeOfOps trait, but I have some guesses below as a tentative starting point:
- Maybe:
ptrneeds to be point to memory currently allocated by the allocator associated with the givenimplofMallocSizeOfOps?- But if so, then it may mean that
shallow_size_ofinsmallvecshould beunsafe(because its safety requirement should require thatopscorresponds to the right allocator).
- But if so, then it may mean that
- Maybe:
ptrjust needs to be valid for reading?- But if so, then it would mean that before looking up allocator-specific metadata (e.g. stored in bytes preceding the allocation) the implementation of
malloc_size_ofwould need to somehow check if the pointer points to "currently allocated memory". And if so, then it should also be able to check ifptris valid for reading.
- But if so, then it would mean that before looking up allocator-specific metadata (e.g. stored in bytes preceding the allocation) the implementation of
The guesses above don't look quite right to me. I feel that the real safety requirements are different from the guesses above. I am probably missing an understanding of how this API is intended to work. Help please? :-)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels