mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-03-01 08:12:23 +07:00
hashmap: return NULL from destructor
We _always_ return NULL from destructors to allow direct assignments to the variable holding the object. Especially on hashmaps, which treat NULL as empty hashmap, this is pretty neat. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
This commit is contained in:
parent
461300d949
commit
c9853d8cda
@ -864,38 +864,41 @@ static void hashmap_free_no_clear(HashmapBase *h) {
|
||||
free(h);
|
||||
}
|
||||
|
||||
void internal_hashmap_free(HashmapBase *h) {
|
||||
HashmapBase *internal_hashmap_free(HashmapBase *h) {
|
||||
|
||||
/* Free the hashmap, but nothing in it */
|
||||
|
||||
if (!h)
|
||||
return;
|
||||
if (h) {
|
||||
internal_hashmap_clear(h);
|
||||
hashmap_free_no_clear(h);
|
||||
}
|
||||
|
||||
internal_hashmap_clear(h);
|
||||
hashmap_free_no_clear(h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void internal_hashmap_free_free(HashmapBase *h) {
|
||||
HashmapBase *internal_hashmap_free_free(HashmapBase *h) {
|
||||
|
||||
/* Free the hashmap and all data objects in it, but not the
|
||||
* keys */
|
||||
|
||||
if (!h)
|
||||
return;
|
||||
if (h) {
|
||||
internal_hashmap_clear_free(h);
|
||||
hashmap_free_no_clear(h);
|
||||
}
|
||||
|
||||
internal_hashmap_clear_free(h);
|
||||
hashmap_free_no_clear(h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void hashmap_free_free_free(Hashmap *h) {
|
||||
Hashmap *hashmap_free_free_free(Hashmap *h) {
|
||||
|
||||
/* Free the hashmap and all data and key objects in it */
|
||||
|
||||
if (!h)
|
||||
return;
|
||||
if (h) {
|
||||
hashmap_clear_free_free(h);
|
||||
hashmap_free_no_clear(HASHMAP_BASE(h));
|
||||
}
|
||||
|
||||
hashmap_clear_free_free(h);
|
||||
hashmap_free_no_clear(HASHMAP_BASE(h));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void internal_hashmap_clear(HashmapBase *h) {
|
||||
|
@ -144,25 +144,25 @@ OrderedHashmap *internal_ordered_hashmap_new(const struct hash_ops *hash_ops HA
|
||||
#define hashmap_new(ops) internal_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
#define ordered_hashmap_new(ops) internal_ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
|
||||
|
||||
void internal_hashmap_free(HashmapBase *h);
|
||||
static inline void hashmap_free(Hashmap *h) {
|
||||
internal_hashmap_free(HASHMAP_BASE(h));
|
||||
HashmapBase *internal_hashmap_free(HashmapBase *h);
|
||||
static inline Hashmap *hashmap_free(Hashmap *h) {
|
||||
return (void*)internal_hashmap_free(HASHMAP_BASE(h));
|
||||
}
|
||||
static inline void ordered_hashmap_free(OrderedHashmap *h) {
|
||||
internal_hashmap_free(HASHMAP_BASE(h));
|
||||
static inline OrderedHashmap *ordered_hashmap_free(OrderedHashmap *h) {
|
||||
return (void*)internal_hashmap_free(HASHMAP_BASE(h));
|
||||
}
|
||||
|
||||
void internal_hashmap_free_free(HashmapBase *h);
|
||||
static inline void hashmap_free_free(Hashmap *h) {
|
||||
internal_hashmap_free_free(HASHMAP_BASE(h));
|
||||
HashmapBase *internal_hashmap_free_free(HashmapBase *h);
|
||||
static inline Hashmap *hashmap_free_free(Hashmap *h) {
|
||||
return (void*)internal_hashmap_free_free(HASHMAP_BASE(h));
|
||||
}
|
||||
static inline void ordered_hashmap_free_free(OrderedHashmap *h) {
|
||||
internal_hashmap_free_free(HASHMAP_BASE(h));
|
||||
static inline OrderedHashmap *ordered_hashmap_free_free(OrderedHashmap *h) {
|
||||
return (void*)internal_hashmap_free_free(HASHMAP_BASE(h));
|
||||
}
|
||||
|
||||
void hashmap_free_free_free(Hashmap *h);
|
||||
static inline void ordered_hashmap_free_free_free(OrderedHashmap *h) {
|
||||
hashmap_free_free_free(PLAIN_HASHMAP(h));
|
||||
Hashmap *hashmap_free_free_free(Hashmap *h);
|
||||
static inline OrderedHashmap *ordered_hashmap_free_free_free(OrderedHashmap *h) {
|
||||
return (void*)hashmap_free_free_free(PLAIN_HASHMAP(h));
|
||||
}
|
||||
|
||||
HashmapBase *internal_hashmap_copy(HashmapBase *h);
|
||||
|
Loading…
Reference in New Issue
Block a user