Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Build log module as C++.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Jan 2019 14:09:36 +0000 (15:09 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Jan 2019 17:37:06 +0000 (18:37 +0100)
The goal is to use C++ mutex.

src/xbt/log.cpp [moved from src/xbt/log.c with 98% similarity]
src/xbt/log_private.hpp [moved from src/xbt/log_private.h with 100% similarity]
src/xbt/xbt_log_appender_file.cpp [moved from src/xbt/xbt_log_appender_file.c with 95% similarity]
src/xbt/xbt_log_layout_format.cpp [moved from src/xbt/xbt_log_layout_format.c with 98% similarity]
src/xbt/xbt_log_layout_simple.cpp [moved from src/xbt/xbt_log_layout_simple.c with 98% similarity]
tools/cmake/DefinePackages.cmake
tools/cmake/Flags.cmake

similarity index 98%
rename from src/xbt/log.c
rename to src/xbt/log.cpp
index 009c80b..e4a2aaa 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "src/xbt_modinter.h"
 
-#include "src/xbt/log_private.h"
+#include "src/xbt/log_private.hpp"
 #include "xbt/asserts.h"
 #include "xbt/dynar.h"
 #include "xbt/ex.h"
@@ -181,7 +181,7 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
   xbt_log_category_t cat = ev->cat;
 
   xbt_assert(ev->priority >= 0, "Negative logging priority naturally forbidden");
-  xbt_assert(ev->priority < sizeof(xbt_log_priority_names) / sizeof(xbt_log_priority_names[0]),
+  xbt_assert(static_cast<size_t>(ev->priority) < sizeof(xbt_log_priority_names)/sizeof(xbt_log_priority_names[0]),
              "Priority %d is greater than the biggest allowed value", ev->priority);
 
   while (1) {
@@ -204,7 +204,7 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
 
         /* The static buffer was too small, use a dynamically expanded one */
         ev->buffer_size = XBT_LOG_DYNAMIC_BUFFER_SIZE;
-        ev->buffer      = xbt_malloc(ev->buffer_size);
+        ev->buffer      = static_cast<char*>(xbt_malloc(ev->buffer_size));
         while (1) {
           va_start(ev->ap, fmt);
           done = cat->layout->do_layout(cat->layout, ev, fmt);
@@ -212,7 +212,7 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
           if (done)
             break; /* Got it */
           ev->buffer_size *= 2;
-          ev->buffer = xbt_realloc(ev->buffer, ev->buffer_size);
+          ev->buffer = static_cast<char*>(xbt_realloc(ev->buffer, ev->buffer_size));
         }
         appender->do_append(appender, ev->buffer);
         xbt_free(ev->buffer);
similarity index 95%
rename from src/xbt/xbt_log_appender_file.c
rename to src/xbt/xbt_log_appender_file.cpp
index f31c73b..7d9313e 100644 (file)
@@ -7,7 +7,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/internal_config.h"
-#include "src/xbt/log_private.h"
+#include "src/xbt/log_private.hpp"
 #include "xbt/sysdep.h"
 #include <errno.h>
 #include <stdio.h>
@@ -19,7 +19,7 @@ static void append_file(xbt_log_appender_t this_, char *str) {
 
 static void free_(xbt_log_appender_t this_) {
   if (this_->data != stderr)
-    fclose(this_->data);
+    fclose(static_cast<FILE*>(this_->data));
 }
 
 xbt_log_appender_t xbt_log_appender_file_new(char *arg) {
@@ -94,7 +94,7 @@ static void append2_file(xbt_log_appender_t this_, char *str) {
 
 static void free_append2_(xbt_log_appender_t this_)
 {
-  xbt_log_append2_file_t data = this_->data;
+  xbt_log_append2_file_t data = static_cast<xbt_log_append2_file_t>(this_->data);
   if (data->file)
     fclose(data->file);
   xbt_free(data->filename);
similarity index 98%
rename from src/xbt/xbt_log_layout_format.c
rename to src/xbt/xbt_log_layout_format.cpp
index 7726483..3243b77 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "simgrid/host.h"
 #include "simgrid/msg.h" /* MSG_get_clock */
-#include "src/xbt/log_private.h"
+#include "src/xbt/log_private.hpp"
 #include "xbt/sysdep.h"
 #include <stdio.h>
 
@@ -80,7 +80,7 @@ static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, co
   int precision = -1;
   int length = -1;
 
-  for (char* q = l->data ; *q != '\0' ; q++) {
+  for (char* q = static_cast<char*>(l->data) ; *q != '\0' ; q++) {
     if (*q == '%') {
       q++;
       do {
similarity index 98%
rename from src/xbt/xbt_log_layout_simple.c
rename to src/xbt/xbt_log_layout_simple.cpp
index fbe3c80..f4179ae 100644 (file)
@@ -6,7 +6,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/sysdep.h"
-#include "src/xbt/log_private.h"
+#include "src/xbt/log_private.hpp"
 
 #include "simgrid/host.h" /* sg_host_self_get_name */
 #include "simgrid/msg.h"  /* MSG_get_clock */
index 19738ea..584ff4c 100644 (file)
@@ -67,7 +67,7 @@ set(EXTRA_DIST
   src/xbt/automaton/parserPromela.tab.hacc
   src/xbt/automaton/parserPromela.yacc
   src/xbt/dict_private.h
-  src/xbt/log_private.h
+  src/xbt/log_private.hpp
   src/xbt/mallocator_private.h
 
   src/xbt/mmalloc/mfree.c
@@ -278,7 +278,7 @@ set(XBT_SRC
   src/xbt/dynar.cpp
   src/xbt/exception.cpp
   src/xbt/graph.c
-  src/xbt/log.c
+  src/xbt/log.cpp
   src/xbt/mallocator.c
   src/xbt/memory_map.cpp
   src/xbt/memory_map.hpp
@@ -286,9 +286,9 @@ set(XBT_SRC
   src/xbt/parmap.cpp
   src/xbt/snprintf.c
   src/xbt/string.cpp
-  src/xbt/xbt_log_appender_file.c
-  src/xbt/xbt_log_layout_format.c
-  src/xbt/xbt_log_layout_simple.c
+  src/xbt/xbt_log_appender_file.cpp
+  src/xbt/xbt_log_layout_format.cpp
+  src/xbt/xbt_log_layout_simple.cpp
   src/xbt/xbt_main.cpp
   src/xbt/xbt_os_file.cpp
   src/xbt/xbt_os_synchro.cpp
index b9a1b61..653f50d 100644 (file)
@@ -152,8 +152,8 @@ if(enable_model-checking AND enable_compile_optimizations)
   foreach(s
       src/kernel/lmm/fair_bottleneck.cpp src/kernel/lmm/lagrange.cpp src/kernel/lmm/maxmin.cpp
       src/xbt/mmalloc/mm.c
-      src/xbt/log.c src/xbt/xbt_log_appender_file.c
-      src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
+      src/xbt/log.cpp src/xbt/xbt_log_appender_file.cpp
+      src/xbt/xbt_log_layout_format.cpp src/xbt/xbt_log_layout_simple.cpp
       src/xbt/dict.cpp src/xbt/dict_elm.c src/xbt/dict_cursor.c
       src/xbt/dynar.cpp
       src/xbt/xbt_str.cpp src/xbt/snprintf.c