Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[XBT] NULL -> nullptr substitution
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Wed, 8 Jun 2016 21:20:59 +0000 (23:20 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 9 Jun 2016 07:40:52 +0000 (09:40 +0200)
I used the following command: (the '**' means recursion in ZSH)
sed -i -e 's/\([^_]\s*\)NULL/\1nullptr/g' src/**/*.cpp

We check for the underscore to avoid replacing MPI_*_NULL

src/xbt/config.cpp
src/xbt/memory_map.cpp
src/xbt/parmap.cpp

index 5903d94..6fc4d00 100644 (file)
@@ -28,7 +28,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
-XBT_EXPORT_NO_IMPORT(xbt_cfg_t) simgrid_config = NULL;
+XBT_EXPORT_NO_IMPORT(xbt_cfg_t) simgrid_config = nullptr;
 
 namespace simgrid {
 namespace config {
@@ -291,7 +291,7 @@ public:
               name,
               variable->getDescription().c_str(),
               variable->getTypeName(), variable, this);
-    xbt_dict_set(this->options, name, variable, NULL);
+    xbt_dict_set(this->options, name, variable, nullptr);
     variable->update();
     return variable;
   }
@@ -314,7 +314,7 @@ static void xbt_cfgelm_free(void *data)
 
 Config::Config() :
   options(xbt_dict_new_homogeneous(xbt_cfgelm_free)),
-  aliases(xbt_dict_new_homogeneous(NULL))
+  aliases(xbt_dict_new_homogeneous(nullptr))
 {}
 
 Config::~Config()
@@ -352,7 +352,7 @@ void Config::alias(const char* realname, const char* aliasname)
   xbt_assert(this->getDictElement(aliasname) == nullptr, "Alias '%s' already.", aliasname);
   xbt_dictelm_t element = this->getDictElement(realname);
   xbt_assert(element, "Cannot define an alias to the non-existing option '%s'.", realname);
-  xbt_dict_set(this->aliases, aliasname, element, NULL);
+  xbt_dict_set(this->aliases, aliasname, element, nullptr);
 }
 
 /** @brief Dump a config set for debuging purpose
@@ -363,9 +363,9 @@ void Config::alias(const char* realname, const char* aliasname)
 void Config::dump(const char *name, const char *indent)
 {
   xbt_dict_t dict = this->options;
-  xbt_dict_cursor_t cursor = NULL;
-  simgrid::config::ConfigurationElement* variable = NULL;
-  char *key = NULL;
+  xbt_dict_cursor_t cursor = nullptr;
+  simgrid::config::ConfigurationElement* variable = nullptr;
+  char *key = nullptr;
 
   if (name)
     printf("%s>> Dumping of the config set '%s':\n", indent, name);
@@ -389,7 +389,7 @@ void Config::showAliases()
   unsigned int dynar_cursor;
   xbt_dictelm_t dictel;
   char *name;
-  xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
+  xbt_dynar_t names = xbt_dynar_new(sizeof(char *), nullptr);
 
   xbt_dict_foreach(this->aliases, dict_cursor, name, dictel)
     xbt_dynar_push(names, &name);
@@ -406,7 +406,7 @@ void Config::help()
   unsigned int dynar_cursor;
   simgrid::config::ConfigurationElement* variable;
   char *name;
-  xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL);
+  xbt_dynar_t names = xbt_dynar_new(sizeof(char *), nullptr);
 
   xbt_dict_foreach(this->options, dict_cursor, name, variable)
     xbt_dynar_push(names, &name);
@@ -447,7 +447,7 @@ template<class T>
 XBT_PUBLIC(void) declareFlag(const char* name, const char* description,
   T value, std::function<void(const T&)> callback)
 {
-  if (simgrid_config == NULL)
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
   simgrid_config->registerOption<T>(
     name, description, std::move(value), std::move(callback));
@@ -480,21 +480,21 @@ void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg)
 void xbt_cfg_register_double(const char *name, double default_value,
   xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == NULL)
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
   simgrid_config->registerOption<double>(name, desc, default_value, cb_set);
 }
 
 void xbt_cfg_register_int(const char *name, int default_value,xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == NULL)
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
   simgrid_config->registerOption<int>(name, desc, default_value, cb_set);
 }
 
 void xbt_cfg_register_string(const char *name, const char *default_value, xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == NULL)
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
   simgrid_config->registerOption<std::string>(name, desc,
     default_value ? default_value : "", cb_set);
@@ -502,14 +502,14 @@ void xbt_cfg_register_string(const char *name, const char *default_value, xbt_cf
 
 void xbt_cfg_register_boolean(const char *name, const char*default_value,xbt_cfg_cb_t cb_set, const char *desc)
 {
-  if (simgrid_config == NULL)
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
   simgrid_config->registerOption<bool>(name, desc, simgrid::config::parseBool(default_value), cb_set);
 }
 
 void xbt_cfg_register_alias(const char *realname, const char *aliasname)
 {
-  if (simgrid_config == NULL)
+  if (simgrid_config == nullptr)
     simgrid_config = xbt_cfg_new();
   simgrid_config->alias(realname, aliasname);
 }
@@ -550,7 +550,7 @@ void xbt_cfg_set_parse(const char *options)
     }
     if (option - name == len) {
       XBT_DEBUG("Boundary=EOL");
-      option = NULL;            /* don't do next iteration */
+      option = nullptr;            /* don't do next iteration */
     } else {
       XBT_DEBUG("Boundary on '%c'. len=%d;option-name=%ld", *option, len, (long) (option - name));
       /* Pass the following blank chars */
@@ -560,7 +560,7 @@ void xbt_cfg_set_parse(const char *options)
         option++;
       }
       if (option - name == len - 1)
