Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid a local variable only used by xbt_assert.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Apr 2021 08:50:23 +0000 (10:50 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Apr 2021 08:53:01 +0000 (10:53 +0200)
examples/cpp/replay-io/s4u-replay-io.cpp
src/bindings/java/JavaContext.cpp
src/bindings/java/jmsg.cpp
src/kernel/resource/profile/Profile.cpp
src/mc/ModelChecker.cpp
src/mc/Session.cpp
src/mc/remote/AppSide.cpp
src/smpi/internals/smpi_global.cpp
teshsuite/msg/task_destroy_cancel/task_destroy_cancel.c

index 1211950..8755783 100644 (file)
@@ -88,8 +88,7 @@ public:
     double clock          = simgrid::s4u::Engine::get_clock();
 
     ACT_DEBUG("Entering Close: %s (filename: %s)", NAME.c_str(), file_name.c_str());
-    XBT_ATTRIB_UNUSED auto count = opened_files.erase(full_name);
-    xbt_assert(count == 1, "File not found in opened files: %s", full_name.c_str());
+    xbt_assert(opened_files.erase(full_name) == 1, "File not found in opened files: %s", full_name.c_str());
 
     log_action(action, simgrid::s4u::Engine::get_clock() - clock);
   }
index 39a3070..e1a1e4e 100644 (file)
@@ -56,8 +56,8 @@ void JavaContext::start_hook()
 
   //Attach the thread to the JVM
   JNIEnv *env;
-  XBT_ATTRIB_UNUSED jint error = __java_vm->AttachCurrentThread((void**)&env, nullptr);
-  xbt_assert((error == JNI_OK), "The thread could not be attached to the JVM");
+  xbt_assert(__java_vm->AttachCurrentThread((void**)&env, nullptr) == JNI_OK,
+             "The thread could not be attached to the JVM");
   this->jenv_ = env;
 }
 
index 4b41e9e..cb08bb5 100644 (file)
@@ -257,8 +257,7 @@ static void run_jprocess(JNIEnv *env, jobject jprocess)
   if (env->ExceptionOccurred()) {
     XBT_DEBUG("Something went wrong in this Java actor, forget about it.");
     env->ExceptionClear();
-    XBT_ATTRIB_UNUSED jint error = __java_vm->DetachCurrentThread();
-    xbt_assert(error == JNI_OK, "Cannot detach failing thread");
+    xbt_assert(__java_vm->DetachCurrentThread() == JNI_OK, "Cannot detach failing thread");
     simgrid::ForcefulKillException::do_throw();
   }
 }
