[rfc] More ``char *'' -> ``const char *'' symtab.c and source.c

Andrew Cagney ac131313@localhost.cygnus.com
Mon Jun 11 15:01:00 GMT 2001


Hello,

This patch propogates another const-char-* down through several functions.
It is actually fallout from looking at basename() which currently casts
(const char *) -> (char *).

thoughts?

	Andrew

Mon Jun 11 17:26:43 2001  Andrew Cagney  <cagney@b1.cygnus.com>

	* source.c (openp): Make parameters ``path'' and ``string''
 	constant.
	(openp): Use alloca to safely duplicate ``string''. Make local
 	variables ``p'' and ``p1'' constant. Delete char* casts.
	* defs.h: Update.

	* symtab.c (lookup_symtab_1): Make parameter ``name'' constant.
	(lookup_symtab, lookup_partial_symtab): Ditto.
	* symtab.h (lookup_symtab, lookup_partial_symtab): Update.

Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.52
diff -p -r1.52 defs.h
*** defs.h	2001/06/10 16:25:51	1.52
--- defs.h	2001/06/11 21:55:18
*************** extern void print_address (CORE_ADDR, st
*** 698,704 ****
  
  /* From source.c */
  
! extern int openp (char *, int, char *, int, int, char **);
  
  extern int source_full_path_of (char *, char **);
  
--- 698,704 ----
  
  /* From source.c */
  
! extern int openp (const char *, int, const char *, int, int, char **);
  
  extern int source_full_path_of (char *, char **);
  
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.15
diff -p -r1.15 source.c
*** source.c	2001/06/06 10:27:59	1.15
--- source.c	2001/06/11 21:55:18
*************** source_info (char *ignore, int from_tty)
*** 515,526 ****
  /*  >>>> This should only allow files of certain types,
     >>>>  eg executable, non-directory */
  int
! openp (char *path, int try_cwd_first, char *string, int mode, int prot,
         char **filename_opened)
  {
    register int fd;
    register char *filename;
!   register char *p, *p1;
    register int len;
    int alloclen;
  
--- 515,528 ----
  /*  >>>> This should only allow files of certain types,
     >>>>  eg executable, non-directory */
  int
! openp (const char *path, int try_cwd_first, const char *string,
!        int mode, int prot,
         char **filename_opened)
  {
    register int fd;
    register char *filename;
!   const char *p;
!   const char *p1;
    register int len;
    int alloclen;
  
*************** openp (char *path, int try_cwd_first, ch
*** 534,540 ****
    if (try_cwd_first || IS_ABSOLUTE_PATH (string))
      {
        int i;
!       filename = string;
        fd = open (filename, mode, prot);
        if (fd >= 0)
  	goto done;
--- 536,543 ----
    if (try_cwd_first || IS_ABSOLUTE_PATH (string))
      {
        int i;
!       filename = alloca (strlen (string) + 1);
!       strcpy (filename, string);
        fd = open (filename, mode, prot);
        if (fd >= 0)
  	goto done;
*************** openp (char *path, int try_cwd_first, ch
*** 548,558 ****
      string += 2;
  
    alloclen = strlen (path) + strlen (string) + 2;
!   filename = (char *) alloca (alloclen);
    fd = -1;
    for (p = path; p; p = p1 ? p1 + 1 : 0)
      {
!       p1 = (char *) strchr (p, DIRNAME_SEPARATOR);
        if (p1)
  	len = p1 - p;
        else
--- 551,561 ----
      string += 2;
  
    alloclen = strlen (path) + strlen (string) + 2;
!   filename = alloca (alloclen);
    fd = -1;
    for (p = path; p; p = p1 ? p1 + 1 : 0)
      {
!       p1 = strchr (p, DIRNAME_SEPARATOR);
        if (p1)
  	len = p1 - p;
        else
*************** openp (char *path, int try_cwd_first, ch
*** 570,576 ****
  	  if (newlen > alloclen)
  	    {
  	      alloclen = newlen;
! 	      filename = (char *) alloca (alloclen);
  	    }
  	  strcpy (filename, current_directory);
  	}
--- 573,579 ----
  	  if (newlen > alloclen)
  	    {
  	      alloclen = newlen;
! 	      filename = alloca (alloclen);
  	    }
  	  strcpy (filename, current_directory);
  	}
*************** done:
*** 597,603 ****
    if (filename_opened)
      {
        if (fd < 0)
! 	*filename_opened = (char *) 0;
        else if (IS_ABSOLUTE_PATH (filename))
  	*filename_opened = savestring (filename, strlen (filename));
        else
--- 600,606 ----
    if (filename_opened)
      {
        if (fd < 0)
! 	*filename_opened = NULL;
        else if (IS_ABSOLUTE_PATH (filename))
  	*filename_opened = savestring (filename, strlen (filename));
        else
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.39
diff -p -r1.39 symtab.c
*** symtab.c	2001/06/11 16:05:24	1.39
--- symtab.c	2001/06/11 21:55:19
*************** static struct partial_symbol *lookup_par
*** 79,85 ****
  						     const char *, int,
  						     namespace_enum);
  
! static struct symtab *lookup_symtab_1 (char *);
  
  static struct symbol *lookup_symbol_aux (const char *name, const
  					 struct block *block, const
--- 79,85 ----
  						     const char *, int,
  						     namespace_enum);
  
! static struct symtab *lookup_symtab_1 (const char *);
  
  static struct symbol *lookup_symbol_aux (const char *name, const
  					 struct block *block, const
*************** cplusplus_hint (char *name)
*** 138,144 ****
     in the symtab filename will also work.  */
  
  static struct symtab *
! lookup_symtab_1 (char *name)
  {
    register struct symtab *s;
    register struct partial_symtab *ps;
--- 138,144 ----
     in the symtab filename will also work.  */
  
  static struct symtab *
! lookup_symtab_1 (const char *name)
  {
    register struct symtab *s;
    register struct partial_symtab *ps;
*************** got_symtab:
*** 192,198 ****
     of variations if the first lookup doesn't work.  */
  
  struct symtab *
! lookup_symtab (char *name)
  {
    register struct symtab *s;
  #if 0
--- 192,198 ----
     of variations if the first lookup doesn't work.  */
  
  struct symtab *
! lookup_symtab (const char *name)
  {
    register struct symtab *s;
  #if 0
*************** lookup_symtab (char *name)
*** 229,235 ****
     in the psymtab filename will also work.  */
  
  struct partial_symtab *
! lookup_partial_symtab (char *name)
  {
    register struct partial_symtab *pst;
    register struct objfile *objfile;
--- 229,235 ----
     in the psymtab filename will also work.  */
  
  struct partial_symtab *
! lookup_partial_symtab (const char *name)
  {
    register struct partial_symtab *pst;
    register struct objfile *objfile;
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.22
diff -p -r1.22 symtab.h
*** symtab.h	2001/06/11 16:05:24	1.22
--- symtab.h	2001/06/11 21:55:19
*************** extern int asm_demangle;
*** 1072,1078 ****
  
  /* lookup a symbol table by source file name */
  
! extern struct symtab *lookup_symtab (char *);
  
  /* lookup a symbol by name (optional block, optional symtab) */
  
--- 1072,1078 ----
  
  /* lookup a symbol table by source file name */
  
! extern struct symtab *lookup_symtab (const char *);
  
  /* lookup a symbol by name (optional block, optional symtab) */
  
*************** find_pc_sect_partial_function (CORE_ADDR
*** 1122,1128 ****
  
  /* lookup partial symbol table by filename */
  
! extern struct partial_symtab *lookup_partial_symtab (char *);
  
  /* lookup partial symbol table by address */
  
--- 1122,1128 ----
  
  /* lookup partial symbol table by filename */
  
! extern struct partial_symtab *lookup_partial_symtab (const char *);
  
  /* lookup partial symbol table by address */
  



More information about the Gdb-patches mailing list