diff -r 56c62780582e -r 4a06fd63909a src/cx/map.h --- a/src/cx/map.h Thu Feb 23 18:58:15 2023 +0100 +++ b/src/cx/map.h Thu Feb 23 21:42:46 2023 +0100 @@ -112,7 +112,7 @@ /** * Removes an element. */ - __attribute__((__nonnull__, __warn_unused_result__)) + __attribute__((__nonnull__)) void *(*remove)( CxMap *map, CxHashKey key @@ -259,13 +259,38 @@ /** * Removes a key/value-pair from the map by using the key. * + * If this map is storing pointers, you should make sure that the map + * is not the last location where this pointer is stored. + * Otherwise, use cxMapRemoveAndGet() to retrieve the pointer while + * removing it from the map. + * * @param map the map * @param key the key - * @return if this map is storing pointers, the removed value, \c NULL otherwise + * @see cxMapRemoveAndGet() + */ +__attribute__((__nonnull__)) +static inline void cxMapRemove( + CxMap *map, + CxHashKey key +) { + (void) map->cl->remove(map, key); +} + +/** + * Removes a key/value-pair from the map by using the key. + * + * This function should only be used when the map is storing pointers, + * in order to retrieve the pointer you are about to remove. + * In any other case, cxMapRemove() is sufficient. + * + * @param map the map + * @param key the key + * @return the stored pointer or \c NULL if either the key is not present + * in the map or the map is not storing pointers * @see cxMapStorePointers() */ __attribute__((__nonnull__, __warn_unused_result__)) -static inline void *cxMapRemove( +static inline void *cxMapRemoveAndGet( CxMap *map, CxHashKey key ) {