[36/66] Change tui_alloc_source_buffer return type to void

Message ID 20190623224329.16060-37-tom@tromey.com
State New
Headers show
Series
  • Clean up the TUI
Related show

Commit Message

Tom Tromey June 23, 2019, 10:42 p.m.
tui_alloc_source_buffer can't actually fail, so change its return type
to void and update the callers.

2019-06-23  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (tui_alloc_source_buffer): Change return
	type to void.
	* tui/tui-winsource.c (tui_alloc_source_buffer): Change return
	type to void.
	* tui/tui-source.c (tui_set_source_content): Update.
	* tui/tui-disasm.c (tui_set_disassem_content): Update.
---
 gdb/ChangeLog           |   9 +++
 gdb/tui/tui-disasm.c    |   5 +-
 gdb/tui/tui-source.c    | 149 ++++++++++++++++++++--------------------
 gdb/tui/tui-winsource.c |   4 +-
 gdb/tui/tui-winsource.h |   2 +-
 5 files changed, 86 insertions(+), 83 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index a9d827f5b78..0bc7c642bcd 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -165,7 +165,6 @@  tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
 enum tui_status
 tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  enum tui_status ret = TUI_FAILURE;
   int i;
   int offset = TUI_DISASM_WIN->horizontal_offset;
   int max_lines, line_width;
@@ -180,9 +179,7 @@  tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc)
   if (pc == 0)
     return TUI_FAILURE;
 
-  ret = tui_alloc_source_buffer (TUI_DISASM_WIN);
-  if (ret != TUI_SUCCESS)
-    return ret;
+  tui_alloc_source_buffer (TUI_DISASM_WIN);
 
   tui_source_window_base *base = TUI_DISASM_WIN;
   base->gdbarch = gdbarch;
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index c6367765d67..39abe81a870 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -133,86 +133,85 @@  tui_set_source_content (struct symtab *s,
     {
       int line_width, nlines;
 
-      if ((ret = tui_alloc_source_buffer (TUI_SRC_WIN)) == TUI_SUCCESS)
+      ret = TUI_SUCCESS;
+      tui_alloc_source_buffer (TUI_SRC_WIN);
+      line_width = TUI_SRC_WIN->width - 1;
+      /* Take hilite (window border) into account, when
+	 calculating the number of lines.  */
+      nlines = (line_no + (TUI_SRC_WIN->height - 2)) - line_no;
+
+      std::string srclines;
+      if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
+					    &srclines))
 	{
-	  line_width = TUI_SRC_WIN->width - 1;
-	  /* Take hilite (window border) into account, when
-	     calculating the number of lines.  */
-	  nlines = (line_no + (TUI_SRC_WIN->height - 2)) - line_no;
-
-	  std::string srclines;
-	  if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
-						&srclines))
+	  if (!noerror)
 	    {
-	      if (!noerror)
-		{
-		  const char *filename = symtab_to_filename_for_display (s);
-		  char *name = (char *) alloca (strlen (filename) + 100);
-
-		  sprintf (name, "%s:%d", filename, line_no);
-		  print_sys_errmsg (name, errno);
-		}
-	      ret = TUI_FAILURE;
+	      const char *filename = symtab_to_filename_for_display (s);
+	      char *name = (char *) alloca (strlen (filename) + 100);
+
+	      sprintf (name, "%s:%d", filename, line_no);
+	      print_sys_errmsg (name, errno);
 	    }
