shared/strbuf: expose read only value for "allocated" buffer size

We cannot actually mark the field as const, because then you could no
longer initialize a variable that contains a NMStrBuf with designated
initializers.

We also want to keep the "_allocated" alias, for the only places that
are allowed to mutate the field: inside "nm-str-buf.h". Add an alias
for that field, that is allowed to be read, provided that you don't
modify it!

The alternative would be a nm_str_buf_get_allocated() accessor, but
that seems unnecessarily verbose when you could just access the field.
This commit is contained in:
Thomas Haller 2020-04-06 10:43:07 +02:00
parent 7ff170a28f
commit 64894182ca

View file

@ -16,7 +16,10 @@ typedef struct _NMStrBuf {
/*const*/ gsize len;
gsize _len;
};
gsize _allocated;
union {
/*const*/ gsize allocated;
gsize _allocated;
};
bool _do_bzero_mem;
} NMStrBuf;