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: Heads up - Alpha ISO-C fixes


FYI,

The attatched patch:

	o	purges PTR from the make_cleanup stuff

	o	documents a problem with casting
		function pointers when calling make_cleanup()

	o	makes the function type def signature
		consistent with other typedefs.

I resisted the temptation to move this code out of utils.c.

	Andrew

(This is just the start, sigh)
Sat Mar  4 10:57:25 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* defs.h (make_cleanup_func): Document as deprecated.
	(make_cleanup_ftype): New typedef.  Make signature consistent with
 	other function typedefs.  Document as not be used out side of
 	make_cleanup code. Use in make_cleanup declarations.
	
	* utils.c (make_cleanup, make_final_cleanup, make_run_cleanup,
 	make_exec_cleanup, make_exec_error_cleanup, make_my_cleanup,
 	null_cleanup): Change K&R definition to ISO-C using void* and
 	make_cleanup_fytpe.
	(discard_my_cleanups): Don't cast argument to free.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.5
diff -p -r1.5 defs.h
*** defs.h	2000/03/03 15:37:09	1.5
--- defs.h	2000/03/04 00:34:36
*************** extern void discard_final_cleanups (stru
*** 293,316 ****
  extern void discard_exec_error_cleanups (struct cleanup *);
  extern void discard_my_cleanups (struct cleanup **, struct cleanup *);
  
  typedef void (*make_cleanup_func) (void *);
  
! extern struct cleanup *make_cleanup (make_cleanup_func, void *);
  
  extern struct cleanup *make_cleanup_freeargv (char **);
  
  struct ui_file;
  extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *);
  
! extern struct cleanup *make_final_cleanup (make_cleanup_func, void *);
  
  extern struct cleanup *make_my_cleanup (struct cleanup **,
! 					make_cleanup_func, void *);
  
! extern struct cleanup *make_run_cleanup (make_cleanup_func, void *);
  
! extern struct cleanup *make_exec_cleanup (make_cleanup_func, void *);
! extern struct cleanup *make_exec_error_cleanup (make_cleanup_func, void *);
  
  extern struct cleanup *save_cleanups (void);
  extern struct cleanup *save_final_cleanups (void);
--- 293,328 ----
  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.
!    Instead either use a bounce function or add a wrapper function.
!    Calling a f(char*) function with f(void*) is non-portable. */
! typedef void (make_cleanup_ftype) (void *);
  
+ extern struct cleanup *make_cleanup (make_cleanup_ftype *, void *);
+ 
  extern struct cleanup *make_cleanup_freeargv (char **);
  
  struct ui_file;
  extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *);
  
! extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *);
  
  extern struct cleanup *make_my_cleanup (struct cleanup **,
! 					make_cleanup_ftype *, void *);
  
! extern struct cleanup *make_run_cleanup (make_cleanup_ftype *, void *);
  
! extern struct cleanup *make_exec_cleanup (make_cleanup_ftype *, void *);
! extern struct cleanup *make_exec_error_cleanup (make_cleanup_ftype *, void *);
  
  extern struct cleanup *save_cleanups (void);
  extern struct cleanup *save_final_cleanups (void);
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.2
diff -p -r1.2 utils.c
*** utils.c	2000/02/29 07:45:13	1.2
--- utils.c	2000/03/04 00:34:43
*************** int pagination_enabled = 1;
*** 160,200 ****
     Args are FUNCTION to clean up with, and ARG to pass to it.  */
  
  struct cleanup *
! make_cleanup (function, arg)
!      void (*function) PARAMS ((PTR));
!      PTR arg;
  {
    return make_my_cleanup (&cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_final_cleanup (function, arg)
!      void (*function) PARAMS ((PTR));
!      PTR arg;
  {
    return make_my_cleanup (&final_cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_run_cleanup (function, arg)
!      void (*function) PARAMS ((PTR));
!      PTR arg;
  {
    return make_my_cleanup (&run_cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_exec_cleanup (function, arg)
!      void (*function) PARAMS ((PTR));
!      PTR arg;
  {
    return make_my_cleanup (&exec_cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_exec_error_cleanup (function, arg)
!      void (*function) PARAMS ((PTR));
!      PTR arg;
  {
    return make_my_cleanup (&exec_error_cleanup_chain, function, arg);
  }
--- 160,190 ----
     Args are FUNCTION to clean up with, and ARG to pass to it.  */
  
  struct cleanup *
! make_cleanup (make_cleanup_ftype *function, void *arg)
  {
    return make_my_cleanup (&cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_final_cleanup (make_cleanup_ftype *function, void *arg)
  {
    return make_my_cleanup (&final_cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_run_cleanup (make_cleanup_ftype *function, void *arg)
  {
    return make_my_cleanup (&run_cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_exec_cleanup (make_cleanup_ftype *function, void *arg)
  {
    return make_my_cleanup (&exec_cleanup_chain, function, arg);
  }
  
  struct cleanup *
! make_exec_error_cleanup (make_cleanup_ftype *function, void *arg)
  {
    return make_my_cleanup (&exec_error_cleanup_chain, function, arg);
  }
*************** make_cleanup_ui_file_delete (struct ui_f
*** 226,235 ****
  }
  
  struct cleanup *
! make_my_cleanup (pmy_chain, function, arg)
!      struct cleanup **pmy_chain;
!      void (*function) PARAMS ((PTR));
!      PTR arg;
  {
    register struct cleanup *new
    = (struct cleanup *) xmalloc (sizeof (struct cleanup));
--- 216,223 ----
  }
  
  struct cleanup *
! make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
! 		 void *arg)
  {
    register struct cleanup *new
    = (struct cleanup *) xmalloc (sizeof (struct cleanup));
*************** discard_my_cleanups (pmy_chain, old_chai
*** 328,334 ****
    while ((ptr = *pmy_chain) != old_chain)
      {
        *pmy_chain = ptr->next;
!       free ((PTR) ptr);
      }
  }
  
--- 316,322 ----
    while ((ptr = *pmy_chain) != old_chain)
      {
        *pmy_chain = ptr->next;
!       free (ptr);
      }
  }
  
*************** free_current_contents (location)
*** 402,409 ****
  
  /* ARGSUSED */
  void
! null_cleanup (arg)
!      PTR arg;
  {
  }
  
--- 390,396 ----
  
  /* ARGSUSED */
  void
! null_cleanup (void *arg)
  {
  }
  

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