Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in src/xbt/log.cpp.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Dec 2019 23:11:53 +0000 (00:11 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Dec 2019 23:27:30 +0000 (00:27 +0100)
src/xbt/log.cpp
src/xbt/log_private.hpp
src/xbt/xbt_log_appender_file.cpp
src/xbt/xbt_log_layout_format.cpp
src/xbt/xbt_log_layout_simple.cpp

index 0060b27..ba62665 100644 (file)
@@ -123,7 +123,7 @@ void xbt_log_init(int *argc, char **argv)
   }
 }
 
-static void log_cat_exit(xbt_log_category_t cat)
+static void log_cat_exit(const s_xbt_log_category_t* cat)
 {
   xbt_log_category_t child;
 
@@ -340,7 +340,7 @@ void xbt_log_parent_set(xbt_log_category_t cat, xbt_log_category_t parent)
   cat->isThreshInherited = 1;
 }
 
-static void _set_inherited_thresholds(xbt_log_category_t cat)
+static void _set_inherited_thresholds(const s_xbt_log_category_t* cat)
 {
   xbt_log_category_t child = cat->firstChild;
 
@@ -631,7 +631,7 @@ static void xbt_log_help_categories_rec(xbt_log_category_t category, const std::
     cats.push_back(cat);
 
   std::sort(begin(cats), end(cats),
-            [](xbt_log_category_t a, xbt_log_category_t b) { return strcmp(a->name, b->name) < 0; });
+            [](const s_xbt_log_category_t* a, const s_xbt_log_category_t* b) { return strcmp(a->name, b->name) < 0; });
 
   for (auto const& cat : cats) {
     XBT_HELP("%s%s: %s", this_prefix.c_str(), cat->name, cat->description);
index 01eb726..888b23d 100644 (file)
@@ -8,14 +8,14 @@
 
 #include "xbt/log.h"
 struct xbt_log_appender_s {
-  void (*do_append) (xbt_log_appender_t this_appender, char *event);
-  void (*free_) (xbt_log_appender_t this_);
+  void (*do_append)(const s_xbt_log_appender_t* this_appender, const char* event);
+  void (*free_)(const s_xbt_log_appender_t* this_);
   void *data;
 };
 
 struct xbt_log_layout_s {
-  int (*do_layout) (xbt_log_layout_t l, xbt_log_event_t event, const char *fmt);
-  void (*free_) (xbt_log_layout_t l);
+  int (*do_layout)(const s_xbt_log_layout_t* l, xbt_log_event_t event, const char* fmt);
+  void (*free_)(const s_xbt_log_layout_t* l);
   void *data;
 };
 
index fbb0a88..669f2df 100644 (file)
 #include <cstdio>
 #include <cstring>
 
-static void append_file(xbt_log_appender_t this_, char *str) {
+static void append_file(const s_xbt_log_appender_t* this_, const char* str)
+{
   fputs(str, (FILE *) this_->data);
 }
 
-static void free_(xbt_log_appender_t this_)
+static void free_(const s_xbt_log_appender_t* this_)
 {
   fclose(static_cast<FILE*>(this_->data));
 }
@@ -86,20 +87,21 @@ static void open_append2_file(xbt_log_append2_file_t data){
   }
 }
 
-static void append2_file(xbt_log_appender_t this_, char *str) {
-   xbt_log_append2_file_t d=(xbt_log_append2_file_t) this_->data;
-   xbt_assert(d->file);
-   if(ftell(d->file)>=d->limit) {
-     open_append2_file(d);
-   }
-   fputs(str, d->file);
-   if(d->count<0){
-     fputs(APPEND2_END_TOKEN,d->file);
-     fseek(d->file,-((signed long)strlen(APPEND2_END_TOKEN)),SEEK_CUR);
-   }
+static void append2_file(const s_xbt_log_appender_t* this_, const char* str)
+{
+  xbt_log_append2_file_t d = (xbt_log_append2_file_t)this_->data;
+  xbt_assert(d->file);
+  if (ftell(d->file) >= d->limit) {
+    open_append2_file(d);
+  }
+  fputs(str, d->file);
+  if (d->count < 0) {
+    fputs(APPEND2_END_TOKEN, d->file);
+    fseek(d->file, -((signed long)strlen(APPEND2_END_TOKEN)), SEEK_CUR);
+  }
 }
 
-static void free_append2_(xbt_log_appender_t this_)
+static void free_append2_(const s_xbt_log_appender_t* this_)
 {
   xbt_log_append2_file_t data = static_cast<xbt_log_append2_file_t>(this_->data);
   if (data->file)
index 6a675dd..6825dda 100644 (file)
@@ -68,7 +68,7 @@ static constexpr const char* ERRMSG =
 #define show_int(data) show_it((data), "d")
 #define show_double(data) show_it((data), "f")
 
-static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char* msg_fmt)
+static int xbt_log_layout_format_doit(const s_xbt_log_layout_t* l, xbt_log_event_t ev, const char* msg_fmt)
 {
   char *p = ev->buffer;
   int rem_size = ev->buffer_size;
@@ -175,7 +175,7 @@ static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, co
   return 1;
 }
 
-static void xbt_log_layout_format_free(xbt_log_layout_t lay)
+static void xbt_log_layout_format_free(const s_xbt_log_layout_t* lay)
 {
   xbt_free(lay->data);
 }
index 6e4b400..20e00c8 100644 (file)
@@ -23,7 +23,7 @@ extern int xbt_log_no_loc;
     p += (len);                                                                                                        \
   } while (0)
 
-static int xbt_log_layout_simple_doit(xbt_log_layout_t, xbt_log_event_t ev, const char* fmt)
+static int xbt_log_layout_simple_doit(const s_xbt_log_layout_t*, xbt_log_event_t ev, const char* fmt)
 {
   char *p = ev->buffer;
   int rem_size = ev->buffer_size;