getty-zig / getty

A (de)serialization framework for Zig
https://getty.so
MIT License
183 stars 14 forks source link

de: Add allocation check functions to aggregate access interfaces #132

Closed polykernel closed 1 year ago

polykernel commented 1 year ago

This commit implements proposal https://github.com/getty-zig/getty/issues/127 to adds allocation check functions for aggregate access interfaces, namingly the functions isElementAllocated, isValueAllocated, isPayloadAllocated to the SeqAccess, MapAccess and VariantAccess interfaces respectively. This allows checking the storage location of a value deserialized from access methods (e.g., nextKey) and makes it possible to conditionally free the value only if it is allocated on the heap. Thus, eliminating the need to unconditionally free values which in some cases force an allocator to be passed for deserialization even if no allocation would take place, contravening the principle of least privilege.

closes https://github.com/getty-zig/getty/issues/127