src/cx/map.h

changeset 985
68754c7de906
parent 984
e8f354a25ac8
--- a/src/cx/map.h	Thu Nov 07 20:22:56 2024 +0100
+++ b/src/cx/map.h	Thu Nov 07 22:46:58 2024 +0100
@@ -89,19 +89,19 @@
     /**
      * Deallocates the entire memory.
      */
-    __attribute__((__nonnull__))
+    cx_attr_nonnull
     void (*destructor)(struct cx_map_s *map);
 
     /**
      * Removes all elements.
      */
-    __attribute__((__nonnull__))
+    cx_attr_nonnull
     void (*clear)(struct cx_map_s *map);
 
     /**
      * Add or overwrite an element.
      */
-    __attribute__((__nonnull__))
+    cx_attr_nonnull
     int (*put)(
             CxMap *map,
             CxHashKey key,
@@ -111,7 +111,8 @@
     /**
      * Returns an element.
      */
-    __attribute__((__nonnull__, __warn_unused_result__))
+    cx_attr_nonnull
+    cx_attr_nodiscard
     void *(*get)(
             const CxMap *map,
             CxHashKey key
@@ -120,7 +121,7 @@
     /**
      * Removes an element.
      */
-    __attribute__((__nonnull__))
+    cx_attr_nonnull
     void *(*remove)(
             CxMap *map,
             CxHashKey key,
@@ -130,7 +131,8 @@
     /**
      * Creates an iterator for this map.
      */
-    __attribute__((__nonnull__, __warn_unused_result__))
+    cx_attr_nonnull
+    cx_attr_nodiscard
     CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
 };
 
@@ -151,7 +153,7 @@
 /**
  * A shared instance of an empty map.
  *
- * Writing to that map is undefined.
+ * Writing to that map is not allowed.
  */
 extern CxMap *const cxEmptyMap;
 
@@ -164,7 +166,7 @@
  * @param map the map
  * @see cxMapStorePointers()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapStoreObjects(CxMap *map) {
     map->collection.store_pointer = false;
 }
@@ -181,7 +183,7 @@
  * @param map the map
  * @see cxMapStoreObjects()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapStorePointers(CxMap *map) {
     map->collection.store_pointer = true;
     map->collection.elem_size = sizeof(void *);
@@ -194,7 +196,7 @@
  * @return true, if this map is storing pointers
  * @see cxMapStorePointers()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline bool cxMapIsStoringPointers(const CxMap *map) {
     return map->collection.store_pointer;
 }
@@ -215,7 +217,7 @@
  *
  * @param map the map to be cleared
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapClear(CxMap *map) {
     map->cl->clear(map);
 }
@@ -226,7 +228,7 @@
  * @param map the map
  * @return the number of stored elements
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline size_t cxMapSize(const CxMap *map) {
     return map->collection.size;
 }
@@ -243,7 +245,8 @@
  * @param map the map to create the iterator for
  * @return an iterator for the currently stored values
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline CxIterator cxMapIteratorValues(const CxMap *map) {
     return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
 }
@@ -259,7 +262,8 @@
  * @param map the map to create the iterator for
  * @return an iterator for the currently stored keys
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
     return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
 }
@@ -277,7 +281,8 @@
  * @see cxMapIteratorKeys()
  * @see cxMapIteratorValues()
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline CxIterator cxMapIterator(const CxMap *map) {
     return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
 }
@@ -292,7 +297,8 @@
  * @param map the map to create the iterator for
  * @return an iterator for the currently stored values
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 CxIterator cxMapMutIteratorValues(CxMap *map);
 
 /**
@@ -306,7 +312,8 @@
  * @param map the map to create the iterator for
  * @return an iterator for the currently stored keys
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 CxIterator cxMapMutIteratorKeys(CxMap *map);
 
 /**
@@ -322,7 +329,8 @@
  * @see cxMapMutIteratorKeys()
  * @see cxMapMutIteratorValues()
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 CxIterator cxMapMutIterator(CxMap *map);
 
 #ifdef __cplusplus
@@ -336,7 +344,7 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline int cxMapPut(
         CxMap *map,
         CxHashKey const &key,
@@ -354,7 +362,7 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline int cxMapPut(
         CxMap *map,
         cxstring const &key,
@@ -371,7 +379,7 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline int cxMapPut(
         CxMap *map,
         cxmutstr const &key,
@@ -388,7 +396,8 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_cstr_arg(2)
 static inline int cxMapPut(
         CxMap *map,
         const char *key,
@@ -404,7 +413,8 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cxMapGet(
         const CxMap *map,
         CxHashKey const &key
@@ -419,7 +429,8 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cxMapGet(
         const CxMap *map,
         cxstring const &key
@@ -434,7 +445,8 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cxMapGet(
         const CxMap *map,
         cxmutstr const &key
@@ -449,7 +461,9 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
+cx_attr_cstr_arg(2)
 static inline void *cxMapGet(
         const CxMap *map,
         const char *key
@@ -471,7 +485,7 @@
  * @see cxMapRemoveAndGet()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapRemove(
         CxMap *map,
         CxHashKey const &key
@@ -493,7 +507,7 @@
  * @see cxMapRemoveAndGet()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapRemove(
         CxMap *map,
         cxstring const &key
@@ -515,7 +529,7 @@
  * @see cxMapRemoveAndGet()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapRemove(
         CxMap *map,
         cxmutstr const &key
@@ -537,7 +551,8 @@
  * @see cxMapRemoveAndGet()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_cstr_arg(2)
 static inline void cxMapRemove(
         CxMap *map,
         const char *key
@@ -559,7 +574,7 @@
  * @see cxMapRemove()
  * @see cxMapRemoveAndGet()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapDetach(
         CxMap *map,
         CxHashKey const &key
@@ -581,7 +596,7 @@
  * @see cxMapRemove()
  * @see cxMapRemoveAndGet()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapDetach(
         CxMap *map,
         cxstring const &key
@@ -603,7 +618,7 @@
  * @see cxMapRemove()
  * @see cxMapRemoveAndGet()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cxMapDetach(
         CxMap *map,
         cxmutstr const &key
@@ -625,7 +640,8 @@
  * @see cxMapRemove()
  * @see cxMapRemoveAndGet()
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_cstr_arg(2)
 static inline void cxMapDetach(
         CxMap *map,
         const char *key
@@ -652,7 +668,8 @@
  * @see cxMapStorePointers()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cxMapRemoveAndGet(
         CxMap *map,
         CxHashKey key
@@ -679,7 +696,8 @@
  * @see cxMapStorePointers()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cxMapRemoveAndGet(
         CxMap *map,
         cxstring key
@@ -706,7 +724,8 @@
  * @see cxMapStorePointers()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cxMapRemoveAndGet(
         CxMap *map,
         cxmutstr key
@@ -733,7 +752,9 @@
  * @see cxMapStorePointers()
  * @see cxMapDetach()
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
+cx_attr_cstr_arg(2)
 static inline void *cxMapRemoveAndGet(
         CxMap *map,
         const char *key
@@ -751,7 +772,7 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline int cx_map_put(
         CxMap *map,
         CxHashKey key,
@@ -768,7 +789,7 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline int cx_map_put_cxstr(
         CxMap *map,
         cxstring key,
@@ -785,7 +806,7 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline int cx_map_put_mustr(
         CxMap *map,
         cxmutstr key,
@@ -802,7 +823,8 @@
  * @param value the value
  * @return 0 on success, non-zero value on failure
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_cstr_arg(2)
 static inline int cx_map_put_str(
         CxMap *map,
         const char *key,
@@ -834,7 +856,8 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cx_map_get(
         const CxMap *map,
         CxHashKey key
@@ -849,7 +872,8 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cx_map_get_cxstr(
         const CxMap *map,
         cxstring key
@@ -864,7 +888,8 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cx_map_get_mustr(
         const CxMap *map,
         cxmutstr key
@@ -879,7 +904,9 @@
  * @param key the key
  * @return the value
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
+cx_attr_cstr_arg(2)
 static inline void *cx_map_get_str(
         const CxMap *map,
         const char *key
@@ -908,7 +935,7 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cx_map_remove(
         CxMap *map,
         CxHashKey key
@@ -922,7 +949,7 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cx_map_remove_cxstr(
         CxMap *map,
         cxstring key
@@ -936,7 +963,7 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cx_map_remove_mustr(
         CxMap *map,
         cxmutstr key
@@ -950,7 +977,8 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_cstr_arg(2)
 static inline void cx_map_remove_str(
         CxMap *map,
         const char *key
@@ -987,7 +1015,7 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cx_map_detach(
         CxMap *map,
         CxHashKey key
@@ -1002,7 +1030,7 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cx_map_detach_cxstr(
         CxMap *map,
         cxstring key
@@ -1017,7 +1045,7 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 static inline void cx_map_detach_mustr(
         CxMap *map,
         cxmutstr key
@@ -1032,7 +1060,8 @@
  * @param map the map
  * @param key the key
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_cstr_arg(2)
 static inline void cx_map_detach_str(
         CxMap *map,
         const char *key
@@ -1070,7 +1099,8 @@
  * @return the stored pointer or \c NULL if either the key is not present
  * in the map or the map is not storing pointers
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cx_map_remove_and_get(
         CxMap *map,
         CxHashKey key
@@ -1086,7 +1116,8 @@
  * @return the stored pointer or \c NULL if either the key is not present
  * in the map or the map is not storing pointers
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cx_map_remove_and_get_cxstr(
         CxMap *map,
         cxstring key
@@ -1102,7 +1133,8 @@
  * @return the stored pointer or \c NULL if either the key is not present
  * in the map or the map is not storing pointers
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
 static inline void *cx_map_remove_and_get_mustr(
         CxMap *map,
         cxmutstr key
@@ -1118,7 +1150,9 @@
  * @return the stored pointer or \c NULL if either the key is not present
  * in the map or the map is not storing pointers
  */
-__attribute__((__nonnull__, __warn_unused_result__))
+cx_attr_nonnull
+cx_attr_nodiscard
+cx_attr_cstr_arg(2)
 static inline void *cx_map_remove_and_get_str(
         CxMap *map,
         const char *key

mercurial