-        option = NULL;          /* don't do next iteration */
+        option = nullptr;          /* don't do next iteration */
     }
     XBT_DEBUG("parse now:'%s'; parse later:'%s'", name, option);
 
@@ -791,7 +791,7 @@ double xbt_cfg_get_double(const char *key)
  *
  * Returns the first value from the config set under the given name.
  * If there is more than one value, it will issue a warning.
- * Returns NULL if there is no value.
+ * Returns nullptr if there is no value.
  *
  * \warning the returned value is the actual content of the config set
  */
@@ -835,11 +835,11 @@ XBT_PUBLIC_DATA(xbt_cfg_t) simgrid_config;
 
 static void make_set()
 {
-  simgrid_config = NULL;
+  simgrid_config = nullptr;
   xbt_log_threshold_set(&_XBT_LOGV(xbt_cfg), xbt_log_priority_critical);
-  xbt_cfg_register_int("speed", 0, NULL, "");
-  xbt_cfg_register_string("peername", "", NULL, "");
-  xbt_cfg_register_string("user", "", NULL, "");
+  xbt_cfg_register_int("speed", 0, nullptr, "");
+  xbt_cfg_register_string("peername", "", nullptr, "");
+  xbt_cfg_register_string("user", "", nullptr, "");
 }                               /* end_of_make_set */
 
 XBT_TEST_UNIT("memuse", test_config_memuse, "Alloc and free a config set")
index 0f7cc0f..56349c4 100644 (file)
@@ -34,17 +34,17 @@ XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
   /* to be returned. */
   char* path = bprintf("/proc/%i/maps", (int) pid);
   FILE *fp = std::fopen(path, "r");
-  if(fp == NULL)
+  if(fp == nullptr)
     std::perror("fopen failed");
   xbt_assert(fp, "Cannot open %s to investigate the memory map of the process.", path);
   free(path);
-  setbuf(fp, NULL);
+  setbuf(fp, nullptr);
 
   std::vector<VmMap> ret;
 
   /* Read one line at the time, parse it and add it to the memory map to be returned */
   ssize_t read; /* Number of bytes readed */
