From: Arnaud Giersch Date: Fri, 3 Jul 2020 12:10:27 +0000 (+0200) Subject: [sonar] Const for pointer and reference parameters (slight return). X-Git-Tag: v3.26~502 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/503aa37006d22d261b792dd00d526976fafa7052?hp=872b290c60a6ad3bf6f248f40d443589ba772a1c [sonar] Const for pointer and reference parameters (slight return). --- diff --git a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp index b240d22c27..d34e21f775 100644 --- a/examples/s4u/engine-filtering/s4u-engine-filtering.cpp +++ b/examples/s4u/engine-filtering/s4u-engine-filtering.cpp @@ -39,7 +39,7 @@ class FrequencyChanged { std::map host_list; public: - explicit FrequencyChanged(simgrid::s4u::Engine& e) + explicit FrequencyChanged(const simgrid::s4u::Engine& e) { std::vector list = e.get_all_hosts(); for (auto& host : list) { diff --git a/include/simgrid/plugins/file_system.h b/include/simgrid/plugins/file_system.h index 7b9c7a55cd..bc36088b42 100644 --- a/include/simgrid/plugins/file_system.h +++ b/include/simgrid/plugins/file_system.h @@ -29,14 +29,14 @@ XBT_PUBLIC sg_size_t sg_file_read(sg_file_t fd, sg_size_t size); XBT_PUBLIC sg_size_t sg_file_write(sg_file_t fd, sg_size_t size); XBT_PUBLIC void sg_file_close(const_sg_file_t fd); -XBT_PUBLIC const char* sg_file_get_name(sg_file_t fd); -XBT_PUBLIC sg_size_t sg_file_get_size(sg_file_t fd); +XBT_PUBLIC const char* sg_file_get_name(const_sg_file_t fd); +XBT_PUBLIC sg_size_t sg_file_get_size(const_sg_file_t fd); XBT_PUBLIC void sg_file_dump(sg_file_t fd); XBT_PUBLIC void* sg_file_get_data(const_sg_file_t fd); XBT_PUBLIC void sg_file_set_data(sg_file_t fd, void* data); XBT_PUBLIC void sg_file_seek(sg_file_t fd, sg_offset_t offset, int origin); -XBT_PUBLIC sg_size_t sg_file_tell(sg_file_t fd); -XBT_PUBLIC void sg_file_move(sg_file_t fd, const char* fullpath); +XBT_PUBLIC sg_size_t sg_file_tell(const_sg_file_t fd); +XBT_PUBLIC void sg_file_move(const_sg_file_t fd, const char* fullpath); XBT_PUBLIC void sg_file_unlink(sg_file_t fd); XBT_PUBLIC int sg_file_rcopy(sg_file_t file, sg_host_t host, const char* fullpath); XBT_PUBLIC int sg_file_rmove(sg_file_t file, sg_host_t host, const char* fullpath); diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 881499fd77..a0f9afb9ba 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -225,7 +225,7 @@ xbt::signal PajeEvent::on_destruction; xbt::signal StateEvent::on_destruction; xbt::signal EntityValue::on_creation; -static void on_container_creation_paje(Container& c) +static void on_container_creation_paje(const Container& c) { double timestamp = SIMIX_get_clock(); std::stringstream stream; @@ -244,7 +244,7 @@ static void on_container_creation_paje(Container& c) tracing_file << stream.str() << std::endl; } -static void on_container_destruction_paje(Container& c) +static void on_container_destruction_paje(const Container& c) { // trace my destruction, but not if user requests so or if the container is root if (not trace_disable_destroy && &c != Container::get_root()) { @@ -323,13 +323,13 @@ static void on_event_destruction(const PajeEvent& event) tracing_file << event.stream_.str() << std::endl; } -static void on_state_event_destruction(StateEvent& event) +static void on_state_event_destruction(const StateEvent& event) { if (event.has_extra()) *tracing_files.at(event.get_container()) << event.stream_.str() << std::endl; } -static void on_type_creation(Type& type, e_event_type event_type) +static void on_type_creation(const Type& type, e_event_type event_type) { if (event_type == PAJE_DefineLinkType) return; // this kind of type has to be handled differently @@ -344,7 +344,7 @@ static void on_type_creation(Type& type, e_event_type event_type) tracing_file << stream.str() << std::endl; } -static void on_link_type_creation(Type& type, Type& source, Type& dest) +static void on_link_type_creation(const Type& type, const Type& source, const Type& dest) { std::stringstream stream; XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, PAJE_DefineLinkType, trace_precision, 0.); diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 6e0b52a988..0c9d9a5d6a 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -494,7 +494,8 @@ ActorImpl* ActorImpl::start(const ActorCode& code) } ActorImplPtr ActorImpl::create(const std::string& name, const ActorCode& code, void* data, s4u::Host* host, - const std::unordered_map* properties, ActorImpl* parent_actor) + const std::unordered_map* properties, + const ActorImpl* parent_actor) { XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname()); diff --git a/src/kernel/actor/ActorImpl.hpp b/src/kernel/actor/ActorImpl.hpp index 181e0195e6..6e9691f35f 100644 --- a/src/kernel/actor/ActorImpl.hpp +++ b/src/kernel/actor/ActorImpl.hpp @@ -121,7 +121,8 @@ public: ActorImpl* start(const ActorCode& code); static ActorImplPtr create(const std::string& name, const ActorCode& code, void* data, s4u::Host* host, - const std::unordered_map* properties, ActorImpl* parent_actor); + const std::unordered_map* properties, + const ActorImpl* parent_actor); static ActorImplPtr attach(const std::string& name, void* data, s4u::Host* host, const std::unordered_map* properties); static void detach(); diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 1b40450457..6c37927962 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -702,7 +702,7 @@ void sg_file_close(const_sg_file_t fd) /** Retrieves the path to the file * @ingroup plugin_filesystem */ -const char* sg_file_get_name(sg_file_t fd) +const char* sg_file_get_name(const_sg_file_t fd) { xbt_assert((fd != nullptr), "Invalid file descriptor"); return fd->get_path(); @@ -711,7 +711,7 @@ const char* sg_file_get_name(sg_file_t fd) /** Retrieves the size of the file * @ingroup plugin_filesystem */ -sg_size_t sg_file_get_size(sg_file_t fd) +sg_size_t sg_file_get_size(const_sg_file_t fd) { return fd->size(); } @@ -752,12 +752,12 @@ void sg_file_seek(sg_file_t fd, sg_offset_t offset, int origin) fd->seek(offset, origin); } -sg_size_t sg_file_tell(sg_file_t fd) +sg_size_t sg_file_tell(const_sg_file_t fd) { return fd->tell(); } -void sg_file_move(sg_file_t fd, const char* fullpath) +void sg_file_move(const_sg_file_t fd, const char* fullpath) { fd->move(fullpath); } diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp index ad1a720c19..e03b30f052 100644 --- a/src/smpi/include/smpi_file.hpp +++ b/src/smpi/include/smpi_file.hpp @@ -49,13 +49,14 @@ class File : public F2C{ int get_view(MPI_Offset* disp, MPI_Datatype* etype, MPI_Datatype* filetype, char* datarep) const; MPI_Info info(); void set_info( MPI_Info info); - static int read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status); - static int read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status); - static int read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status); - static int write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status); - static int write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status); - static int write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status); - template int op_all(void *buf, int count,MPI_Datatype datatype, MPI_Status *status); + static int read(MPI_File fh, void* buf, int count, const Datatype* datatype, MPI_Status* status); + static int read_shared(MPI_File fh, void* buf, int count, const Datatype* datatype, MPI_Status* status); + static int read_ordered(MPI_File fh, void* buf, int count, const Datatype* datatype, MPI_Status* status); + static int write(MPI_File fh, void* buf, int count, const Datatype* datatype, MPI_Status* status); + static int write_shared(MPI_File fh, const void* buf, int count, const Datatype* datatype, MPI_Status* status); + static int write_ordered(MPI_File fh, const void* buf, int count, const Datatype* datatype, MPI_Status* status); + template + int op_all(void* buf, int count, const Datatype* datatype, MPI_Status* status); static int close(MPI_File *fh); static int del(const char* filename, const Info* info); MPI_Errhandler errhandler(); @@ -71,8 +72,9 @@ class File : public F2C{ /* issue_date = {Winter 1996},*/ /* pages = {301--317},*/ /* }*/ - template - int File::op_all(void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ + template + int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* status) + { //get min and max offsets from everyone. int size = comm_->size(); int rank = comm_-> rank(); diff --git a/src/smpi/include/smpi_group.hpp b/src/smpi/include/smpi_group.hpp index 82c51c4ef6..67e1291183 100644 --- a/src/smpi/include/smpi_group.hpp +++ b/src/smpi/include/smpi_group.hpp @@ -29,7 +29,7 @@ class Group : public F2C{ public: Group() = default; explicit Group(int size) : size_(size), rank_to_actor_map_(size, nullptr), index_to_rank_map_(size, MPI_UNDEFINED) {} - explicit Group(Group* origin); + explicit Group(const Group* origin); void set_mapping(s4u::Actor* actor, int rank); int rank(int index); diff --git a/src/smpi/include/smpi_status.hpp b/src/smpi/include/smpi_status.hpp index 31a7a1d450..c906afd8d0 100644 --- a/src/smpi/include/smpi_status.hpp +++ b/src/smpi/include/smpi_status.hpp @@ -20,7 +20,7 @@ static void empty(MPI_Status * status); static int cancelled (const MPI_Status * status); static void set_cancelled (MPI_Status * status, int flag); static void set_elements(MPI_Status* status, const Datatype*, int count); -static int get_count(const MPI_Status * status, MPI_Datatype datatype); +static int get_count(const MPI_Status* status, const Datatype* datatype); }; diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 6e01ff4263..d05763b69a 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -115,7 +115,7 @@ public: return (it == store.end()) ? MPI_REQUEST_NULL : it->second; } - void remove(MPI_Request req) + void remove(const Request* req) { if (req == MPI_REQUEST_NULL) return; diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp index 5e480d6705..872d9a7e3c 100644 --- a/src/smpi/mpi/smpi_file.cpp +++ b/src/smpi/mpi/smpi_file.cpp @@ -145,7 +145,7 @@ namespace smpi{ return MPI_SUCCESS; } - int File::read(MPI_File fh, void* /*buf*/, int count, MPI_Datatype datatype, MPI_Status* status) + int File::read(MPI_File fh, void* /*buf*/, int count, const Datatype* datatype, MPI_Status* status) { //get position first as we may be doing non contiguous reads and it will probably be updated badly MPI_Offset position = fh->file_->tell(); @@ -173,7 +173,8 @@ namespace smpi{ /* address="Berlin, Heidelberg",*/ /* pages="84--93"*/ /* }*/ - int File::read_shared(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ + int File::read_shared(MPI_File fh, void* buf, int count, const Datatype* datatype, MPI_Status* status) + { fh->shared_mutex_->lock(); fh->seek(*(fh->shared_file_pointer_),MPI_SEEK_SET); read(fh, buf, count, datatype, status); @@ -182,7 +183,8 @@ namespace smpi{ return MPI_SUCCESS; } - int File::read_ordered(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ + int File::read_ordered(MPI_File fh, void* buf, int count, const Datatype* datatype, MPI_Status* status) + { //0 needs to get the shared pointer value MPI_Offset val; if(fh->comm_->rank()==0){ @@ -205,7 +207,7 @@ namespace smpi{ return ret; } - int File::write(MPI_File fh, void* /*buf*/, int count, MPI_Datatype datatype, MPI_Status* status) + int File::write(MPI_File fh, void* /*buf*/, int count, const Datatype* datatype, MPI_Status* status) { //get position first as we may be doing non contiguous reads and it will probably be updated badly MPI_Offset position = fh->file_->tell(); @@ -223,7 +225,8 @@ namespace smpi{ return MPI_SUCCESS; } - int File::write_shared(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ + int File::write_shared(MPI_File fh, const void* buf, int count, const Datatype* datatype, MPI_Status* status) + { fh->shared_mutex_->lock(); XBT_DEBUG("Write shared on %s - Shared ptr before : %lld",fh->file_->get_path(), *(fh->shared_file_pointer_)); fh->seek(*(fh->shared_file_pointer_),MPI_SEEK_SET); @@ -234,7 +237,8 @@ namespace smpi{ return MPI_SUCCESS; } - int File::write_ordered(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status){ + int File::write_ordered(MPI_File fh, const void* buf, int count, const Datatype* datatype, MPI_Status* status) + { //0 needs to get the shared pointer value MPI_Offset val; if(fh->comm_->rank()==0){ diff --git a/src/smpi/mpi/smpi_group.cpp b/src/smpi/mpi/smpi_group.cpp index 92cee3055b..37b2a22d6e 100644 --- a/src/smpi/mpi/smpi_group.cpp +++ b/src/smpi/mpi/smpi_group.cpp @@ -14,7 +14,7 @@ MPI_Group MPI_GROUP_EMPTY=&mpi_MPI_GROUP_EMPTY; namespace simgrid{ namespace smpi{ -Group::Group(Group* origin) +Group::Group(const Group* origin) { if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) { size_ = origin->size(); diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index f1060f159a..2bc696f74f 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -1026,7 +1026,7 @@ int Request::waitany(int count, MPI_Request requests[], MPI_Status * status) return index; } -static int sort_accumulates(MPI_Request a, MPI_Request b) +static int sort_accumulates(const Request* a, const Request* b) { return (a->tag() > b->tag()); } diff --git a/src/smpi/mpi/smpi_status.cpp b/src/smpi/mpi/smpi_status.cpp index b048fe74bc..c11c0979f7 100644 --- a/src/smpi/mpi/smpi_status.cpp +++ b/src/smpi/mpi/smpi_status.cpp @@ -37,7 +37,7 @@ void Status::set_elements(MPI_Status* status, const Datatype*, int count) status->count=count; } -int Status::get_count(const MPI_Status * status, MPI_Datatype datatype) +int Status::get_count(const MPI_Status* status, const Datatype* datatype) { return status->count / datatype->size(); } diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 0d3bfc93e8..ff17a48e31 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -73,7 +73,7 @@ void HostImpl::turn_on() const } /** Kill all actors hosted here */ -void HostImpl::turn_off(kernel::actor::ActorImpl* issuer) +void HostImpl::turn_off(const kernel::actor::ActorImpl* issuer) { for (auto& actor : actor_list_) { XBT_DEBUG("Killing Actor %s@%s on behalf of %s which turned off that host.", actor.get_cname(), diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 7ce24682d4..6e3404f197 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -66,7 +66,7 @@ public: s4u::Host* get_iface() { return piface_; } void turn_on() const; - void turn_off(kernel::actor::ActorImpl* issuer); + void turn_off(const kernel::actor::ActorImpl* issuer); std::vector get_all_actors(); size_t get_actor_count() const; void add_actor(kernel::actor::ActorImpl* actor) { actor_list_.push_back(*actor); }