1.1 --- a/src/cx/map.h Thu Feb 23 18:58:15 2023 +0100 1.2 +++ b/src/cx/map.h Thu Feb 23 21:42:46 2023 +0100 1.3 @@ -112,7 +112,7 @@ 1.4 /** 1.5 * Removes an element. 1.6 */ 1.7 - __attribute__((__nonnull__, __warn_unused_result__)) 1.8 + __attribute__((__nonnull__)) 1.9 void *(*remove)( 1.10 CxMap *map, 1.11 CxHashKey key 1.12 @@ -259,13 +259,38 @@ 1.13 /** 1.14 * Removes a key/value-pair from the map by using the key. 1.15 * 1.16 + * If this map is storing pointers, you should make sure that the map 1.17 + * is not the last location where this pointer is stored. 1.18 + * Otherwise, use cxMapRemoveAndGet() to retrieve the pointer while 1.19 + * removing it from the map. 1.20 + * 1.21 * @param map the map 1.22 * @param key the key 1.23 - * @return if this map is storing pointers, the removed value, \c NULL otherwise 1.24 + * @see cxMapRemoveAndGet() 1.25 + */ 1.26 +__attribute__((__nonnull__)) 1.27 +static inline void cxMapRemove( 1.28 + CxMap *map, 1.29 + CxHashKey key 1.30 +) { 1.31 + (void) map->cl->remove(map, key); 1.32 +} 1.33 + 1.34 +/** 1.35 + * Removes a key/value-pair from the map by using the key. 1.36 + * 1.37 + * This function should only be used when the map is storing pointers, 1.38 + * in order to retrieve the pointer you are about to remove. 1.39 + * In any other case, cxMapRemove() is sufficient. 1.40 + * 1.41 + * @param map the map 1.42 + * @param key the key 1.43 + * @return the stored pointer or \c NULL if either the key is not present 1.44 + * in the map or the map is not storing pointers 1.45 * @see cxMapStorePointers() 1.46 */ 1.47 __attribute__((__nonnull__, __warn_unused_result__)) 1.48 -static inline void *cxMapRemove( 1.49 +static inline void *cxMapRemoveAndGet( 1.50 CxMap *map, 1.51 CxHashKey key 1.52 ) {