Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / smpi / bindings / smpi_pmpi.cpp
index 66346e8..4a07b91 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -76,7 +76,7 @@ int PMPI_Get_version (int *version,int *subversion){
 }
 
 int PMPI_Get_library_version (char *version,int *len){
-  snprintf(version, MPI_MAX_LIBRARY_VERSION_STRING, "SMPI Version %d.%d. Copyright The SimGrid Team 2007-2020",
+  snprintf(version, MPI_MAX_LIBRARY_VERSION_STRING, "SMPI Version %d.%d. Copyright The SimGrid Team 2007-2021",
            SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR);
   *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
   return MPI_SUCCESS;
@@ -152,10 +152,10 @@ int PMPI_Get_address(const void *location, MPI_Aint * address)
 
 int PMPI_Get_processor_name(char *name, int *resultlen)
 {
-  strncpy(name, sg_host_self()->get_cname(),
-          strlen(sg_host_self()->get_cname()) < MPI_MAX_PROCESSOR_NAME - 1 ? strlen(sg_host_self()->get_cname()) + 1
-                                                                           : MPI_MAX_PROCESSOR_NAME - 1);
-  *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
+  int len = std::min<int>(sg_host_self()->get_name().size(), MPI_MAX_PROCESSOR_NAME - 1);
+  std::string(sg_host_self()->get_name()).copy(name, len);
+  name[len]  = '\0';
+  *resultlen = len;
 
   return MPI_SUCCESS;
 }
@@ -188,12 +188,8 @@ int PMPI_Initialized(int* flag) {
 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info /*info*/, void* baseptr)
 {
   void *ptr = xbt_malloc(size);
-  if(ptr==nullptr)
-    return MPI_ERR_NO_MEM;
-  else {
-    *static_cast<void**>(baseptr) = ptr;
-    return MPI_SUCCESS;
-  }
+  *static_cast<void**>(baseptr) = ptr;
+  return MPI_SUCCESS;
 }
 
 int PMPI_Free_mem(void *baseptr){
@@ -209,9 +205,8 @@ int PMPI_Error_class(int errorcode, int* errorclass) {
 
 int PMPI_Error_string(int errorcode, char* string, int* resultlen)
 {
-  static const char* smpi_error_string[] = {FOREACH_ERROR(GENERATE_STRING)};
-  constexpr int nerrors                  = (sizeof smpi_error_string) / (sizeof smpi_error_string[0]);
-  if (errorcode < 0 || errorcode >= nerrors || string == nullptr)
+  static const std::vector<const char*> smpi_error_string = {FOREACH_ERROR(GENERATE_STRING)};
+  if (errorcode < 0 || static_cast<size_t>(errorcode) >= smpi_error_string.size() || string == nullptr)
     return MPI_ERR_ARG;
 
   int len    = snprintf(string, MPI_MAX_ERROR_STRING, "%s", smpi_error_string[errorcode]);