-  char* line = NULL;
+  char* line = nullptr;
   std::size_t n = 0; /* Amount of bytes to read by xbt_getline */
   while ((read = xbt_getline(&line, &n, fp)) != -1) {
 
@@ -58,8 +58,8 @@ XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
     lfields[0] = strtok(line, " ");
 
     int i;
-    for (i = 1; i < 6 && lfields[i - 1] != NULL; i++) {
-      lfields[i] = std::strtok(NULL, " ");
+    for (i = 1; i < 6 && lfields[i - 1] != nullptr; i++) {
+      lfields[i] = std::strtok(nullptr, " ");
     }
 
     /* Check to see if we got the expected amount of columns */
@@ -69,7 +69,7 @@ XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
     /* Ok we are good enough to try to get the info we need */
     /* First get the start and the end address of the map   */
     char *tok = std::strtok(lfields[0], "-");
-    if (tok == NULL)
+    if (tok == nullptr)
       xbt_abort();
 
     VmMap memreg;
@@ -79,8 +79,8 @@ XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
     if (*endptr != '\0')
       xbt_abort();
 
-    tok = std::strtok(NULL, "-");
-    if (tok == NULL)
+    tok = std::strtok(nullptr, "-");
+    if (tok == nullptr)
       xbt_abort();
 
     memreg.end_addr = std::strtoull(tok, &endptr, 16);
@@ -125,7 +125,7 @@ XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
 
     /* Get the device major:minor bytes */
     tok = std::strtok(lfields[3], ":");
-    if (tok == NULL)
+    if (tok == nullptr)
       xbt_abort();
 
     memreg.dev_major = (char) strtoul(tok, &endptr, 16);
@@ -133,8 +133,8 @@ XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
     if (*endptr != '\0')
       xbt_abort();
 
-    tok = std::strtok(NULL, ":");
-    if (tok == NULL)
+    tok = std::strtok(nullptr, ":");
+    if (tok == nullptr)
       xbt_abort();
 
     memreg.dev_minor = (char) std::strtoul(tok, &endptr, 16);
index 2445b0b..ac96752 100644 (file)
@@ -116,7 +116,7 @@ xbt_parmap_t xbt_parmap_new(unsigned int num_workers, e_xbt_parmap_mode_t mode)
 
   /* Create the pool of worker threads */
   xbt_parmap_thread_data_t data;
-  parmap->workers[0] = NULL;
+  parmap->workers[0] = nullptr;
 #if HAVE_PTHREAD_SETAFFINITY
   int core_bind = 0;
 #endif  
@@ -124,7 +124,7 @@ xbt_parmap_t xbt_parmap_new(unsigned int num_workers, e_xbt_parmap_mode_t mode)
     data = xbt_new0(s_xbt_parmap_thread_data_t, 1);
     data->parmap = parmap;
     data->worker_id = i;
-    parmap->workers[i] = xbt_os_thread_create(NULL, xbt_parmap_worker_main, data, NULL);
+    parmap->workers[i] = xbt_os_thread_create(nullptr, xbt_parmap_worker_main, data, nullptr);
 #if HAVE_PTHREAD_SETAFFINITY
     xbt_os_thread_bind(parmap->workers[i], core_bind); 
     if (core_bind != xbt_os_get_numcores())
@@ -151,7 +151,7 @@ void xbt_parmap_destroy(xbt_parmap_t parmap)
 
   unsigned int i;
   for (i = 1; i < parmap->num_workers; i++)
-    xbt_os_thread_join(parmap->workers[i], NULL);
+    xbt_os_thread_join(parmap->workers[i], nullptr);
 
   xbt_os_cond_destroy(parmap->ready_cond);
   xbt_os_mutex_destroy(parmap->ready_mutex);
@@ -245,7 +245,7 @@ void xbt_parmap_apply(xbt_parmap_t parmap, void_f_pvoid_t fun, xbt_dynar_t data)
  *
  * Worker threads call this function to get more work.
  *
- * \return the next task to process, or NULL if there is no more work
+ * \return the next task to process, or nullptr if there is no more work
  */
 void* xbt_parmap_next(xbt_parmap_t parmap)
 {
@@ -253,7 +253,7 @@ void* xbt_parmap_next(xbt_parmap_t parmap)
   if (index < xbt_dynar_length(parmap->data)) {
     return xbt_dynar_get_as(parmap->data, index, void*);
   }
-  return NULL;
+  return nullptr;
 }
 
 static void xbt_parmap_work(xbt_parmap_t parmap)
@@ -272,7 +272,7 @@ static void *xbt_parmap_worker_main(void *arg)
   xbt_parmap_thread_data_t data = (xbt_parmap_thread_data_t) arg;
   xbt_parmap_t parmap = data->parmap;
   unsigned round = 0;
-  smx_context_t context = SIMIX_context_new(std::function<void()>(), NULL, NULL);
+  smx_context_t context = SIMIX_context_new(std::function<void()>(), nullptr, nullptr);
   SIMIX_context_set_current(context);
 
   XBT_DEBUG("New worker thread created");
@@ -291,7 +291,7 @@ static void *xbt_parmap_worker_main(void *arg)
     } else {
       delete context;
       xbt_free(data);
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -300,13 +300,13 @@ static void *xbt_parmap_worker_main(void *arg)
 static void futex_wait(unsigned *uaddr, unsigned val)
 {
   XBT_VERB("Waiting on futex %p", uaddr);
-  syscall(SYS_futex, uaddr, FUTEX_WAIT_PRIVATE, val, NULL, NULL, 0);
+  syscall(SYS_futex, uaddr, FUTEX_WAIT_PRIVATE, val, nullptr, nullptr, 0);
 }
 
 static void futex_wake(unsigned *uaddr, unsigned val)
 {
   XBT_VERB("Waking futex %p", uaddr);
-  syscall(SYS_futex, uaddr, FUTEX_WAKE_PRIVATE, val, NULL, NULL, 0);
+  syscall(SYS_futex, uaddr, FUTEX_WAKE_PRIVATE, val, nullptr, nullptr, 0);
 }
 #endif