fix cli-script.c
authorTom Tromey <tromey@redhat.com>
Thu, 30 May 2013 17:36:29 +0000 (17:36 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 30 May 2013 17:36:29 +0000 (17:36 +0000)
read_command_lines_1 had some (IMNSHO) spaghetti-ish code for cleanup
handling.  This makes the code much simpler to understand, by
introducing an outer cleanup.

This is another case where a stylistic change for the checker is also
nice for the reader.

* cli/cli-script.c (read_command_lines_1): Use a null cleanup
for 'old_chain'.  Do not check 'head' before processing
cleanups.

gdb/ChangeLog
gdb/cli/cli-script.c

index 5c999c0..14b51d9 100644 (file)
@@ -1,5 +1,11 @@
 2013-05-30  Tom Tromey  <tromey@redhat.com>
 
+       * cli/cli-script.c (read_command_lines_1): Use a null cleanup
+       for 'old_chain'.  Do not check 'head' before processing
+       cleanups.
+
+2013-05-30  Tom Tromey  <tromey@redhat.com>
+
        * mi/mi-cmd-stack.c (list_arg_or_local): Remove
        "cleanup_tuple".
 
index 43fd479..d35f42f 100644 (file)
@@ -1246,13 +1246,12 @@ read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands,
                      void (*validator)(char *, void *), void *closure)
 {
   struct command_line *head, *tail, *next;
-  struct cleanup *old_chain;
+  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   enum command_control_type ret;
   enum misc_command_type val;
 
   control_level = 0;
   head = tail = NULL;
-  old_chain = NULL;
 
   while (1)
     {
@@ -1298,22 +1297,17 @@ read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands,
       else
        {
          head = next;
-         old_chain = make_cleanup_free_command_lines (&head);
+         make_cleanup_free_command_lines (&head);
        }
       tail = next;
     }
 
   dont_repeat ();
 
-  if (head)
-    {
-      if (ret != invalid_control)
-       {
-         discard_cleanups (old_chain);
-       }
-      else
-       do_cleanups (old_chain);
-    }
+  if (ret != invalid_control)
+    discard_cleanups (old_chain);
+  else
+    do_cleanups (old_chain);
 
   return head;
 }