Buffers provide the ability to free the control block but preserve and
return the previously controlled data to the caller: buffer_free_without_data().
As wrapped buffers, strings also have this functionality: str_free_without_data().
(They have to do that, as their buffer implementation is encapsulated away
out of sight to the str.h user.)
Arrays, also wrapped buffers, are missing this capability under the 'array'
name, you have to use the buffer function call, which involves diving into
the guts of the array implementation (because arrays do not hide their
implementation like strings do), and also sacrifices array's type safety.
With this inline helper, it should be simple, obvious, clean and safe.
Signed-off-by: Phil Carmody <phil@dovecot.fi>
#define array_free(array) \
array_free_i(&(array)->arr)
+static inline void * ATTR_WARN_UNUSED_RESULT
+array_free_without_data_i(struct array *array)
+{
+ return buffer_free_without_data(&array->buffer);
+}
+#define array_free_without_data(array) \
+ ARRAY_TYPE_CAST_MODIFIABLE(array)array_free_without_data_i(&(array)->arr)
+
static inline bool
array_is_created_i(const struct array *array)
{