This is the mail archive of the gdb-patches@sources.redhat.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]

[rfc] Return old cleanup when doing a restore_cleanups()


Hello,

The attached patch tweeks the restore_cleanups() family of functions so 
that the old cleanup is returned.

In theory, that returned cleanup should be NULL (since the cleanup chain 
will have been drained just prior to the restore_cleanups() call).  In 
reality, I'm not too sure.  I'd like to find out what the old chain was 
so I can add an assert to certain callers (e.g. catch_errors()).

I guess the alternative is to just stick the assert in 
restore_cleanups() and see what breaks.

Thoughts?  Preference?

	Andrew

Ref: top.c:catch_errors()

   /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
      clean things up (restoring the cleanup chain) to the state they
      were just prior to the call.  Unfortunately, many FUNC's are not
      that well behaved.  This could be fixed by adding either a
      do_cleanups call (to cover the problem) or an assertion check to
      detect bad FUNCs code. */

   /* Restore the cleanup chain and error/quit messages to their
      original states. */

   restore_cleanups (saved_cleanup_chain);

2001-08-13  Andrew Cagney  <ac131313@redhat.com>

	* defs.h (restore_cleanups, restore_my_cleanups)
	(restore_final_cleanups): Return a cleanup.
	* utils.c (restore_cleanups, restore_final_cleanups): Return value
	from restore_my_cleanups.
	(restore_my_cleanups): Return old cleanup value.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.62
diff -p -r1.62 defs.h
*** defs.h	2001/08/02 20:57:19	1.62
--- defs.h	2001/08/13 19:20:18
*************** extern struct cleanup *save_cleanups (vo
*** 562,570 ****
  extern struct cleanup *save_final_cleanups (void);
  extern struct cleanup *save_my_cleanups (struct cleanup **);
  
! extern void restore_cleanups (struct cleanup *);
! extern void restore_final_cleanups (struct cleanup *);
! extern void restore_my_cleanups (struct cleanup **, struct cleanup *);
  
  extern void free_current_contents (void *);
  
--- 562,571 ----
  extern struct cleanup *save_final_cleanups (void);
  extern struct cleanup *save_my_cleanups (struct cleanup **);
  
! extern struct cleanup *restore_cleanups (struct cleanup *);
! extern struct cleanup *restore_final_cleanups (struct cleanup *);
! extern struct cleanup *restore_my_cleanups (struct cleanup **,
! 					    struct cleanup *);
  
  extern void free_current_contents (void *);
  
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.47
diff -p -r1.47 utils.c
*** utils.c	2001/08/01 18:39:23	1.47
--- utils.c	2001/08/13 19:20:20
*************** save_my_cleanups (struct cleanup **pmy_c
*** 372,393 ****
  }
  
  /* Restore the cleanup chain from a previously saved chain.  */
! void
  restore_cleanups (struct cleanup *chain)
  {
!   restore_my_cleanups (&cleanup_chain, chain);
  }
  
! void
  restore_final_cleanups (struct cleanup *chain)
  {
!   restore_my_cleanups (&final_cleanup_chain, chain);
  }
  
! void
  restore_my_cleanups (struct cleanup **pmy_chain, struct cleanup *chain)
  {
    *pmy_chain = chain;
  }
  
  /* This function is useful for cleanups.
--- 372,395 ----
  }
  
  /* Restore the cleanup chain from a previously saved chain.  */
! struct cleanup *
  restore_cleanups (struct cleanup *chain)
  {
!   return restore_my_cleanups (&cleanup_chain, chain);
  }
  
! struct cleanup *
  restore_final_cleanups (struct cleanup *chain)
  {
!   return restore_my_cleanups (&final_cleanup_chain, chain);
  }
  
! struct cleanup *
  restore_my_cleanups (struct cleanup **pmy_chain, struct cleanup *chain)
  {
+   struct cleanup *old_cleanups = *pmy_chain;
    *pmy_chain = chain;
+   return old_cleanups;
  }
  
  /* This function is useful for cleanups.

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