From: Frederic Suter Date: Thu, 27 Jul 2017 12:31:44 +0000 (+0200) Subject: Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid X-Git-Tag: v3_17~316^2~4 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/48eb2f1b9262fc74f527816c348ed2aa6efa9f65?hp=42e383007df6506a0a9e8188fb38627ea0256352 Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid --- diff --git a/examples/msg/cloud-masterworker/cloud-masterworker.c b/examples/msg/cloud-masterworker/cloud-masterworker.c index 8d31f14b12..86449a44ee 100644 --- a/examples/msg/cloud-masterworker/cloud-masterworker.c +++ b/examples/msg/cloud-masterworker/cloud-masterworker.c @@ -122,8 +122,8 @@ static int master_fun(int argc, char *argv[]) XBT_INFO("# Add one more process on each VM"); xbt_dynar_foreach(vms, i, vm) { unsigned int index = i + xbt_dynar_length(vms); - char *vm_name = bprintf("VM%02u", i); - char *pr_name = bprintf("WRK%02u", index); + char* vm_name = bprintf("VM%02u", i); + char* pr_name = bprintf("WRK%02u", index); XBT_INFO("put a process (%s) on %s", pr_name, vm_name); MSG_process_create(pr_name, worker_fun, NULL, (msg_host_t)vm); diff --git a/examples/msg/dht-pastry/dht-pastry.c b/examples/msg/dht-pastry/dht-pastry.c index e9fc5d470a..1c029d2aca 100644 --- a/examples/msg/dht-pastry/dht-pastry.c +++ b/examples/msg/dht-pastry/dht-pastry.c @@ -32,7 +32,7 @@ static int timeout = 50; static int max_simulation_time = 1000; typedef struct s_node { - unsigned id; //128bits generated random(2^128 -1) + unsigned id; // 128bits generated random(2^128 -1) unsigned known_id; char mailbox[MAILBOX_NAME_SIZE]; // my mailbox name (string representation of the id) unsigned namespace_set[NAMESPACE_SIZE]; @@ -63,7 +63,7 @@ typedef enum { typedef struct s_task_data { e_task_type_t type; // type of task unsigned sender_id; // id parameter (used by some types of tasks) - //int request_finger; // finger parameter (used by some types of tasks) + // int request_finger; // finger parameter (used by some types of tasks) unsigned answer_id; // answer (used by some types of tasks) char answer_to[MAILBOX_NAME_SIZE]; // mailbox to send an answer to (if any) //const char* issuer_host_name; // used for logging diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 10b3ff38d5..f29739eae8 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -76,7 +76,7 @@ XBT_PUBLIC(void) xbt_backtrace_display_current(); /** @brief Like malloc, but xbt_die() on error @hideinitializer */ static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) { - void *res = malloc(n); + void* res = malloc(n); if (!res) xbt_die("Memory allocation of %lu bytes failed", (unsigned long)n); return res; @@ -85,7 +85,7 @@ static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) { /** @brief like malloc, but xbt_die() on error and memset data to 0 @hideinitializer */ static XBT_ALWAYS_INLINE void *xbt_malloc0(size_t n) { - void *res = calloc(n, 1); + void* res = calloc(n, 1); if (!res) xbt_die("Memory callocation of %lu bytes failed", (unsigned long)n); return res; diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index 7fbfdf0823..977bad1502 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -11,10 +11,11 @@ #include #include +#include #include #include -#include #include +#include #include #include @@ -23,11 +24,7 @@ #include "xbt/misc.h" #include "xbt/sysdep.h" #include "xbt/log.h" -#include "xbt/ex.h" #include "xbt/dynar.h" -#include "xbt/dict.h" - -// ***** XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support"); @@ -177,6 +174,7 @@ public: bool isDefault() const { return isdefault; } std::string const& getDescription() const { return desc; } + std::string const& getKey() const { return key; } }; // **** TypedConfigurationElement **** @@ -262,13 +260,13 @@ const char* TypedConfigurationElement::getTypeName() // override class Config { private: // name -> ConfigElement: - xbt_dict_t options; + std::map options; // alias -> xbt_dict_elm_t from options: - xbt_dict_t aliases; - bool warn_for_aliases; + std::map aliases; + bool warn_for_aliases = true; public: - Config(); + Config() = default; ~Config(); // No copy: @@ -284,15 +282,11 @@ public: simgrid::config::TypedConfigurationElement* registerOption(const char* name, A&&... a) { - xbt_assert(xbt_dict_get_or_null(this->options, name) == nullptr, - "Refusing to register the config element '%s' twice.", name); - TypedConfigurationElement* variable = - new TypedConfigurationElement(name, std::forward(a)...); - XBT_DEBUG("Register cfg elm %s (%s) of type %s @%p in set %p)", - name, - variable->getDescription().c_str(), + xbt_assert(options.find(name) == options.end(), "Refusing to register the config element '%s' twice.", name); + TypedConfigurationElement* variable = new TypedConfigurationElement(name, std::forward(a)...); + XBT_DEBUG("Register cfg elm %s (%s) of type %s @%p in set %p)", name, variable->getDescription().c_str(), variable->getTypeName(), variable, this); - xbt_dict_set(this->options, name, variable, nullptr); + options.insert({name, variable}); variable->update(); return variable; } @@ -303,58 +297,43 @@ public: void help(); protected: - xbt_dictelm_t getDictElement(const char* name); + ConfigurationElement* getDictElement(const char* name); }; -/* Internal stuff used in cache to free a variable */ -static void xbt_cfgelm_free(void *data) -{ - if (data) - delete (simgrid::config::ConfigurationElement*) data; -} - -Config::Config() - : options(xbt_dict_new_homogeneous(xbt_cfgelm_free)) - , aliases(xbt_dict_new_homogeneous(nullptr)) - , warn_for_aliases(true) -{} - Config::~Config() { XBT_DEBUG("Frees cfg set %p", this); - xbt_dict_free(&this->options); - xbt_dict_free(&this->aliases); + for (auto elm : options) + delete elm.second; } -inline -xbt_dictelm_t Config::getDictElement(const char* name) +inline ConfigurationElement* Config::getDictElement(const char* name) { - // We are interested in the options dictelm: - xbt_dictelm_t res = xbt_dict_get_elm_or_null(options, name); - if (res) - return res; - // The aliases dict stores pointers to the options dictelm: - res = (xbt_dictelm_t) xbt_dict_get_or_null(aliases, name); - if (res && warn_for_aliases) - XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->key); - return res; + try { + return options.at(name); + } catch (std::out_of_range& unfound) { + try { + ConfigurationElement* res = aliases.at(name); + if (warn_for_aliases) + XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->getKey().c_str()); + return res; + } catch (std::out_of_range& missing_key) { + throw simgrid::config::missing_key_error(std::string("Bad config key: ") + name); + } + } } -inline -ConfigurationElement& Config::operator[](const char* name) +inline ConfigurationElement& Config::operator[](const char* name) { - xbt_dictelm_t elm = getDictElement(name); - if (elm == nullptr) - throw simgrid::config::missing_key_error(std::string("Bad config key, ") + name); - return *(ConfigurationElement*)elm->content; + return *(getDictElement(name)); } 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(aliases.find(aliasname) == aliases.end(), "Alias '%s' already.", aliasname); + ConfigurationElement* 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, nullptr); + this->aliases.insert({aliasname, element}); } /** @brief Dump a config set for debuging purpose @@ -364,60 +343,34 @@ 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 = nullptr; - simgrid::config::ConfigurationElement* variable = nullptr; - char *key = nullptr; - if (name) printf("%s>> Dumping of the config set '%s':\n", indent, name); - xbt_dict_foreach(dict, cursor, key, variable) - printf("%s %s: ()%s) %s", indent, key, - variable->getTypeName(), - variable->getStringValue().c_str()); + for (auto elm : options) + printf("%s %s: ()%s) %s", indent, elm.first.c_str(), elm.second->getTypeName(), + elm.second->getStringValue().c_str()); if (name) printf("%s<< End of the config set '%s'\n", indent, name); fflush(stdout); - - xbt_dict_cursor_free(&cursor); } /** @brief Displays the declared aliases and their description */ void Config::showAliases() { - xbt_dict_cursor_t dict_cursor; - xbt_dictelm_t dictel; - char *name; - std::vector names; - - xbt_dict_foreach(this->aliases, dict_cursor, name, dictel) - names.push_back(name); - std::sort(begin(names), end(names), [](char* a, char* b) { return strcmp(a, b) < 0; }); - bool old_warn_for_aliases = false; std::swap(warn_for_aliases, old_warn_for_aliases); - for (auto name : names) - printf(" %s: %s\n", name, (*this)[name].getDescription().c_str()); + for (auto elm : aliases) + printf(" %s: %s\n", elm.first.c_str(), (*this)[elm.first.c_str()].getDescription().c_str()); std::swap(warn_for_aliases, old_warn_for_aliases); } /** @brief Displays the declared options and their description */ void Config::help() { - xbt_dict_cursor_t dict_cursor; - simgrid::config::ConfigurationElement* variable; - char *name; - std::vector names; - - xbt_dict_foreach(this->options, dict_cursor, name, variable) - names.push_back(name); - std::sort(begin(names), end(names), [](char* a, char* b) { return strcmp(a, b) < 0; }); - - for (auto name : names) { - variable = (simgrid::config::ConfigurationElement*) xbt_dict_get(this->options, name); - printf(" %s: %s\n", name, variable->getDescription().c_str()); + for (auto elm : options) { + simgrid::config::ConfigurationElement* variable = this->options.at(elm.first); + printf(" %s: %s\n", elm.first.c_str(), variable->getDescription().c_str()); printf(" Type: %s; ", variable->getTypeName()); printf("Current value: %s\n", variable->getStringValue().c_str()); } diff --git a/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c b/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c index 30d5a88d16..fced26e395 100644 --- a/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c +++ b/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c @@ -48,7 +48,7 @@ static void print_buffer_int(void *buf, int len, char *msg, int rank) { printf("[%d] %s (#%d): ", rank, msg, len); for (int tmp = 0; tmp < len; tmp++) { - int *v = buf; + int* v = buf; printf("[%d]", v[tmp]); } printf("\n"); diff --git a/teshsuite/smpi/mpich3-test/coll/allgatherv4.c b/teshsuite/smpi/mpich3-test/coll/allgatherv4.c index 89d2e057f9..4c4cde6ded 100644 --- a/teshsuite/smpi/mpich3-test/coll/allgatherv4.c +++ b/teshsuite/smpi/mpich3-test/coll/allgatherv4.c @@ -60,9 +60,9 @@ int main(int argc, char **argv) if (!rbuf) fprintf(stderr, "\trbuf of %d bytes\n", MAX_BUF); if (!recvcounts) - fprintf(stderr, "\trecvcounts of %zu bytes\n", comm_size * sizeof(int)); + fprintf(stderr, "\trecvcounts of %zu bytes\n", comm_size * sizeof(int)); if (!displs) - fprintf(stderr, "\tdispls of %zu bytes\n", comm_size * sizeof(int)); + fprintf(stderr, "\tdispls of %zu bytes\n", comm_size * sizeof(int)); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } diff --git a/teshsuite/smpi/mpich3-test/datatype/dataalign.c b/teshsuite/smpi/mpich3-test/datatype/dataalign.c index 8dc30efaab..1754cd9fed 100644 --- a/teshsuite/smpi/mpich3-test/datatype/dataalign.c +++ b/teshsuite/smpi/mpich3-test/datatype/dataalign.c @@ -85,10 +85,10 @@ int main(int argc, char *argv[]) * this can generate a file that diff, for example, * believes is a binary file */ if (isprint((int) (s1[j].c))) { - fprintf(stderr, "Got s[%d].c = %c; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a'); + fprintf(stderr, "Got s[%d].c = %c; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a'); } else { - fprintf(stderr, "Got s[%d].c = %hhx; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a'); + fprintf(stderr, "Got s[%d].c = %hhx; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a'); } } } diff --git a/teshsuite/smpi/mpich3-test/datatype/longdouble.c b/teshsuite/smpi/mpich3-test/datatype/longdouble.c index 40fed30cd9..d9f9ca55c1 100644 --- a/teshsuite/smpi/mpich3-test/datatype/longdouble.c +++ b/teshsuite/smpi/mpich3-test/datatype/longdouble.c @@ -35,8 +35,8 @@ int main(int argc, char *argv[]) if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) { MPI_Type_size(MPI_LONG_DOUBLE, &type_size); if (type_size != sizeof(long double)) { - printf("type_size != sizeof(long double) : (%d != %zu)\n", type_size, sizeof(long double)); - ++errs; + printf("type_size != sizeof(long double) : (%d != %zu)\n", type_size, sizeof(long double)); + ++errs; } } #endif @@ -44,9 +44,9 @@ int main(int argc, char *argv[]) if (MPI_C_LONG_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) { MPI_Type_size(MPI_C_LONG_DOUBLE_COMPLEX, &type_size); if (type_size != sizeof(long double _Complex)) { - printf("type_size != sizeof(long double _Complex) : (%d != %zu)\n", type_size, - sizeof(long double _Complex)); - ++errs; + printf("type_size != sizeof(long double _Complex) : (%d != %zu)\n", type_size, + sizeof(long double _Complex)); + ++errs; } } #endif