Patch to make more use of libiberty.a, part 1/2

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Mon Sep 6 13:05:00 GMT 1999


This patch cleans up stuff now that we're using libiberty in more
places.  (E.g. don't define local copies of stuff provided by
libiberty.)  In addition to cleanups, it also does the following:

the patch nukes calls to malloc/realloc/calloc/strdup and favors the
'x' versions instead.  I left alone files that are linked with the
target executable like frame.c/libgcc2.c/crt-files.  I also didn't
touch files that include hconfig.h (gen*.c, etc and fixinc/* even
though it links with libiberty.  I think this is done in error.)
Finally, there were a couple of cases where comments indicated the 'x'
version was explicitly avoided.

The patch also consolidates calls to [x]malloc/bzero -> xcalloc,
[x]malloc/strcpy -> xstrdup and [x]malloc/strcpy/strcat/... -> concat,
among other things.  Details below.

Bootstrapped on OSF4 and Irix6.  This is part 1/2.  Okay to install?


1999-09-06  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* c-aux-info.c (concat): Don't define.

	* cccp.c (my_strerror): Likewise.  All callers changed to use
	xstrerror instead.
	(do_include): Call xstrdup, not xmalloc/strcpy.
	(grow_outbuf): Don't check if xrealloc returns NULL, it can't.
	(xmalloc, xrealloc, xcalloc, xstrdup): Don't define.

	* collect2.c (my_strsignal): Likewise.  All callers changed to use
	strsignal instead.
	(locatelib): Call xstrdup, not xmalloc/strcpy.

	* 1750a.h (ASM_OUTPUT_INTERNAL_LABEL): Call xmalloc, not malloc.

	* dsp16xx.c (override_options): Call xstrdup, not xmalloc/strcpy.

	* i370.h (ASM_DECLARE_FUNCTION_NAME): Call xmalloc, not malloc.

	* mips.c (build_mips16_call_stub): Call xstrdup, not xmalloc/strcpy.

	* cppinit.c (cpp_options_init): Call xcalloc, not xmalloc/bzero.

	* dwarfout.c (dwarfout_init): Call concat, not xmalloc/strcpy/...

	* except.c (new_eh_region_entry): Call xmalloc/xrealloc, not
	malloc/realloc.
	(find_all_handler_type_matches): Likewise.  Don't check return
	value.
	(get_new_handler, init_insn_eh_region, process_nestinfo): Call
	xmalloc, not malloc.
	(init_eh_nesting_info): Likewise.  Call xcalloc, not xmalloc/bzero.

	* gcc.c (xstrerror, xmalloc, xrealloc): Don't define.
	(init_spec): Call xcalloc, not xmalloc/bzero.
	(set_spec): Call xstrdup, not save_string.
	(record_temp_file): Call xstrdup, not xmalloc/strcpy.
	(find_a_file): Call xstrdup, not xmalloc/strcpy.
	(process_command): Call xstrdup, not save_string.
	(main): Call xcalloc, not xmalloc/bzero.

	* gcov.c (xmalloc): Don't define.
	(create_program_flow_graph): Call xcalloc, not xmalloc/bzero.
	(scan_for_source_files): Call xstrdup, not xmalloc/strcpy.
	(output_data): Call xcalloc, not xmalloc/bzero.

	* haifa-sched.c (schedule_insns): Call xcalloc, not xmalloc/bzero.

	* mips-tdump.c (xmalloc): Don't define.
	(print_symbol): Call xmalloc, not malloc.
	(read_tfile): Call xcalloc, not calloc.

	* mips-tfile.c (xfree, my_strsignal, xmalloc, xcalloc, xrealloc):
	Don't define.  All callers of xfree/my_strsignal changed to use
	free/strsignal instead.
	(allocate_cluster): Call xcalloc, not calloc.

	* objc/objc-act.c (lang_init): Call concat, not xmalloc/strcpy/...
	Fix memory leak, free allocated memory.

	* prefix.c (translate_name): Call xstrdup, not save_string.
	(update_path): Likewise.

	* profile.c (branch_prob): Call xstrdup, not xmalloc/strcpy.

	* protoize.c (xstrerror, xmalloc, xrealloc, xfree, savestring2):
	Don't define.  Callers of xfree/savestring2 changed to use
	free/concat instead.

	* reload1.c (reload): Call xcalloc, not xmalloc/bzero.
	(init_elim_table): Likewise.

	* resource.c (init_resource_info): Likewise.

	* stupid.c (stupid_life_analysis): Likewise.

	* toplev.c (xmalloc, xcalloc, xrealloc, xstrdup): Don't define.
	(open_dump_file): Call concat, not xmalloc/strcpy/...
	(clean_dump_file): Likewise.
	(compile_file): Call xstrdup, not xmalloc/strcpy.


diff -rup orig/egcs-CVS19990904/gcc/c-aux-info.c egcs-CVS19990904/gcc/c-aux-info.c
--- orig/egcs-CVS19990904/gcc/c-aux-info.c	Mon Apr 19 09:56:47 1999
+++ egcs-CVS19990904/gcc/c-aux-info.c	Sat Sep  4 10:07:00 1999
@@ -45,67 +45,6 @@ static const char *gen_formal_list_for_f
 static const char *gen_type		PROTO((const char *, tree, formals_style));
 static const char *gen_decl		PROTO((tree, int, formals_style));
 
-/* Concatenate a sequence of strings, returning the result.
-
-   This function is based on the one in libiberty.  */
-
-/* This definition will conflict with the one from prefix.c in
-   libcpp.a when linking cc1 and cc1obj.  So only provide it if we are
-   not using libcpp.a */
-#ifndef USE_CPPLIB
-char *
-concat VPROTO((const char *first, ...))
-{
-  register int length;
-  register char *newstr;
-  register char *end;
-  register const char *arg;
-  va_list args;
-#ifndef ANSI_PROTOTYPES
-  const char *first;
-#endif
-
-  /* First compute the size of the result and get sufficient memory.  */
-
-  VA_START (args, first);
-#ifndef ANSI_PROTOTYPES
-  first = va_arg (args, const char *);
-#endif
-
-  arg = first;
-  length = 0;
-
-  while (arg != 0)
-    {
-      length += strlen (arg);
-      arg = va_arg (args, const char *);
-    }
-
-  newstr = (char *) malloc (length + 1);
-  va_end (args);
-
-  /* Now copy the individual pieces to the result string.  */
-
-  VA_START (args, first);
-#ifndef ANSI_PROTOTYPES
-  first = va_arg (args, char *);
-#endif
-
-  end = newstr;
-  arg = first;
-  while (arg != 0)
-    {
-      while (*arg)
-	*end++ = *arg++;
-      arg = va_arg (args, const char *);
-    }
-  *end = '\000';
-  va_end (args);
-
-  return (newstr);
-}
-#endif /* ! USE_CPPLIB */
-
 /* Given a string representing an entire type or an entire declaration
    which only lacks the actual "data-type" specifier (at its left end),
    affix the data-type specifier to the left end of the given type
diff -rup orig/egcs-CVS19990904/gcc/cccp.c egcs-CVS19990904/gcc/cccp.c
--- orig/egcs-CVS19990904/gcc/cccp.c	Sat Jul 31 07:41:27 1999
+++ egcs-CVS19990904/gcc/cccp.c	Sat Sep  4 11:32:55 1999
@@ -964,7 +964,6 @@ static int discard_comments PROTO((U_CHA
 
 static int change_newlines PROTO((U_CHAR *, int));
 
-static char *my_strerror PROTO((int));
 static void notice PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1;
 static void vnotice PROTO((const char *, va_list));
 void error PVPROTO((const char *, ...)) ATTRIBUTE_PRINTF_1;
@@ -4723,8 +4722,7 @@ get_filename:
     
     /* Actually process the file */
     if (pcfbuf) {
-      pcfname = xmalloc (strlen (pcftry) + 1);
-      strcpy (pcfname, pcftry);
+      pcfname = xstrdup (pcftry);
       pcfinclude ((U_CHAR *) pcfbuf, (U_CHAR *) fname, op);
     }
     else
@@ -9230,38 +9228,6 @@ change_newlines (start, length)
   return obp - start;
 }
 