index 234e2eb..7174d92 100644 (file)
@@ -181,8 +181,8 @@ Profile* Profile::from_string(const std::string& name, const std::string& input,
 
       profile->stochastic_event_list.emplace_back(stochevent);
     } else {
-      XBT_ATTRIB_UNUSED int res = sscanf(val.c_str(), "%lg  %lg\n", &event.date_, &event.value_);
-      xbt_assert(res == 2, "%s:%d: Syntax error in trace\n%s", name.c_str(), linecount, input.c_str());
+      xbt_assert(sscanf(val.c_str(), "%lg  %lg\n", &event.date_, &event.value_) == 2,
+                 "%s:%d: Syntax error in trace\n%s", name.c_str(), linecount, input.c_str());
 
       xbt_assert(last_event->date_ <= event.date_,
                  "%s:%d: Invalid trace: Events must be sorted, but time %g > time %g.\n%s", name.c_str(), linecount,
index 88a52a4..f83ee8d 100644 (file)
@@ -265,8 +265,7 @@ void ModelChecker::handle_waitpid()
       // From PTRACE_O_TRACEEXIT:
 #ifdef __linux__
       if (status>>8 == (SIGTRAP | (PTRACE_EVENT_EXIT<<8))) {
-        long ptrace_res = ptrace(PTRACE_GETEVENTMSG, remote_process_->pid(), 0, &status);
-        xbt_assert(ptrace_res != -1, "Could not get exit status");
+        xbt_assert(ptrace(PTRACE_GETEVENTMSG, remote_process_->pid(), 0, &status) != -1, "Could not get exit status");
         if (WIFSIGNALED(status)) {
           MC_report_crash(status);
           this->get_remote_process().terminate();
@@ -386,18 +385,15 @@ void ModelChecker::finalize_app(bool terminate_asap)
   memset(&m, 0, sizeof m);
   m.type  = MessageType::FINALIZE;
   m.value = terminate_asap;
-  int res = checker_side_.get_channel().send(m);
-  xbt_assert(res == 0, "Could not ask the app to finalize on need");
+  xbt_assert(checker_side_.get_channel().send(m) == 0, "Could not ask the app to finalize on need");
 
   s_mc_message_t answer;
-  ssize_t s = checker_side_.get_channel().receive(answer);
-  xbt_assert(s != -1, "Could not receive answer to FINALIZE");
+  xbt_assert(checker_side_.get_channel().receive(answer) != -1, "Could not receive answer to FINALIZE");
 }
 
 bool ModelChecker::checkDeadlock()
 {
-  int res = checker_side_.get_channel().send(MessageType::DEADLOCK_CHECK);
-  xbt_assert(res == 0, "Could not check deadlock state");
+  xbt_assert(checker_side_.get_channel().send(MessageType::DEADLOCK_CHECK) == 0, "Could not check deadlock state");
   s_mc_message_int_t message;
   ssize_t s = checker_side_.get_channel().receive(message);
   xbt_assert(s != -1, "Could not receive message");
index 5a22cbb..6b2943b 100644 (file)
@@ -39,16 +39,14 @@ template <class Code> void run_child_process(int socket, Code code)
   // Make sure we do not outlive our parent
   sigset_t mask;
   sigemptyset (&mask);
-  int sigprocmask_res = sigprocmask(SIG_SETMASK, &mask, nullptr);
-  xbt_assert(sigprocmask_res >= 0, "Could not unblock signals");
-  int prctl_res = prctl(PR_SET_PDEATHSIG, SIGHUP);
-  xbt_assert(prctl_res == 0, "Could not PR_SET_PDEATHSIG");
+  xbt_assert(sigprocmask(SIG_SETMASK, &mask, nullptr) >= 0, "Could not unblock signals");
+  xbt_assert(prctl(PR_SET_PDEATHSIG, SIGHUP) == 0, "Could not PR_SET_PDEATHSIG");
 #endif
 
   // Remove CLOEXEC to pass the socket to the application
-  int fdflags   = fcntl(socket, F_GETFD, 0);
-  int fcntl_res = fdflags != -1 ? fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) : -1;
-  xbt_assert(fcntl_res != -1, "Could not remove CLOEXEC for socket");
+  int fdflags = fcntl(socket, F_GETFD, 0);
+  xbt_assert(fdflags != -1 && fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) != -1,
+             "Could not remove CLOEXEC for socket");
 
   // Disable lazy relocation in the model-checked process to prevent the application from
   // modifying its .got.plt during snapshot.
@@ -71,8 +69,7 @@ Session::Session(const std::function<void()>& code)
   // between the model-checker process (ourselves) and the model-checked
   // process:
   int sockets[2];
-  int res = socketpair(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockets);
-  xbt_assert(res != -1, "Could not create socketpair");
+  xbt_assert(socketpair(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockets) != -1, "Could not create socketpair");
 
   pid_t pid = fork();
   xbt_assert(pid >= 0, "Could not fork model-checked process");
index 27c7277..376e8b6 100644 (file)
@@ -67,8 +67,7 @@ AppSide* AppSide::initialize()
   s_mc_message_initial_addresses_t message{
       MessageType::INITIAL_ADDRESSES, mmalloc_preinit(), simgrid::kernel::actor::get_maxpid_addr(),
       simgrid::simix::simix_global_get_actors_addr(), simgrid::simix::simix_global_get_dead_actors_addr()};
-  int send_res = instance_->channel_.send(message);
-  xbt_assert(send_res == 0, "Could not send the initial message with addresses.");
+  xbt_assert(instance_->channel_.send(message) == 0, "Could not send the initial message with addresses.");
 
   instance_->handle_messages();
   return instance_.get();
@@ -88,8 +87,7 @@ void AppSide::handle_deadlock_check(const s_mc_message_t*) const
 
   // Send result:
   s_mc_message_int_t answer{MessageType::DEADLOCK_CHECK_REPLY, deadlock};
-  int send_res = channel_.send(answer);
-  xbt_assert(send_res == 0, "Could not send response");
+  xbt_assert(channel_.send(answer) == 0, "Could not send response");
 }
 void AppSide::handle_simcall_execute(const s_mc_message_simcall_handle_t* message) const
 {
@@ -146,8 +144,7 @@ void AppSide::handle_messages() const
 
         // Send result:
         s_mc_message_simcall_is_visible_answer_t answer{MessageType::SIMCALL_IS_VISIBLE_ANSWER, value};
-        int send_res = channel_.send(answer);
-        xbt_assert(send_res == 0, "Could not send response");
+        xbt_assert(channel_.send(answer) == 0, "Could not send response");
         break;
       }
 
@@ -162,8 +159,7 @@ void AppSide::handle_messages() const
         // Send result:
         s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, {0}};
         value.copy(answer.value, (sizeof answer.value) - 1); // last byte was set to '\0' by initialization above
