public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Factor out dwz_with_low_mem
@ 2021-03-23  8:52 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-23  8:52 UTC (permalink / raw)
  To: dwz, jakub, mark

Hi,

Factor out new function dwz_with_low_mem out of dwz_one_file/dwz_files.

Any comments?

Thanks,
- Tom

Factor out dwz_with_low_mem

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

	* dwz.c (dwz_with_low_mem): New function, factored out of ...
	(dwz_one_file): ... here, and ...
	(dwz_files): here.

---
 dwz.c | 56 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/dwz.c b/dwz.c
index a7aa23b..4fc1e7d 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16256,32 +16256,49 @@ make_temp_file (const char *name)
   return fd;
 }
 
-/* Dwarf-compress FILE.  If OUTFILE, write to result to OUTFILE, otherwise
-   modify FILE.  */
+/* As dwz, but retry with MULTIFILE_MODE_LOW_MEM if the low_mem_die_limit
+   is hit.  */
 static int
-dwz_one_file (const char *file, const char *outfile)
+dwz_with_low_mem (const char *file, const char *outfile,
+		  struct file_result *res, struct file_result *resa,
+		  char **files, bool *low_mem_p)
 {
-  int ret = 0;
-  struct file_result res;
-
-  if (stats_p)
-    init_stats (file);
+  int ret;
 
-  res.die_count = 0;
+  if (low_mem_p)
+    *low_mem_p = false;
 
   ret = (low_mem_die_limit == 0
 	 ? 2
-	 : dwz (file, outfile, &res, NULL, NULL));
+	 : dwz (file, outfile, res, resa, files));
 
   if (ret == 2)
     {
       multifile_mode = MULTIFILE_MODE_LOW_MEM;
-      ret = dwz (file, outfile, &res, NULL, NULL);
+      if (low_mem_p)
+	*low_mem_p = true;
+
+      ret = dwz (file, outfile, res, resa, files);
     }
 
   return ret;
 }
 
+/* Dwarf-compress FILE.  If OUTFILE, write to result to OUTFILE, otherwise
+   modify FILE.  */
+static int
+dwz_one_file (const char *file, const char *outfile)
+{
+  struct file_result res;
+
+  if (stats_p)
+    init_stats (file);
+
+  res.die_count = 0;
+
+  return dwz_with_low_mem (file, outfile, &res, NULL, NULL, NULL);
+}
+
 /* Dwarf-compress FILES.  If HARDLINK, detect if some files are hardlinks and
    if so, dwarf-compress just one, and relink the others.  */
 static int
@@ -16324,19 +16341,12 @@ dwz_files (int nr_files, char *files[], bool hardlink)
       file = files[i];
       if (stats_p)
 	init_stats (file);
-      thisret = (low_mem_die_limit == 0
-		 ? 2
-		 : dwz (file, NULL, &resa[i],
-			hardlinks ? resa : NULL, files));
-      if (thisret == 2)
-	{
-	  multifile_mode = MULTIFILE_MODE_LOW_MEM;
-	  thisret = dwz (file, NULL, &resa[i],
-			 hardlinks ? resa : NULL, files);
-	}
-      else if (thisret == 1)
+      bool low_mem_p;
+      thisret = dwz_with_low_mem (file, NULL, &resa[i],
+				  hardlinks ? resa : NULL, files, &low_mem_p);
+      if (thisret == 1)
 	ret = 1;
-      else if (resa[i].res >= 0)
+      else if (!low_mem_p && resa[i].res >= 0)
 	successcount++;
       if (hardlink
 	  && resa[i].res >= 0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-23  8:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  8:52 [PATCH] Factor out dwz_with_low_mem Tom de Vries

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).