-/* my_strerror - return the descriptive text associated with an
-   `errno' code.  */
-
-static char *
-my_strerror (errnum)
-     int errnum;
-{
-  char *result;
-
-#ifndef VMS
-#ifndef HAVE_STRERROR
-  result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
-#else
-  result = strerror (errnum);
-#endif
-#else	/* VMS */
-  /* VAXCRTL's strerror() takes an optional second argument, which only
-     matters when the first argument is EVMSERR.  However, it's simplest
-     just to pass it unconditionally.  `vaxc$errno' is declared in
-     <errno.h>, and maintained by the library in parallel with `errno'.
-     We assume that caller's `errnum' either matches the last setting of
-     `errno' by the library or else does not have the value `EVMSERR'.  */
-
-  result = strerror (errnum, vaxc$errno);
-#endif
-
-  if (!result)
-    result = "errno = ?";
-
-  return result;
-}
-
 /* notice - output message to stderr */
 
 static void
@@ -9358,7 +9324,7 @@ error_from_errno (name)
     fprintf (stderr, ":%d: ", ip->lineno);
   }
 
-  fprintf (stderr, "%s: %s\n", name, my_strerror (e));
+  fprintf (stderr, "%s: %s\n", name, xstrerror (e));
 
   errors++;
 }
@@ -9716,8 +9682,7 @@ grow_outbuf (obuf, needed)
   if (minsize > obuf->length)
     obuf->length = minsize;
 