-        int send_res = channel_.send(answer);
-        xbt_assert(send_res == 0, "Could not send response");
+        xbt_assert(channel_.send(answer) == 0, "Could not send response");
         break;
       }
 
@@ -178,8 +174,7 @@ void AppSide::handle_messages() const
         // Send result:
         s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, {0}};
         value.copy(answer.value, (sizeof answer.value) - 1); // last byte was set to '\0' by initialization above
-        int send_res = channel_.send(answer);
-        xbt_assert(send_res == 0, "Could not send response");
+        xbt_assert(channel_.send(answer) == 0, "Could not send response");
         break;
       }
 
@@ -202,8 +197,8 @@ void AppSide::handle_messages() const
 #endif
         }
         coverage_checkpoint();
-        int send_res = channel_.send(MessageType::DEADLOCK_CHECK_REPLY); // really?
-        xbt_assert(send_res == 0, "Could not answer to FINALIZE");
+        xbt_assert(channel_.send(MessageType::DEADLOCK_CHECK_REPLY) == 0, // DEADLOCK_CHECK_REPLY, really?
+                   "Could not answer to FINALIZE");
         if (terminate_asap)
           ::_Exit(0);
         break;
@@ -221,8 +216,7 @@ void AppSide::main_loop() const
   coverage_checkpoint();
   while (true) {
     simgrid::mc::execute_actors();
-    int send_res = channel_.send(MessageType::WAITING);
-    xbt_assert(send_res == 0, "Could not send WAITING message to model-checker");
+    xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send WAITING message to model-checker");
     this->handle_messages();
   }
 }
index 30d81d3..f10b47c 100644 (file)
@@ -351,8 +351,8 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of
 {
   int fdin = open(src.c_str(), O_RDONLY);
   xbt_assert(fdin >= 0, "Cannot read from %s. Please make sure that the file exists and is executable.", src.c_str());
-  XBT_ATTRIB_UNUSED int unlink_status = unlink(target.c_str());
-  xbt_assert(unlink_status == 0 || errno == ENOENT, "Failed to unlink file %s: %s", target.c_str(), strerror(errno));
+  xbt_assert(unlink(target.c_str()) == 0 || errno == ENOENT, "Failed to unlink file %s: %s", target.c_str(),
+             strerror(errno));
   int fdout = open(target.c_str(), O_CREAT | O_RDWR | O_EXCL, S_IRWXU);
   xbt_assert(fdout >= 0, "Cannot write into %s: %s", target.c_str(), strerror(errno));
 
@@ -419,14 +419,13 @@ static void smpi_init_privatization_dlopen(const std::string& executable)
     for (auto const& libname : privatize_libs) {
       // load the library once to add it to the local libs, to get the absolute path
       void* libhandle = dlopen(libname.c_str(), RTLD_LAZY);
-      xbt_assert(libhandle != nullptr, 
-                     "Cannot dlopen %s - check your settings in smpi/privatize-libs", libname.c_str());
+      xbt_assert(libhandle != nullptr, "Cannot dlopen %s - check your settings in smpi/privatize-libs",
+                 libname.c_str());
       // get library name from path
       std::string fullpath = libname;
 #if not defined(__APPLE__) && not defined(__HAIKU__)
-      XBT_ATTRIB_UNUSED int dl_iterate_res = dl_iterate_phdr(visit_libs, &fullpath);
-      xbt_assert(dl_iterate_res != 0, "Can't find a linked %s - check your settings in smpi/privatize-libs",
-                 fullpath.c_str());
+      xbt_assert(dl_iterate_phdr(visit_libs, &fullpath) != 0,
+                 "Can't find a linked %s - check your settings in smpi/privatize-libs", fullpath.c_str());
       XBT_DEBUG("Extra lib to privatize '%s' found", fullpath.c_str());
 #else
       xbt_die("smpi/privatize-libs is not (yet) compatible with OSX nor with Haiku");
index eebcf6d..2a10ed9 100644 (file)
@@ -66,8 +66,7 @@ static int worker(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
 {
   while (1) {
     msg_task_t task           = NULL;
-    XBT_ATTRIB_UNUSED int res = MSG_task_receive(&(task), "worker_mailbox");
-    xbt_assert(res == MSG_OK, "MSG_task_get failed");
+    xbt_assert(MSG_task_receive(&(task), "worker_mailbox") == MSG_OK, "MSG_task_receive failed");
     XBT_INFO("Handling task \"%s\"", MSG_task_get_name(task));
 
     if (!strcmp(MSG_task_get_name(task), "finalize")) {