This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [rfa/threads] Eliminate use of make_cleanup_func


Andrew Cagney wrote:
> 
> Hello,
> 
> The attached removes the last remaining use of make_cleanup_func from
> the GDB sources.  As part of the change I added an explicit call to
> do_cleanups() - I think that previously the code was relying on the
> caller to do a cleanup :-/.
> 
>         Andrew
> 
> PS: It shows no regressions on solaris but I don't know that that means
> much.

Oh, flip! Lets try again.  The patch is attached... :-)

	Andrew
Mon Jun  5 18:44:14 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* thread.c (make_cleanup_restore_current_thread,
 	do_restore_current_thread_cleanup): New functions.
	(thread_apply_all_command, thread_apply_command): Use. Call
 	do_cleanups when finished.

	* defs.h (make_cleanup_func): Delete typedef.
	* TODO: Update.

Index: gdb/TODO
===================================================================
RCS file: /cvs/src/src/gdb/TODO,v
retrieving revision 1.30
diff -p -r1.30 TODO
*** TODO	2000/06/05 05:20:58	1.30
--- TODO	2000/06/06 03:13:53
*************** Eliminate all uses of PARAMS in GDB's so
*** 101,114 ****
  
  --
  
- Elimination of make_cleanup_func. (Andrew Cagney)
- 
- make_cleanup_func elimination
- http://sourceware.cygnus.com/ml/gdb-patches/2000-q1/msg00791.html
- http://sourceware.cygnus.com/ml/gdb-patches/2000-q1/msg00814.html
- 
- --
- 
  Fix copyright notices.
  
  Turns out that ``1998-2000'' isn't considered valid :-(
--- 101,106 ----
*************** file at a time.
*** 143,148 ****
--- 135,143 ----
  Elimination of ``(catch_errors_ftype *) func''.
  
  Like make_cleanup_func it isn't portable.
+ http://sourceware.cygnus.com/ml/gdb-patches/2000-q1/msg00791.html
+ http://sourceware.cygnus.com/ml/gdb-patches/2000-q1/msg00814.html
+ 
  
  --
  
Index: gdb/defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.24
diff -p -r1.24 defs.h
*** defs.h	2000/06/04 13:46:37	1.24
--- defs.h	2000/06/06 03:13:56
*************** extern void discard_final_cleanups (stru
*** 306,318 ****
  extern void discard_exec_error_cleanups (struct cleanup *);
  extern void discard_my_cleanups (struct cleanup **, struct cleanup *);
  
- /* DEPRECATED: cagney/2000-03-04: Do not use this typedef to cast
-    function pointers so that they match the argument to the various
-    cleanup functions.  Post GDB 5.0, this typedef will be
-    deleted. [Editors note: cagney was the person that added most of
-    those type casts] */
- typedef void (*make_cleanup_func) (void *);
- 
  /* NOTE: cagney/2000-03-04: This typedef is strictly for the
     make_cleanup function declarations below. Do not use this typedef
     as a cast when passing functions into the make_cleanup() code.
--- 306,311 ----
Index: gdb/thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.2
diff -p -r1.2 thread.c
*** thread.c	2000/05/28 01:12:32	1.2
--- thread.c	2000/06/06 03:13:58
*************** restore_current_thread (pid)
*** 519,524 ****
--- 519,546 ----
      }
  }
  
+ struct current_thread_cleanup
+ {
+   int inferior_pid;
+ };
+ 
+ static void
+ do_restore_current_thread_cleanup (void *arg)
+ {
+   struct current_thread_cleanup *old = arg;
+   restore_current_thread (old->inferior_pid);
+   free (old);
+ }
+ 
+ static struct cleanup *
+ make_cleanup_restore_current_thread (int inferior_pid)
+ {
+   struct current_thread_cleanup *old
+     = xmalloc (sizeof (struct current_thread_cleanup));
+   old->inferior_pid = inferior_pid;
+   return make_cleanup (do_restore_current_thread_cleanup, old);
+ }
+ 
  /* Apply a GDB command to a list of threads.  List syntax is a whitespace
     seperated list of numbers, or ranges, or the keyword `all'.  Ranges consist
     of two numbers seperated by a hyphen.  Examples:
*************** thread_apply_all_command (cmd, from_tty)
*** 539,546 ****
    if (cmd == NULL || *cmd == '\000')
      error ("Please specify a command following the thread ID list");
  
!   old_chain = make_cleanup ((make_cleanup_func) restore_current_thread,
! 			    (void *) inferior_pid);
  
    for (tp = thread_list; tp; tp = tp->next)
      if (thread_alive (tp))
--- 561,567 ----
    if (cmd == NULL || *cmd == '\000')
      error ("Please specify a command following the thread ID list");
  
!   old_chain = make_cleanup_restore_current_thread (inferior_pid);
  
    for (tp = thread_list; tp; tp = tp->next)
      if (thread_alive (tp))
*************** thread_apply_all_command (cmd, from_tty)
*** 556,561 ****
--- 577,584 ----
  #endif
  	execute_command (cmd, from_tty);
        }
+ 
+   do_cleanups (old_chain);
  }
  
  static void
*************** thread_apply_command (tidlist, from_tty)
*** 575,582 ****
    if (*cmd == '\000')
      error ("Please specify a command following the thread ID list");
  
!   old_chain = make_cleanup ((make_cleanup_func) restore_current_thread,
! 			    (void *) inferior_pid);
  
    while (tidlist < cmd)
      {
--- 598,604 ----
    if (*cmd == '\000')
      error ("Please specify a command following the thread ID list");
  
!   old_chain = make_cleanup_restore_current_thread (inferior_pid);
  
    while (tidlist < cmd)
      {
*************** thread_apply_command (tidlist, from_tty)
*** 627,632 ****
--- 649,656 ----
  	    }
  	}
      }
+ 
+   do_cleanups (old_chain);
  }
  
  /* Switch to the specified thread.  Will dispatch off to thread_apply_command

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]