-  if ((p = (U_CHAR *) xrealloc (obuf->buf, obuf->length)) == NULL)
-    memory_full ();
+  p = (U_CHAR *) xrealloc (obuf->buf, obuf->length);
 
   obuf->bufp = p + (obuf->bufp - obuf->buf);
   obuf->buf = p;
@@ -10638,7 +10603,7 @@ static void
 perror_with_name (name)
      char *name;
 {
-  fprintf (stderr, "%s: %s: %s\n", progname, name, my_strerror (errno));
+  fprintf (stderr, "%s: %s: %s\n", progname, name, xstrerror (errno));
   errors++;
 }
 
@@ -10668,53 +10633,6 @@ static void
 memory_full ()
 {
   fatal ("Memory exhausted.");
-}
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR ptr = (PTR) malloc (size);
-  if (!ptr)
-    memory_full ();
-  return ptr;
-}
-
-PTR
-xrealloc (old, size)
-  PTR old;
-  size_t size;
-{
-  register PTR ptr;
-  if (old)
-    ptr = (PTR) realloc (old, size);
-  else
-    ptr = (PTR) malloc (size);
-  if (!ptr)
-    memory_full ();
-  return ptr;
-}
-
-PTR
-xcalloc (number, size)
-  size_t number, size;
-{
-  register size_t total = number * size;
-  register PTR ptr = (PTR) malloc (total);
-  if (!ptr)
-    memory_full ();
-  bzero (ptr, total);
-  return ptr;
-}
-
-char *
-xstrdup (input)
-  const char *input;
-{
-  register size_t len = strlen (input) + 1;
-  register char *output = xmalloc (len);
-  memcpy (output, input, len);
-  return output;
 }
 
 #ifdef VMS
diff -rup orig/egcs-CVS19990904/gcc/collect2.c egcs-CVS19990904/gcc/collect2.c
--- orig/egcs-CVS19990904/gcc/collect2.c	Fri Sep  3 15:05:57 1999
+++ egcs-CVS19990904/gcc/collect2.c	Sat Sep  4 11:36:28 1999
@@ -261,7 +261,6 @@ static struct path_prefix *libpaths[3] =
 static const char *libexts[3] = {"a", "so", NULL};  /* possible library extentions */
 #endif
 
-static const char *my_strsignal	PROTO((int));
 static void handler		PROTO((int));
 static int is_ctor_dtor		PROTO((const char *));
 static char *find_a_file	PROTO((struct path_prefix *, const char *));
@@ -321,29 +320,6 @@ dup2 (oldfd, newfd)
   return fd;
 }
 #endif
-
-static const char *
-my_strsignal (s)
-     int s;
-{
-#ifdef HAVE_STRSIGNAL
-  return strsignal (s);
-#else
-  if (s >= 0 && s < NSIG)
-    {
-# ifdef NO_SYS_SIGLIST
-      static char buffer[30];
-
-      sprintf (buffer, "Unknown signal %d", s);
-      return buffer;
-# else
-      return sys_siglist[s];
-# endif
-    }
-  else
-    return NULL;
-#endif /* HAVE_STRSIGNAL */
-}
 
 /* Delete tempfiles and exit function.  */
 
@@ -1577,7 +1553,7 @@ collect_wait (prog)
 		  : "%s terminated with signal %d [%s], core dumped"),
 		 prog,
 		 sig,
-		 my_strsignal(sig));
+		 strsignal(sig));
 	  collect_exit (FATAL_EXIT_CODE);
 	}
 
@@ -2418,8 +2394,7 @@ locatelib (name)
 	    if (*ld_rules == ':')
 	      cnt++;
 	  ld_rules = (char *) (ld_2->ld_rules + code);
-	  ldr = (char *) xmalloc (strlen (ld_rules) + 1);
-	  strcpy (ldr, ld_rules);
+	  ldr = xstrdup (ld_rules);
 	}
       p = getenv ("LD_LIBRARY_PATH");
       q = 0;
@@ -2429,8 +2404,7 @@ locatelib (name)
 	  for (q = p ; *q != 0; q++)
 	    if (*q == ':')
 	      cnt++;
-	  q = (char *) xmalloc (strlen (p) + 1);
-	  strcpy (q, p);
+	  q = xstrdup (p);
 	}
       l = (const char **) xmalloc ((cnt + 3) * sizeof (char *));
       pp = l;
