public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Factor out {encode,decode}_child_exit_status
Date: Fri, 26 Mar 2021 14:01:29 +0100	[thread overview]
Message-ID: <20210326130128.GA27155@delia> (raw)

Hi,

Factor out new function encode_child_exit_status and encode_child_exit_status
out of dwz_files_1.

Committed to trunk.

Thanks,
- Tom

Factor out {encode,decode}_child_exit_status

2021-03-26  Tom de Vries  <tdevries@suse.de>

	* dwz.c (encode_child_exit_status, decode_child_exit_status): New
	function, factored out of ...
	(dwz_files_1): ... here.

---
 dwz.c | 66 +++++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/dwz.c b/dwz.c
index 3873158..5a1dd0f 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16406,6 +16406,37 @@ update_hardlinks (int nr_files, char *files[], struct file_result *resa)
     }
 }
 
+/* Encode child process exit status.  */
+static int
+encode_child_exit_status (int thisret, bool low_mem_p, struct file_result *res)
+{
+  if (thisret == 0 && low_mem_p)
+    thisret = 2;
+  assert (thisret >= 0 && thisret <= 2);
+  assert (res->res >= -3);
+  thisret = thisret + ((res->res + 3) << 2);
+  return thisret;
+}
+
+/* Decode child process exit status.  */
+static int
+decode_child_exit_status (int state, bool *low_mem_p, struct file_result *res)
+{
+  int ret;
+  if (!WIFEXITED (state))
+    error (1, 0, "Child dwz process got killed");
+  ret = WEXITSTATUS (state) & 0x3;
+  *low_mem_p = false;
+  if (ret == 2)
+    {
+      ret = 0;
+      *low_mem_p = true;
+    }
+  res->res = (int)((WEXITSTATUS (state) & ~0x3) >> 2) - 3;
+
+  return ret;
+}
+
 /* Dwarf-compress FILES.  If HARDLINK, detect if some files are hardlinks and
    if so, dwarf-compress just one, and relink the others.  */
 static int
@@ -16458,17 +16489,9 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	    {
 	      int state;
 	      pid_t got_pid = waitpid (-1, &state, 0);
-	      if (!WIFEXITED (state))
-		error (1, 0, "Child dwz process got killed");
-	      thisret = WEXITSTATUS (state) & 0x3;
-	      bool low_mem_p = false;
-	      if (thisret == 2)
-		{
-		  thisret = 0;
-		  low_mem_p = true;
-		}
-	      (void)low_mem_p;
-	      res->res = (int)((WEXITSTATUS (state) & ~0x3) >> 2) - 3;
+	      bool low_mem_p;
+	      int thisret
+		= decode_child_exit_status (state, &low_mem_p, res);
 	      if (thisret == 1)
 		ret = 1;
 	      nr_forks--;
@@ -16488,13 +16511,7 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	    {
 	      bool low_mem_p;
 	      thisret = dwz_with_low_mem (file, NULL, res, &low_mem_p);
-	      /* Encode thisret, low_mem_p and res->res into return status.  */
-	      if (thisret == 0 && low_mem_p)
-		thisret = 2;
-	      assert (thisret >= 0 && thisret <= 2);
-	      assert (res->res >= -3);
-	      thisret = thisret + ((res->res + 3) << 2);
-	      return thisret;
+	      return encode_child_exit_status (thisret, low_mem_p, res);
 	    }
 	  else
 	    {
@@ -16515,17 +16532,8 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	  int state;
 	  pid_t got_pid = waitpid (pids[i], &state, 0);
 	  assert (got_pid == pids[i]);
-	  if (!WIFEXITED (state))
-	    error (1, 0, "Child dwz process got killed");
-	  thisret = WEXITSTATUS (state) & 0x3;
-	  bool low_mem_p = false;
-	  if (thisret == 2)
-	    {
-	      thisret = 0;
-	      low_mem_p = true;
-	    }
-	  (void)low_mem_p;
-	  res->res = (int)((WEXITSTATUS (state) & ~0x3) >> 2) - 3;
+	  bool low_mem_p;
+	  thisret = decode_child_exit_status (state, &low_mem_p, res);
 	  if (thisret == 1)
 	    ret = 1;
 	}

                 reply	other threads:[~2021-03-26 13:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210326130128.GA27155@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).