I'm working on getting Bun ready for Zig 0.14. We have an unmanaged container for borrowed subslices of strings, which uses one of the bits in the len to store whether it needs to be freed. In debug builds, CowSlice also stores an allocator so that, even though it is unmanaged, it can make sure you don't try to free it with the wrong allocator.
However, I understand that comparing the ptr field on an Allocator is unsound because some implementations set it to undefined. I see that this approach was maintained in #22691, instead of the counter-proposal to set unneeded ptr fields to null instead. We can of course compare only the vtable field instead, but that makes the safety check weaker, because it would consider two different instances of the same kind of allocator to be equal (e.g. two arena or fixed buffer allocators). I don't see a way to provide the strongest possible safety guarantees without sometimes comparing undefined pointers.
This safety check seems like it might be useful for std's unmanaged containers as well. Is this a use case that should be supported?
I'm working on getting Bun ready for Zig 0.14. We have an unmanaged container for borrowed subslices of strings, which uses one of the bits in the
lento store whether it needs to be freed. In debug builds,CowSlicealso stores an allocator so that, even though it is unmanaged, it can make sure you don't try to free it with the wrong allocator.However, I understand that comparing the
ptrfield on an Allocator is unsound because some implementations set it toundefined. I see that this approach was maintained in #22691, instead of the counter-proposal to set unneededptrfields tonullinstead. We can of course compare only thevtablefield instead, but that makes the safety check weaker, because it would consider two different instances of the same kind of allocator to be equal (e.g. two arena or fixed buffer allocators). I don't see a way to provide the strongest possible safety guarantees without sometimes comparingundefinedpointers.This safety check seems like it might be useful for std's unmanaged containers as well. Is this a use case that should be supported?