diff -rup orig/egcs-CVS19990904/gcc/config/1750a/1750a.h egcs-CVS19990904/gcc/config/1750a/1750a.h
--- orig/egcs-CVS19990904/gcc/config/1750a/1750a.h	Tue Aug  3 07:42:22 1999
+++ egcs-CVS19990904/gcc/config/1750a/1750a.h	Sat Sep  4 11:13:33 1999
@@ -1116,7 +1116,7 @@ enum reg_class { NO_REGS, R2, R0_1, INDE
 	do {							\
 	  if (strcmp(PREFIX,"LC") == 0) {			\
 	     label_pending = 1;					\
-	     datalbl[++datalbl_ndx].name = (char *) malloc (9); \
+	     datalbl[++datalbl_ndx].name = (char *) xmalloc (9);\
 	     sprintf(datalbl[datalbl_ndx].name,"LC%d",NUM);	\
 	     datalbl[datalbl_ndx].size = 0;			\
 	     check_section(Konst);				\
diff -rup orig/egcs-CVS19990904/gcc/config/dsp16xx/dsp16xx.c egcs-CVS19990904/gcc/config/dsp16xx/dsp16xx.c
--- orig/egcs-CVS19990904/gcc/config/dsp16xx/dsp16xx.c	Tue Aug 24 15:43:09 1999
+++ egcs-CVS19990904/gcc/config/dsp16xx/dsp16xx.c	Sat Sep  4 13:22:54 1999
@@ -1505,8 +1505,7 @@ override_options ()
   if (const_seg_name == (char *) 0)
     const_seg_name = DEFAULT_CONST_SEG_NAME;
   
-  save_chip_name = (char *) xmalloc (strlen(chip_name) + 1);
-  strcpy (save_chip_name, chip_name);
+  save_chip_name = xstrdup (chip_name);
 
   rsect_text = (char *) xmalloc (strlen(".rsect ") + 
 				 strlen(text_seg_name) + 3);
diff -rup orig/egcs-CVS19990904/gcc/config/i370/i370.h egcs-CVS19990904/gcc/config/i370/i370.h
--- orig/egcs-CVS19990904/gcc/config/i370/i370.h	Mon Aug  9 15:42:28 1999
+++ egcs-CVS19990904/gcc/config/i370/i370.h	Sat Sep  4 11:14:22 1999
@@ -1569,12 +1569,7 @@ enum reg_class
   if (!mvs_function_name)						\
     {									\
       mvs_function_name_length = strlen (NAME) * 2;			\
-      mvs_function_name = (char *) malloc (mvs_function_name_length);	\
-      if (mvs_function_name == 0)					\
-	{								\
-	  fatal ("virtual memory exceeded");				\
-	  abort ();							\
-	}								\
+      mvs_function_name = (char *) xmalloc (mvs_function_name_length);	\
     }									\
   if (!strcmp (NAME, "main"))						\
     strcpy (mvs_function_name, "gccmain");				\
diff -rup orig/egcs-CVS19990904/gcc/config/mips/mips.c egcs-CVS19990904/gcc/config/mips/mips.c
--- orig/egcs-CVS19990904/gcc/config/mips/mips.c	Thu Sep  2 07:42:53 1999
+++ egcs-CVS19990904/gcc/config/mips/mips.c	Sat Sep  4 13:25:55 1999
@@ -7973,8 +7973,7 @@ build_mips16_call_stub (retval, fnmem, a
 
       /* Record this stub.  */
       l = (struct mips16_stub *) xmalloc (sizeof *l);
-      l->name = (char *) xmalloc (strlen (fnname) + 1);
-      strcpy (l->name, fnname);
+      l->name = xstrdup (fnname);
       l->fpret = fpret;
       l->next = mips16_stubs;
       mips16_stubs = l;
diff -rup orig/egcs-CVS19990904/gcc/cppinit.c egcs-CVS19990904/gcc/cppinit.c
--- orig/egcs-CVS19990904/gcc/cppinit.c	Wed Aug  4 16:44:33 1999
+++ egcs-CVS19990904/gcc/cppinit.c	Sat Sep  4 11:38:28 1999
@@ -525,8 +525,8 @@ cpp_options_init (opts)
   opts->cplusplus_comments = 1;
   opts->warn_import = 1;
 
-  opts->pending = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
-  bzero ((char *) opts->pending, sizeof (struct cpp_pending));
+  opts->pending =
+    (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
 }
 
 /* Initialize a cpp_reader structure. */
diff -rup orig/egcs-CVS19990904/gcc/dwarfout.c egcs-CVS19990904/gcc/dwarfout.c
--- orig/egcs-CVS19990904/gcc/dwarfout.c	Mon Aug 30 21:59:58 1999
+++ egcs-CVS19990904/gcc/dwarfout.c	Sat Sep  4 11:41:35 1999
@@ -5822,10 +5822,7 @@ dwarfout_init (asm_out_file, main_input_
 	    if (!pwd)
 	      pfatal_with_name ("getpwd");
 	    len = strlen (pwd);
-	    dirname = (char *) xmalloc (len + 2);
-    
-	    strcpy (dirname, pwd);
-	    strcpy (dirname + len, "/");
+	    dirname = concat (pwd, "/");
 	    ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname);
 	    free (dirname);
 	  }
diff -rup orig/egcs-CVS19990904/gcc/except.c egcs-CVS19990904/gcc/except.c
--- orig/egcs-CVS19990904/gcc/except.c	Thu Sep  2 15:41:42 1999
+++ egcs-CVS19990904/gcc/except.c	Sat Sep  4 10:47:22 1999
@@ -706,14 +706,14 @@ new_eh_region_entry (note_eh_region, ret
       if (num_func_eh_entries == 0)
         {
           function_eh_regions = 
-                        (struct func_eh_entry *) malloc (SIZE_FUNC_EH (50));
+                        (struct func_eh_entry *) xmalloc (SIZE_FUNC_EH (50));
           num_func_eh_entries = 50;
         }
       else
         {
           num_func_eh_entries  = num_func_eh_entries * 3 / 2;
           function_eh_regions = (struct func_eh_entry *) 
-            realloc (function_eh_regions, SIZE_FUNC_EH (num_func_eh_entries));
+            xrealloc (function_eh_regions, SIZE_FUNC_EH (num_func_eh_entries));
         }
     }
   function_eh_regions[current_func_eh_entry].range_number = note_eh_region;
@@ -807,10 +807,7 @@ find_all_handler_type_matches (array)
     return 0;
 
   max_ptr = 100;
-  ptr = (void **)malloc (max_ptr * sizeof (void *));
-
-  if (ptr == NULL)
-    return 0;
+  ptr = (void **) xmalloc (max_ptr * sizeof (void *));
 
   for (x = 0 ; x < current_func_eh_entry; x++)
     {
@@ -834,9 +831,7 @@ find_all_handler_type_matches (array)
               if (n_ptr >= max_ptr) 
                 {
                   max_ptr += max_ptr / 2;
-                  ptr = (void **)realloc (ptr, max_ptr * sizeof (void *));
-                  if (ptr == NULL)
-                    return 0;
+                  ptr = (void **) xrealloc (ptr, max_ptr * sizeof (void *));
                 }
               ptr[n_ptr] = val;
               n_ptr++;
@@ -856,7 +851,7 @@ get_new_handler (handler, typeinfo)
      void *typeinfo;
 {
   struct handler_info* ptr;
-  ptr = (struct handler_info *) malloc (sizeof (struct handler_info));
+  ptr = (struct handler_info *) xmalloc (sizeof (struct handler_info));
   ptr->handler_label = handler;
   ptr->handler_number = CODE_LABEL_NUMBER (handler);
   ptr->type_info = typeinfo;
@@ -2878,7 +2873,7 @@ init_insn_eh_region (first, max_uid)
         max_uid = INSN_UID (insn);
 
   maximum_uid = max_uid;
-  insn_eh_region = (int *) malloc ((max_uid + 1) * sizeof (int));
+  insn_eh_region = (int *) xmalloc ((max_uid + 1) * sizeof (int));
   insn = first;
   set_insn_eh_region (&insn, 0);
 }
@@ -2959,7 +2954,7 @@ process_nestinfo (block, info, nested_eh
     extra = 0;
 
   info->num_handlers[index] = count + extra;
-  info->handlers[index] = (handler_info **) malloc ((count + extra) 
+  info->handlers[index] = (handler_info **) xmalloc ((count + extra) 
   						    * sizeof (handler_info **));
 
   /* First put all our handlers into the list.  */
@@ -3007,9 +3002,8 @@ init_eh_nesting_info ()
   rtx insn;
   int x;
 
-  info = (eh_nesting_info *) malloc (sizeof (eh_nesting_info));
-  info->region_index = (int *) malloc ((max_label_num () + 1) * sizeof (int));
-  bzero ((char *) info->region_index, (max_label_num () + 1) * sizeof (int));
+  info = (eh_nesting_info *) xmalloc (sizeof (eh_nesting_info));
+  info->region_index = (int *) xcalloc ((max_label_num () + 1), sizeof (int));
 
   nested_eh_region = (int *) alloca ((max_label_num () + 1) * sizeof (int));
   bzero ((char *) nested_eh_region, (max_label_num () + 1) * sizeof (int));
@@ -3048,14 +3042,10 @@ init_eh_nesting_info ()
     }
 
   region_count++;
-  info->handlers = (handler_info ***) malloc (region_count 
-					      * sizeof (handler_info ***));
-  info->num_handlers = (int *) malloc (region_count * sizeof (int));
-  info->outer_index = (int *) malloc (region_count * sizeof (int));
-
-  bzero ((char *) info->handlers, region_count * sizeof (rtx *));
-  bzero ((char *) info->num_handlers, region_count * sizeof (int));
-  bzero ((char *) info->outer_index, region_count * sizeof (int));
+  info->handlers = (handler_info ***) xcalloc (region_count,
+					       sizeof (handler_info ***));
+  info->num_handlers = (int *) xcalloc (region_count, sizeof (int));
+  info->outer_index = (int *) xcalloc (region_count, sizeof (int));
 
  /* Now initialize the handler lists for all exception blocks.  */
   for (x = 0; x <= max_label_num (); x++)
diff -rup orig/egcs-CVS19990904/gcc/gcc.c egcs-CVS19990904/gcc/gcc.c
--- orig/egcs-CVS19990904/gcc/gcc.c	Fri Aug 27 09:44:08 1999
+++ egcs-CVS19990904/gcc/gcc.c	Sat Sep  4 12:18:55 1999
@@ -1056,26 +1056,6 @@ translate_options (argcp, argvp)
   *argcp = newindex;
 }
 
-char *
-xstrerror(e)
-     int e;
-{
-#ifdef HAVE_STRERROR
-
-  return strerror(e);
-
-#else
-
-  if (!e)
-    return "errno = 0";
-
-  if (e > 0 && e < sys_nerr)
-    return sys_errlist[e];
-
-  return "errno = ?";
-#endif
-}
-
 static char *
 skip_whitespace (p)
      char *p;
@@ -1181,10 +1161,8 @@ init_spec ()
 
 #ifdef EXTRA_SPECS
   extra_specs = (struct spec_list *)
-    xmalloc (sizeof(struct spec_list) *
+    xcalloc (sizeof(struct spec_list),
 	     (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
-  bzero ((PTR) extra_specs, sizeof(struct spec_list) *
-	 (sizeof(extra_specs_1)/sizeof(extra_specs_1[0])));
   
   for (i = (sizeof(extra_specs_1) / sizeof(extra_specs_1[0])) - 1; i >= 0; i--)
     {
@@ -1246,7 +1224,7 @@ set_spec (name, spec)
     {
       /* Not found - make it */
       sl = (struct spec_list *) xmalloc (sizeof (struct spec_list));
-      sl->name = save_string (name, strlen (name));
+      sl->name = xstrdup (name);
       sl->name_len = name_len;
       sl->ptr_spec = &sl->ptr;
       sl->alloc_p = 0;
@@ -1258,7 +1236,7 @@ set_spec (name, spec)
   old_spec = *(sl->ptr_spec);
   *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
 		     ? concat (old_spec, spec + 1, NULL_PTR)
-		     : save_string (spec, strlen (spec)));
+		     : xstrdup (spec));
 
 #ifdef DEBUG_SPECS
   if (verbose_flag)
@@ -1740,9 +1718,7 @@ record_temp_file (filename, always_delet
      int always_delete;
      int fail_delete;
 {
-  register char *name;
-  name = xmalloc (strlen (filename) + 1);
-  strcpy (name, filename);
+  register char * const name = xstrdup (filename);
 
   if (always_delete)
     {
@@ -1993,23 +1969,13 @@ find_a_file (pprefix, name, mode)
   int len = pprefix->max_len + strlen (name) + strlen (file_suffix) + 1;
 
 #ifdef DEFAULT_ASSEMBLER
-  if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) {
-    name = DEFAULT_ASSEMBLER;
-    len = strlen(name)+1;
-    temp = xmalloc (len);
-    strcpy (temp, name);
-    return temp;
-  }
+  if (! strcmp(name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
+    return xstrdup (DEFAULT_ASSEMBLER);
 #endif
 
 #ifdef DEFAULT_LINKER
-  if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0) {
-    name = DEFAULT_LINKER;
-    len = strlen(name)+1;
-    temp = xmalloc (len);
-    strcpy (temp, name);
-    return temp;
-  }
+  if (! strcmp(name, "ld") && access (DEFAULT_LINKER, mode) == 0)
+    return xstrdup (DEFAULT_LINKER);
 #endif
 
   if (machine_suffix)
@@ -2610,8 +2576,8 @@ process_command (argc, argv)
 
   /* Figure compiler version from version string.  */
 
-  compiler_version = temp1 =
-    save_string (version_string, strlen (version_string));
+  compiler_version = temp1 = xstrdup (version_string); 
+
   for (; *temp1; ++temp1)
     {
       if (*temp1 == ' ')
@@ -5026,13 +4992,11 @@ main (argc, argv)
 
   i = n_infiles;
   i += lang_specific_extra_outfiles;
-  outfiles = (const char **) xmalloc (i * sizeof (char *));
-  bzero ((char *) outfiles, i * sizeof (char *));
+  outfiles = (const char **) xcalloc (i, sizeof (char *));
 
   /* Record which files were specified explicitly as link input.  */
 
-  explicit_link_files = xmalloc (n_infiles);
-  bzero (explicit_link_files, n_infiles);
+  explicit_link_files = xcalloc (1, n_infiles);
 
   for (i = 0; (int)i < n_infiles; i++)
     {
@@ -5257,31 +5221,6 @@ lookup_compiler (name, length, language)
   return 0;
 }
 
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR value = (PTR) malloc (size);
-  if (value == 0)
-    fatal ("virtual memory exhausted");
-  return value;
-}
-
-PTR
-xrealloc (old, size)
-  PTR old;
-  size_t size;
-{
-  register PTR ptr;
-  if (old)
-    ptr = (PTR) realloc (old, size);
-  else
-    ptr = (PTR) malloc (size);
-  if (ptr == 0)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
 static char *
 save_string (s, len)
   const char *s;
diff -rup orig/egcs-CVS19990904/gcc/gcov.c egcs-CVS19990904/gcc/gcov.c
--- orig/egcs-CVS19990904/gcc/gcov.c	Thu Sep  2 07:42:23 1999
+++ egcs-CVS19990904/gcc/gcov.c	Sat Sep  4 12:00:03 1999
@@ -267,19 +267,6 @@ fnotice VPROTO ((FILE *file, const char 
 }
 
 
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR value = (PTR) malloc (size);
-  if (value == 0)
-    {
-      fnotice (stderr, "error: virtual memory exhausted");
-      exit (FATAL_EXIT_CODE);
-    }
-  return value;
-}
-
 /* More 'friendly' abort that prints the line and file.
    config.h can #define abort fancy_abort if you like that sort of thing.  */
 
@@ -508,10 +495,8 @@ create_program_flow_graph (bptr)
   /* Read the number of blocks.  */
   __read_long (&num_blocks, bbg_file, 4);
 
-  /* Create an array of size bb number of bb_info structs.  Bzero it.  */
-  bb_graph = (struct bb_info *) xmalloc (num_blocks
-					 * sizeof (struct bb_info));
-  bzero ((char *) bb_graph, sizeof (struct bb_info) * num_blocks);
+  /* Create an array of size bb number of bb_info structs.  */
+  bb_graph = (struct bb_info *) xcalloc (num_blocks, sizeof (struct bb_info));
 
   bptr->bb_graph = bb_graph;
   bptr->num_blocks = num_blocks;
@@ -802,8 +787,7 @@ scan_for_source_files ()
 	      /* No sourcefile structure for this file name exists, create
 		 a new one, and append it to the front of the sources list.  */
 	      s_ptr = (struct sourcefile *) xmalloc (sizeof(struct sourcefile));
-	      s_ptr->name = xmalloc (strlen ((char *) ptr) + 1);
-	      strcpy (s_ptr->name, (char *) ptr);
+	      s_ptr->name = xstrdup (ptr);
 	      s_ptr->maxlineno = 0;
 	      s_ptr->next = sources;
 	      sources = s_ptr;
@@ -1019,17 +1003,11 @@ output_data ()
       else
 	source_file_name = s_ptr->name;
 
-      line_counts = (long *) xmalloc (sizeof (long) * s_ptr->maxlineno);
-      bzero ((char *) line_counts, sizeof (long) * s_ptr->maxlineno);
-      line_exists = xmalloc (s_ptr->maxlineno);
-      bzero (line_exists, s_ptr->maxlineno);
+      line_counts = (long *) xcalloc (sizeof (long), s_ptr->maxlineno);
+      line_exists = xcalloc (1, s_ptr->maxlineno);
       if (output_branch_probs)
-	{
-	  branch_probs = (struct arcdata **) xmalloc (sizeof (struct arcdata *)
-						      * s_ptr->maxlineno);
-	  bzero ((char *) branch_probs, 
-		 sizeof (struct arcdata *) * s_ptr->maxlineno);
-	}
+	branch_probs = (struct arcdata **)
+	  xcalloc (sizeof (struct arcdata *), s_ptr->maxlineno);
       
       /* There will be a zero at the beginning of the bb info, before the
 	 first list of line numbers, so must initialize block_num to 0.  */
diff -rup orig/egcs-CVS19990904/gcc/haifa-sched.c egcs-CVS19990904/gcc/haifa-sched.c
--- orig/egcs-CVS19990904/gcc/haifa-sched.c	Sat Sep  4 07:41:58 1999
+++ egcs-CVS19990904/gcc/haifa-sched.c	Sat Sep  4 12:08:02 1999
@@ -7742,14 +7742,9 @@ schedule_insns (dump_file)
 
   max_uid = (get_max_uid () + 1);
 
-  cant_move = (char *) xmalloc (max_uid * sizeof (char));
-  bzero ((char *) cant_move, max_uid * sizeof (char));
-
-  fed_by_spec_load = (char *) xmalloc (max_uid * sizeof (char));
-  bzero ((char *) fed_by_spec_load, max_uid * sizeof (char));
-
-  is_load_insn = (char *) xmalloc (max_uid * sizeof (char));
-  bzero ((char *) is_load_insn, max_uid * sizeof (char));
+  cant_move = xcalloc (max_uid, sizeof (char));
+  fed_by_spec_load = xcalloc (max_uid, sizeof (char));
+  is_load_insn = xcalloc (max_uid, sizeof (char));
 
   insn_orig_block = (int *) xmalloc (max_uid * sizeof (int));
   insn_luid = (int *) xmalloc (max_uid * sizeof (int));
@@ -7877,17 +7872,17 @@ schedule_insns (dump_file)
      We use xmalloc instead of alloca, because max_uid can be very large
      when there is a lot of function inlining.  If we used alloca, we could
      exceed stack limits on some hosts for some inputs.  */
-  insn_priority = (int *) xmalloc (max_uid * sizeof (int));
-  insn_reg_weight = (int *) xmalloc (max_uid * sizeof (int));
-  insn_tick = (int *) xmalloc (max_uid * sizeof (int));
-  insn_costs = (short *) xmalloc (max_uid * sizeof (short));
-  insn_units = (short *) xmalloc (max_uid * sizeof (short));
-  insn_blockage = (unsigned int *) xmalloc (max_uid * sizeof (unsigned int));
-  insn_ref_count = (int *) xmalloc (max_uid * sizeof (int));
+  insn_priority = (int *) xcalloc (max_uid, sizeof (int));
+  insn_reg_weight = (int *) xcalloc (max_uid, sizeof (int));
+  insn_tick = (int *) xcalloc (max_uid, sizeof (int));
+  insn_costs = (short *) xcalloc (max_uid, sizeof (short));
+  insn_units = (short *) xcalloc (max_uid, sizeof (short));
+  insn_blockage = (unsigned int *) xcalloc (max_uid, sizeof (unsigned int));
+  insn_ref_count = (int *) xcalloc (max_uid, sizeof (int));
 
   /* Allocate for forward dependencies */
-  insn_dep_count = (int *) xmalloc (max_uid * sizeof (int));
-  insn_depend = (rtx *) xmalloc (max_uid * sizeof (rtx));
+  insn_dep_count = (int *) xcalloc (max_uid, sizeof (int));
+  insn_depend = (rtx *) xcalloc (max_uid, sizeof (rtx));
 
   if (reload_completed == 0)
     {
@@ -7915,8 +7910,7 @@ schedule_insns (dump_file)
     {
       rtx line;
 
-      line_note = (rtx *) xmalloc (max_uid * sizeof (rtx));
-      bzero ((char *) line_note, max_uid * sizeof (rtx));
+      line_note = (rtx *) xcalloc (max_uid, sizeof (rtx));
       line_note_head = (rtx *) alloca (n_basic_blocks * sizeof (rtx));
       bzero ((char *) line_note_head, n_basic_blocks * sizeof (rtx));
 
@@ -7934,18 +7928,6 @@ schedule_insns (dump_file)
 	      break;
 	    }
     }
-
-  bzero ((char *) insn_priority, max_uid * sizeof (int));
-  bzero ((char *) insn_reg_weight, max_uid * sizeof (int));
-  bzero ((char *) insn_tick, max_uid * sizeof (int));
-  bzero ((char *) insn_costs, max_uid * sizeof (short));
-  bzero ((char *) insn_units, max_uid * sizeof (short));
-  bzero ((char *) insn_blockage, max_uid * sizeof (unsigned int));
-  bzero ((char *) insn_ref_count, max_uid * sizeof (int));
-
-  /* Initialize for forward dependencies */
-  bzero ((char *) insn_depend, max_uid * sizeof (rtx));
-  bzero ((char *) insn_dep_count, max_uid * sizeof (int));
 
   /* Find units used in this fuction, for visualization */
   if (sched_verbose)


More information about the Gcc-patches mailing list