-	  else
+	  ret = TUI_FAILURE;
+	}
+      else
+	{
+	  int cur_line_no, cur_line;
+	  struct tui_gen_win_info *locator
+	    = tui_locator_win_info_ptr ();
+	  struct tui_source_window_base *src
+	    = (struct tui_source_window_base *) TUI_SRC_WIN;
+	  const char *s_filename = symtab_to_filename_for_display (s);
+
+	  if (TUI_SRC_WIN->title)
+	    xfree (TUI_SRC_WIN->title);
+	  TUI_SRC_WIN->title = xstrdup (s_filename);
+
+	  xfree (src->fullname);
+	  src->fullname = xstrdup (symtab_to_fullname (s));
+
+	  cur_line = 0;
+	  src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
+	  src->start_line_or_addr.loa = LOA_LINE;
+	  cur_line_no = src->start_line_or_addr.u.line_no = line_no;
+
+	  const char *iter = srclines.c_str ();
+	  while (cur_line < nlines)
 	    {
-	      int cur_line_no, cur_line;
-	      struct tui_gen_win_info *locator
-		= tui_locator_win_info_ptr ();
-	      struct tui_source_window_base *src
-		= (struct tui_source_window_base *) TUI_SRC_WIN;
-	      const char *s_filename = symtab_to_filename_for_display (s);
-
-	      if (TUI_SRC_WIN->title)
-		xfree (TUI_SRC_WIN->title);
-	      TUI_SRC_WIN->title = xstrdup (s_filename);
-
-	      xfree (src->fullname);
-	      src->fullname = xstrdup (symtab_to_fullname (s));
-
-	      cur_line = 0;
-	      src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
-	      src->start_line_or_addr.loa = LOA_LINE;
-	      cur_line_no = src->start_line_or_addr.u.line_no = line_no;
-
-	      const char *iter = srclines.c_str ();
-	      while (cur_line < nlines)
-		{
-		  struct tui_win_element *element
-		    = TUI_SRC_WIN->content[cur_line];
-
-		  std::string text;
-		  if (*iter != '\0')
-		    text = copy_source_line (&iter, cur_line_no,
-					     src->horizontal_offset,
-					     line_width);
-
-		  /* Set whether element is the execution point
-		     and whether there is a break point on it.  */
-		  element->which_element.source.line_or_addr.loa =
-		    LOA_LINE;
-		  element->which_element.source.line_or_addr.u.line_no =
-		    cur_line_no;
-		  element->which_element.source.is_exec_point =
-		    (filename_cmp (locator->content[0]
-				   ->which_element.locator.full_name,
-				   symtab_to_fullname (s)) == 0
-		     && cur_line_no
-		     == locator->content[0]
-		     ->which_element.locator.line_no);
-
-		  xfree (TUI_SRC_WIN->content[cur_line]
-			 ->which_element.source.line);
-		  TUI_SRC_WIN->content[cur_line]
-		    ->which_element.source.line
-		    = xstrdup (text.c_str ());
-
-		  cur_line++;
-		  cur_line_no++;
-		}
-	      TUI_SRC_WIN->content_size = nlines;
-	      ret = TUI_SUCCESS;
+	      struct tui_win_element *element
+		= TUI_SRC_WIN->content[cur_line];
+
+	      std::string text;
+	      if (*iter != '\0')
+		text = copy_source_line (&iter, cur_line_no,
+					 src->horizontal_offset,
+					 line_width);
+
+	      /* Set whether element is the execution point
+		 and whether there is a break point on it.  */
+	      element->which_element.source.line_or_addr.loa =
+		LOA_LINE;
+	      element->which_element.source.line_or_addr.u.line_no =
+		cur_line_no;
+	      element->which_element.source.is_exec_point =
+		(filename_cmp (locator->content[0]
+			       ->which_element.locator.full_name,
+			       symtab_to_fullname (s)) == 0
+		 && cur_line_no
+		 == locator->content[0]
+		 ->which_element.locator.line_no);
+
+	      xfree (TUI_SRC_WIN->content[cur_line]
+		     ->which_element.source.line);
+	      TUI_SRC_WIN->content[cur_line]
+		->which_element.source.line
+		= xstrdup (text.c_str ());
+
+	      cur_line++;
+	      cur_line_no++;
 	    }
+	  TUI_SRC_WIN->content_size = nlines;
+	  ret = TUI_SUCCESS;
 	}
     }
   return ret;
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 1ec9cecdc9c..209d33d6c99 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -589,7 +589,7 @@  tui_update_exec_info (struct tui_win_info *win_info)
   tui_show_exec_info_content (win_info);
 }
 
-enum tui_status
+void
 tui_alloc_source_buffer (struct tui_win_info *win_info)
 {
   int i, line_width, max_lines;
@@ -608,8 +608,6 @@  tui_alloc_source_buffer (struct tui_win_info *win_info)
 	win_info->content[i]->which_element.source.line
 	  = (char *) xmalloc (line_width);
     }
-
-  return TUI_SUCCESS;
 }
 
 
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 6f2dc3533f7..ccc9ae5f68a 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -59,7 +59,7 @@  extern void tui_erase_exec_info_content (struct tui_win_info *);
 extern void tui_clear_exec_info_content (struct tui_win_info *);
 extern void tui_update_exec_info (struct tui_win_info *);
 
-extern enum tui_status tui_alloc_source_buffer (struct tui_win_info *);
+extern void tui_alloc_source_buffer (struct tui_win_info *);
 extern int tui_line_is_displayed (int, 
 				  struct tui_win_info *, 
 				  int);