Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in dicts and dynars.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Dec 2019 16:59:21 +0000 (17:59 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Dec 2019 17:24:18 +0000 (18:24 +0100)
include/xbt/dict.h
include/xbt/dynar.h
src/xbt/dict_cursor.c
src/xbt/dict_elm.c
src/xbt/dict_private.h

index e36d2b9..73b6e62 100644 (file)
@@ -45,6 +45,7 @@ SG_BEGIN_DECL
 
 /** @brief Dictionary data type (opaque structure) */
 typedef struct s_xbt_dict *xbt_dict_t;
+typedef const struct s_xbt_dict* const_xbt_dict_t;
 typedef struct s_xbt_dictelm *xbt_dictelm_t;
 typedef struct s_xbt_dictelm {
   char *key;
@@ -124,8 +125,10 @@ struct s_xbt_dict_cursor {
 
 /** @brief Cursor on dictionaries (opaque type) */
 typedef struct s_xbt_dict_cursor *xbt_dict_cursor_t;
+typedef const struct s_xbt_dict_cursor* const_xbt_dict_cursor_t;
 
-static inline xbt_dictelm_t xbt_dict_cursor_get_elm(xbt_dict_cursor_t cursor) {
+static inline xbt_dictelm_t xbt_dict_cursor_get_elm(const_xbt_dict_cursor_t cursor)
+{
   return cursor->current;
 }
 
index 46fa9c8..c90aa68 100644 (file)
@@ -63,6 +63,7 @@ SG_BEGIN_DECL
  */
 /** @brief Dynar data type (opaque type) */
 typedef struct xbt_dynar_s *xbt_dynar_t;
+typedef const struct xbt_dynar_s* const_xbt_dynar_t;
 
 XBT_PUBLIC xbt_dynar_t xbt_dynar_new(const unsigned long elm_size, void_f_pvoid_t const free_f);
 XBT_PUBLIC void xbt_dynar_init(xbt_dynar_t dynar, const unsigned long elmsize, void_f_pvoid_t const free_f);
@@ -201,7 +202,7 @@ typedef struct xbt_dynar_s {
   void_f_pvoid_t free_f;
 } s_xbt_dynar_t;
 
-static inline int _xbt_dynar_cursor_get(const xbt_dynar_t dynar, unsigned int idx, void* const dst)
+static inline int _xbt_dynar_cursor_get(const_xbt_dynar_t dynar, unsigned int idx, void* const dst)
 {
   if (!dynar) /* iterating over a NULL dynar is a no-op */
     return 0;
index ca96b1c..b364d32 100644 (file)
@@ -45,7 +45,7 @@ inline void xbt_dict_cursor_free(xbt_dict_cursor_t * cursor)
 /*
  * Sanity check to see if the head contains something
  */
-static inline void __cursor_not_null(xbt_dict_cursor_t cursor)
+static inline void __cursor_not_null(const_xbt_dict_cursor_t cursor)
 {
   xbt_assert(cursor, "Null cursor");
 }
index 9c5bc3b..6295905 100644 (file)
@@ -25,7 +25,7 @@ xbt_dictelm_t xbt_dictelm_new(const char* key, int key_len, unsigned int hash_co
   return element;
 }
 
-void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element)
+void xbt_dictelm_free(const_xbt_dict_t dict, xbt_dictelm_t element)
 {
   if (element) {
     char *key = element->key;
@@ -40,7 +40,7 @@ void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element)
   }
 }
 
-void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element, void* data)
+void xbt_dictelm_set_data(const_xbt_dict_t dict, xbt_dictelm_t element, void* data)
 {
   void_f_pvoid_t free_f = dict->free_f;
   if (free_f && element->content)
index 15a5d69..6aa9c95 100644 (file)
@@ -34,8 +34,8 @@ XBT_PRIVATE void * dict_elm_mallocator_new_f(void);
 
 /*####[ Function prototypes ]################################################*/
 XBT_PRIVATE xbt_dictelm_t xbt_dictelm_new(const char* key, int key_len, unsigned int hash_code, void* content);
-XBT_PRIVATE void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element);
-XBT_PRIVATE void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element, void* data);
+XBT_PRIVATE void xbt_dictelm_free(const_xbt_dict_t dict, xbt_dictelm_t element);
+XBT_PRIVATE void xbt_dictelm_set_data(const_xbt_dict_t dict, xbt_dictelm_t element, void* data);
 
 SG_END_DECL