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

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


	This is part 2/2.  Okay to install?

		--Kaveh




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

	* 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/mips-tdump.c egcs-CVS19990904/gcc/mips-tdump.c
--- orig/egcs-CVS19990904/gcc/mips-tdump.c	Sun Jan 17 18:41:47 1999
+++ egcs-CVS19990904/gcc/mips-tdump.c	Sat Sep  4 10:50:49 1999
@@ -65,19 +65,6 @@ fatal(s)
   exit(FATAL_EXIT_CODE);
 }
 
-/* Same as `malloc' but report error if no memory available.  */
-/* Do this before size_t is fiddled with so it matches the prototype
-   in libiberty.h . */
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR value = (PTR) malloc (size);
-  if (value == 0)
-    fatal ("Virtual memory exhausted.");
-  return value;
-}
-
 /* Due to size_t being defined in sys/types.h and different
    in stddef.h, we have to do this by hand.....  Note, these
    types are correct for MIPS based systems, and may not be
@@ -928,7 +915,7 @@ print_symbol (sym_ptr, number, strbase, 
 	if (want_scope)
 	  {
 	    if (free_scope == (scope_t *) 0)
-	      scope_ptr = (scope_t *) malloc (sizeof (scope_t));
+	      scope_ptr = (scope_t *) xmalloc (sizeof (scope_t));
 	    else
 	      {
 		scope_ptr = free_scope;
@@ -982,7 +969,7 @@ print_symbol (sym_ptr, number, strbase, 
 	if (want_scope)
 	  {
 	    if (free_scope == (scope_t *) 0)
-	      scope_ptr = (scope_t *) malloc (sizeof (scope_t));
+	      scope_ptr = (scope_t *) xmalloc (sizeof (scope_t));
 	    else
 	      {
 		scope_ptr = free_scope;
@@ -1434,14 +1421,7 @@ read_tfile __proto((void))
 				    "Auxiliary symbols");
 
   if (sym_hdr.iauxMax > 0)
-    {
-      aux_used = calloc (sym_hdr.iauxMax, 1);
-      if (aux_used == (char *) 0)
-	{
-	  perror ("calloc");
-	  exit (1);
-	}
-    }
+    aux_used = xcalloc (sym_hdr.iauxMax, 1);
 
   l_strings = (char *) read_seek ((PTR_T) 0,
 				  sym_hdr.issMax,
diff -rup orig/egcs-CVS19990904/gcc/mips-tfile.c egcs-CVS19990904/gcc/mips-tfile.c
--- orig/egcs-CVS19990904/gcc/mips-tfile.c	Thu Jan 21 12:47:35 1999
+++ egcs-CVS19990904/gcc/mips-tfile.c	Sat Sep  4 11:23:37 1999
@@ -636,7 +636,6 @@ extern void	pfatal_with_name
 				__proto((const char *));
 extern void	fancy_abort	__proto((void));
        void	botch		__proto((const char *));
-extern void	xfree		__proto((PTR));
 
 extern void	fatal		PVPROTO((const char *format, ...)) ATTRIBUTE_PRINTF_1;
 extern void	error		PVPROTO((const char *format, ...)) ATTRIBUTE_PRINTF_1;
@@ -1693,7 +1692,6 @@ STATIC void	  free_thead		__proto((thead
 
 STATIC char	 *local_index		__proto((const char *, int));
 STATIC char	 *local_rindex		__proto((const char *, int));
-STATIC const char	 *my_strsignal		__proto((int));
 
 extern char  *mktemp			__proto((char *));
 extern long   strtol			__proto((const char *, char **, int));
@@ -5022,29 +5020,6 @@ main (argc, argv)
 }
 
 
-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 */
-}
-
 /* Catch a signal and exit without dumping core.  */
 
 STATIC void
@@ -5052,7 +5027,7 @@ catch_signal (signum)
      int signum;
 {
   (void) signal (signum, SIG_DFL);	/* just in case...  */
-  fatal (my_strsignal(signum));
+  fatal (strsignal(signum));
 }
 
 /* Print a fatal error message.  NAME is the text.
@@ -5111,10 +5086,7 @@ STATIC page_t *
 allocate_cluster (npages)
      Size_t npages;
 {
-  register page_t *value = (page_t *) calloc (npages, PAGE_USIZE);
-
-  if (value == 0)
-    fatal ("Virtual memory exhausted.");
+  register page_t *value = (page_t *) xcalloc (npages, PAGE_USIZE);
 
   if (debug > 3)
     fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
@@ -5297,7 +5269,7 @@ free_scope (ptr)
   alloc_counts[ (int)alloc_type_scope ].free_list.f_scope = ptr;
 
 #else
-  xfree ((PTR_T) ptr);
+  free ((PTR_T) ptr);
 #endif
 
 }
@@ -5454,7 +5426,7 @@ free_tag (ptr)
   alloc_counts[ (int)alloc_type_tag ].free_list.f_tag = ptr;
 
 #else
-  xfree ((PTR_T) ptr);
+  free ((PTR_T) ptr);
 #endif
 
 }
@@ -5512,7 +5484,7 @@ free_forward (ptr)
   alloc_counts[ (int)alloc_type_forward ].free_list.f_forward = ptr;
 
 #else
-  xfree ((PTR_T) ptr);
+  free ((PTR_T) ptr);
 #endif
 
 }
@@ -5570,7 +5542,7 @@ free_thead (ptr)
   alloc_counts[ (int)alloc_type_thead ].free_list.f_thead = ptr;
 
 #else
-  xfree ((PTR_T) ptr);
+  free ((PTR_T) ptr);
 #endif
 
 }
@@ -5659,89 +5631,6 @@ botch (s)
      const char *s;
 {
   fatal (s);
-}
-
-/* Same as `malloc' but report error if no memory available.  */
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR value = (PTR) malloc (size);
-  if (value == 0)
-    fatal ("Virtual memory exhausted.");
-
-  if (debug > 3)
-    {
-      fputs ("\tmalloc\tptr = ", stderr);
-      fprintf (stderr, HOST_PTR_PRINTF, value);
-      fprintf (stderr, ", size = %10lu\n", (unsigned long) size);
-    }
-
-  return value;
-}
-
-/* Same as `calloc' but report error if no memory available.  */
-
-PTR
-xcalloc (size1, size2)
-  size_t size1, size2;
-{
-  register PTR value = (PTR) calloc (size1, size2);
-  if (value == 0)
-    fatal ("Virtual memory exhausted.");
-
-  if (debug > 3)
-    {
-      fputs ("\tcalloc\tptr = ", stderr);
-      fprintf (stderr, HOST_PTR_PRINTF, value);
-      fprintf (stderr, ", size1 = %10lu, size2 = %10lu [%lu]\n",
-	       (unsigned long) size1, (unsigned long) size2,
-	       (unsigned long) size1*size2);
-    }
-
-  return value;
-}
-
-/* Same as `realloc' but report error if no memory available.  */
-
-PTR
-xrealloc (ptr, size)
-  PTR ptr;
-  size_t size;
-{
-  register PTR result;
-  if (ptr)
-    result = (PTR) realloc (ptr, size);
-  else
-    result = (PTR) malloc (size);
-  if (!result)
-    fatal ("Virtual memory exhausted.");
-
-  if (debug > 3)
-    {
-      fputs ("\trealloc\tptr = ", stderr);
-      fprintf (stderr, HOST_PTR_PRINTF, result);
-      fprintf (stderr, ", size = %10lu, orig = ", size);
-      fprintf (stderr, HOST_PTR_PRINTF, ptr);
-      fputs ("\n", stderr);
-    }
-
-  return result;
-}
-
-void
-xfree (ptr)
-     PTR ptr;
-{
-  if (debug > 3)
-    {
-      fputs ("\tfree\tptr = ", stderr);
-      fprintf (stderr, HOST_PTR_PRINTF, ptr);
-      fputs ("\n", stderr);
-    }
-
-  free (ptr);
 }
 
 
diff -rup orig/egcs-CVS19990904/gcc/objc/objc-act.c egcs-CVS19990904/gcc/objc/objc-act.c
--- orig/egcs-CVS19990904/gcc/objc/objc-act.c	Fri Sep  3 01:24:06 1999
+++ egcs-CVS19990904/gcc/objc/objc-act.c	Sat Sep  4 13:05:44 1999
@@ -630,13 +630,11 @@ lang_init ()
   /* If gen_declaration desired, open the output file.  */
   if (flag_gen_declaration)
     {
-      int dump_base_name_length = strlen (dump_base_name);
-      register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
-      strcpy (dumpname, dump_base_name);
-      strcat (dumpname, ".decl");
+      register char * const dumpname = concat (dumpname, ".decl", NULL);
       gen_declaration_file = fopen (dumpname, "w");
       if (gen_declaration_file == 0)
 	pfatal_with_name (dumpname);
+      free (dumpname);
     }
 
   if (flag_next_runtime)
diff -rup orig/egcs-CVS19990904/gcc/prefix.c egcs-CVS19990904/gcc/prefix.c
--- orig/egcs-CVS19990904/gcc/prefix.c	Sat Aug 14 22:53:30 1999
+++ egcs-CVS19990904/gcc/prefix.c	Sat Sep  4 12:29:23 1999
@@ -282,7 +226,7 @@ translate_name (name)
   /* Remove any trailing directory separator from what we got.  */
   if (IS_DIR_SEPARATOR (prefix[strlen (prefix) - 1]))
     {
-      char * temp = save_string (prefix, strlen (prefix));
+      char * temp = xstrdup (prefix);
       temp[strlen (temp) - 1] = 0;
       prefix = temp;
     }
@@ -312,28 +256,24 @@ update_path (path, key)
   /* Convert DIR_SEPARATOR_2 to DIR_SEPARATOR. */
   if (DIR_SEPARATOR != DIR_SEPARATOR_2)
     {
-      int i;
-      int len = strlen (path);
-      char *new_path = save_string (path, len);
-      for (i = 0; i < len; i++)
-        if (new_path[i] == DIR_SEPARATOR_2)
-          new_path[i] = DIR_SEPARATOR;
+      char *new_path = xstrdup (path);
       path = new_path;
+      do {
+	if (*new_path == DIR_SEPARATOR_2)
+	  *new_path = DIR_SEPARATOR;
+      } while (*new_path++);
     }
 #endif
       
 #if defined (DIR_SEPARATOR) && !defined (DIR_SEPARATOR_2)
   if (DIR_SEPARATOR != '/')
     {
-      int i;
-      int len = strlen (path);
-      char *new_path = save_string (path, len);
-
-      for (i = 0; i < len; i++)
-        if (new_path[i] == '/')
-          new_path[i] = DIR_SEPARATOR;
-
+      char *new_path = xstrdup (path);
       path = new_path;
+      do {
+	if (*new_path == '/')
+	  *new_path = DIR_SEPARATOR;
+      } while (*newpath++);
     }
 #endif
 
diff -rup orig/egcs-CVS19990904/gcc/profile.c egcs-CVS19990904/gcc/profile.c
--- orig/egcs-CVS19990904/gcc/profile.c	Mon Aug  9 15:42:09 1999
+++ egcs-CVS19990904/gcc/profile.c	Sat Sep  4 12:13:10 1999
@@ -562,9 +562,7 @@ branch_prob (f, dump_file)
 		      {
 			if (last_bb_file_name)
 			  free (last_bb_file_name);
-			last_bb_file_name
-			  = xmalloc (strlen (NOTE_SOURCE_FILE (insn)) + 1);
-			strcpy (last_bb_file_name, NOTE_SOURCE_FILE (insn));
+			last_bb_file_name = xstrdup (NOTE_SOURCE_FILE (insn));
 			output_gcov_string (NOTE_SOURCE_FILE (insn), (long)-1);
 		      }
 
diff -rup orig/egcs-CVS19990904/gcc/protoize.c egcs-CVS19990904/gcc/protoize.c
--- orig/egcs-CVS19990904/gcc/protoize.c	Thu Sep  2 07:42:26 1999
+++ egcs-CVS19990904/gcc/protoize.c	Sat Sep  4 12:16:29 1999
@@ -600,73 +600,6 @@ notice VPARAMS ((const char *msgid, ...)
 }
 
 
-char *
-xstrerror(e)
-     int e;
-{
-
-#ifdef HAVE_STRERROR
-  return strerror(e);
-
-#else
-  if (!e)
-    return "";
-
-  if (e > 0 && e < sys_nerr)
-    return sys_errlist[e];
-
-  return "errno = ?";
-#endif
-}
-
-/* Allocate some space, but check that the allocation was successful.  */
-/* alloca.c uses this, so don't make it static.  */
-
-pointer_type
-xmalloc (byte_count)
-     size_t byte_count;
-{
-  register pointer_type rv = (pointer_type) malloc (byte_count);
-  if (rv == NULL)
-    {
-      notice ("\n%s: virtual memory exceeded\n", pname);
-      exit (FATAL_EXIT_CODE);
-    }
-  return rv;
-}
-
-/* Reallocate some space, but check that the reallocation was successful.  */
-
-pointer_type
-xrealloc (old_space, byte_count)
-     pointer_type old_space;
-     size_t byte_count;
-{
-  register pointer_type rv;
-  if (old_space)
-    rv = (pointer_type) realloc (old_space, byte_count);
-  else
-    rv = (pointer_type) malloc (byte_count);
-  if (rv == NULL)
-    {
-      notice ("\n%s: virtual memory exceeded\n", pname);
-      exit (FATAL_EXIT_CODE);
-    }
-  return rv;
-}
-
-/* Deallocate the area pointed to by an arbitrary pointer, but first, strip
-   the `const' qualifier from it and also make sure that the pointer value
-   is non-null.  */
-
-void
-xfree (p)
-     const_pointer_type p;
-{
-  if (p)
-    free ((NONCONST pointer_type) p);
-}
-
 /* Make a copy of a string INPUT with size SIZE.  */
 
 static char *
@@ -679,21 +612,6 @@ savestring (input, size)
   return output;
 }
 
-/* Make a copy of the concatenation of INPUT1 and INPUT2.  */
-
-static char *
-savestring2 (input1, size1, input2, size2)
-     const char *input1;
-     unsigned int size1;
-     const char *input2;
-     unsigned int size2;
-{
-  char *output = (char *) xmalloc (size1 + size2 + 1);
-  strcpy (output, input1);
-  strcpy (&output[size1], input2);
-  return output;
-}
-
 /* More 'friendly' abort that prints the line and file.
    config.h can #define abort fancy_abort if you like that sort of thing.  */
 
@@ -1109,7 +1027,7 @@ add_symbol (p, s)
      const char *s;
 {
   p->hash_next = NULL;
-  p->symbol = savestring (s, strlen (s));
+  p->symbol = xstrdup (s);
   p->ddip = NULL;
   p->fip = NULL;
   return p;
@@ -1157,7 +1075,7 @@ static void
 free_def_dec (p)
      def_dec_info *p;
 {
-  xfree (p->ansi_decl);
+  free ((NONCONST pointer_type) p->ansi_decl);
 
 #ifndef UNPROTOIZE
   {
@@ -1167,12 +1085,12 @@ free_def_dec (p)
     for (curr = p->f_list_chain; curr; curr = next)
       {
         next = curr->chain_next;
-        xfree (curr);
+        free ((NONCONST pointer_type) curr);
       }
   }
 #endif /* !defined (UNPROTOIZE) */
 
-  xfree (p);
+  free (p);
 }
 
 /* Unexpand as many macro symbol as we can find.
@@ -2072,12 +1990,9 @@ gen_aux_info_file (base_filename)
   /* Store the full source file name in the argument vector.  */
   compile_params[input_file_name_index] = shortpath (NULL, base_filename);
   /* Add .X to source file name to get aux-info file name.  */
-  compile_params[aux_info_file_name_index]
-    = savestring2 (compile_params[input_file_name_index],
-	           strlen (compile_params[input_file_name_index]),
-		   ".X",
-		   2);
-
+  compile_params[aux_info_file_name_index] =
+    concat (compile_params[input_file_name_index], ".X", NULL);
+  
   if (!quiet_flag)
     notice ("%s: compiling `%s'\n",
 	    pname, compile_params[input_file_name_index]);
@@ -2382,7 +2297,7 @@ start_over: ;
             if (referenced_file_is_newer (aux_info_p, aux_info_mtime))
               {
                 free (aux_info_base);
-		xfree (aux_info_relocated_name);
+		free (aux_info_relocated_name);
                 if (keep_it && my_unlink (aux_info_filename) == -1)
                   {
 		    int errno_val = errno;
@@ -2431,7 +2346,7 @@ start_over: ;
   }
 
   free (aux_info_base);
-  xfree (aux_info_relocated_name);
+  free (aux_info_relocated_name);
 }
 
 #ifndef UNPROTOIZE
diff -rup orig/egcs-CVS19990904/gcc/reload1.c egcs-CVS19990904/gcc/reload1.c
--- orig/egcs-CVS19990904/gcc/reload1.c	Fri Sep  3 01:04:33 1999
+++ egcs-CVS19990904/gcc/reload1.c	Sat Sep  4 12:49:29 1999
@@ -655,27 +655,20 @@ reload (first, global, dumpfile)
      Record memory equivalents in reg_mem_equiv so they can
      be substituted eventually by altering the REG-rtx's.  */
 
-  reg_equiv_constant = (rtx *) xmalloc (max_regno * sizeof (rtx));
-  bzero ((char *) reg_equiv_constant, max_regno * sizeof (rtx));
-  reg_equiv_memory_loc = (rtx *) xmalloc (max_regno * sizeof (rtx));
-  bzero ((char *) reg_equiv_memory_loc, max_regno * sizeof (rtx));
-  reg_equiv_mem = (rtx *) xmalloc (max_regno * sizeof (rtx));
-  bzero ((char *) reg_equiv_mem, max_regno * sizeof (rtx));
-  reg_equiv_init = (rtx *) xmalloc (max_regno * sizeof (rtx));
-  bzero ((char *) reg_equiv_init, max_regno * sizeof (rtx));
-  reg_equiv_address = (rtx *) xmalloc (max_regno * sizeof (rtx));
-  bzero ((char *) reg_equiv_address, max_regno * sizeof (rtx));
-  reg_max_ref_width = (int *) xmalloc (max_regno * sizeof (int));
-  bzero ((char *) reg_max_ref_width, max_regno * sizeof (int));
-  reg_old_renumber = (short *) xmalloc (max_regno * sizeof (short));
+  reg_equiv_constant = (rtx *) xcalloc (max_regno, sizeof (rtx));
+  reg_equiv_memory_loc = (rtx *) xcalloc (max_regno, sizeof (rtx));
+  reg_equiv_mem = (rtx *) xcalloc (max_regno, sizeof (rtx));
+  reg_equiv_init = (rtx *) xcalloc (max_regno, sizeof (rtx));
+  reg_equiv_address = (rtx *) xcalloc (max_regno, sizeof (rtx));
+  reg_max_ref_width = (int *) xcalloc (max_regno, sizeof (int));
+  reg_old_renumber = (short *) xcalloc (max_regno, sizeof (short));
   bcopy ((PTR) reg_renumber, (PTR) reg_old_renumber, max_regno * sizeof (short));
   pseudo_forbidden_regs
     = (HARD_REG_SET *) xmalloc (max_regno * sizeof (HARD_REG_SET));
   pseudo_previous_regs
-    = (HARD_REG_SET *) xmalloc (max_regno * sizeof (HARD_REG_SET));
+    = (HARD_REG_SET *) xcalloc (max_regno, sizeof (HARD_REG_SET));
 
   CLEAR_HARD_REG_SET (bad_spill_regs_global);
-  bzero ((char *) pseudo_previous_regs, max_regno * sizeof (HARD_REG_SET));
 
   /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
      Also find all paradoxical subregs and find largest such for each pseudo.
@@ -3731,12 +3724,8 @@ init_elim_table ()
 #endif
 
   if (!reg_eliminate)
-    {
-      reg_eliminate = (struct elim_table *)
-	xmalloc(sizeof(struct elim_table) * NUM_ELIMINABLE_REGS);
-      bzero ((PTR) reg_eliminate,
-	     sizeof(struct elim_table) * NUM_ELIMINABLE_REGS);
-    }
+    reg_eliminate = (struct elim_table *)
+      xcalloc(sizeof(struct elim_table), NUM_ELIMINABLE_REGS);
 
   /* Does this function require a frame pointer?  */
 
diff -rup orig/egcs-CVS19990904/gcc/resource.c egcs-CVS19990904/gcc/resource.c
--- orig/egcs-CVS19990904/gcc/resource.c	Tue Aug 31 22:04:56 1999
+++ egcs-CVS19990904/gcc/resource.c	Sat Sep  4 12:50:37 1999
@@ -1167,14 +1167,9 @@ init_resource_info (epilogue_insn)
     mark_set_resources (epilogue_insn, &end_of_function_needs, 0, 1);
 
   /* Allocate and initialize the tables used by mark_target_live_regs.  */
-  target_hash_table
-    = (struct target_info **) xmalloc ((TARGET_HASH_PRIME
-				       * sizeof (struct target_info *)));
-  bzero ((char *) target_hash_table,
-	 TARGET_HASH_PRIME * sizeof (struct target_info *));
-
-  bb_ticks = (int *) xmalloc (n_basic_blocks * sizeof (int));
-  bzero ((char *) bb_ticks, n_basic_blocks * sizeof (int));
+  target_hash_table = (struct target_info **)
+    xcalloc (TARGET_HASH_PRIME, sizeof (struct target_info *));
+  bb_ticks = (int *) xcalloc (n_basic_blocks, sizeof (int));
 }
 
 /* Free up the resources allcated to mark_target_live_regs ().  This
diff -rup orig/egcs-CVS19990904/gcc/stupid.c egcs-CVS19990904/gcc/stupid.c
--- orig/egcs-CVS19990904/gcc/stupid.c	Fri Aug 20 18:47:09 1999
+++ egcs-CVS19990904/gcc/stupid.c	Sat Sep  4 12:53:03 1999
@@ -220,36 +220,22 @@ stupid_life_analysis (f, nregs, file)
 
   /* Allocate tables to record info about regs.  */
 
-  reg_where_dead = (int *) xmalloc (nregs * sizeof (int));
-  bzero ((char *) reg_where_dead, nregs * sizeof (int));
-
-  reg_where_born_exact = (int *) xmalloc (nregs * sizeof (int));
-  bzero ((char *) reg_where_born_exact, nregs * sizeof (int));
-
-  reg_where_born_clobber = (int *) xmalloc (nregs * sizeof (int));
-  bzero ((char *) reg_where_born_clobber, nregs * sizeof (int));
-
-  reg_where_dead_chain = (struct insn_chain **) xmalloc (nregs * sizeof (struct insn_chain *));
-  bzero ((char *) reg_where_dead_chain, nregs * sizeof (struct insn_chain *));
- 
-  reg_order = (int *) xmalloc (nregs * sizeof (int));
-  bzero ((char *) reg_order, nregs * sizeof (int));
-
-  regs_change_size = (char *) xmalloc (nregs * sizeof (char));
-  bzero ((char *) regs_change_size, nregs * sizeof (char));
-
-  regs_crosses_setjmp = (char *) xmalloc (nregs * sizeof (char));
-  bzero ((char *) regs_crosses_setjmp, nregs * sizeof (char));
+  reg_where_dead = (int *) xcalloc (nregs, sizeof (int));
+  reg_where_born_exact = (int *) xcalloc (nregs, sizeof (int));
+  reg_where_born_clobber = (int *) xcalloc (nregs, sizeof (int));
+  reg_where_dead_chain = (struct insn_chain **)
+    xcalloc (nregs, sizeof (struct insn_chain *));
+  reg_order = (int *) xcalloc (nregs, sizeof (int));
+  regs_change_size = (char *) xcalloc (nregs, sizeof (char));
+  regs_crosses_setjmp = (char *) xcalloc (nregs, sizeof (char));
 
   /* Allocate the reg_renumber array */
   allocate_reg_info (max_regno, FALSE, TRUE);
   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     reg_renumber[i] = i;
 
-  after_insn_hard_regs
-    = (HARD_REG_SET *) xmalloc (max_suid * sizeof (HARD_REG_SET));
-
-  bzero ((char *) after_insn_hard_regs, max_suid * sizeof (HARD_REG_SET));
+  after_insn_hard_regs =
+    (HARD_REG_SET *) xcalloc (max_suid, sizeof (HARD_REG_SET));
 
   /* Allocate and zero out many data structures
      that will record the data from lifetime analysis.  */
diff -rup orig/egcs-CVS19990904/gcc/toplev.c egcs-CVS19990904/gcc/toplev.c
--- orig/egcs-CVS19990904/gcc/toplev.c	Thu Sep  2 07:42:32 1999
+++ egcs-CVS19990904/gcc/toplev.c	Sat Sep  4 12:57:23 1999
@@ -2276,76 +2276,6 @@ botch (s)
 {
   abort ();
 }
-
-/* Same as `malloc' but report error if no memory available.  */
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR value;
-
-  if (size == 0)
-    size = 1;
-
-  value = (PTR) malloc (size);
-  if (value == 0)
-    fatal ("virtual memory exhausted");
-  return value;
-}
-
-/* Same as `calloc' but report error if no memory available.  */
-
-PTR
-xcalloc (size1, size2)
-  size_t size1, size2;
-{
-  register PTR value;
-
-  if (size1 == 0 || size2 == 0)
-    size1 = size2 = 1;
-
-  value = (PTR) calloc (size1, size2);
-  if (value == 0)
-    fatal ("virtual memory exhausted");
-  return value;
-}
-
-
-/* Same as `realloc' but report error if no memory available.  
-   Also handle null PTR even if the vendor realloc gets it wrong.  */
-
-PTR
-xrealloc (ptr, size)
-  PTR ptr;
-  size_t size;
-{
-  register PTR result;
-
-  if (size == 0)
-    size = 1;
-
-  result = (ptr ? (PTR) realloc (ptr, size) : (PTR) malloc (size));
-
-  if (!result)
-    fatal ("virtual memory exhausted");
-
-  return result;
-}
-
-/* Same as `strdup' but report error if no memory available.  */
-
-char *
-xstrdup (s)
-  register const char *s;
-{
-  register char *result = (char *) malloc (strlen (s) + 1);
-
-  if (! result)
-    fatal ("virtual memory exhausted");
-  strcpy (result, s);
-  return result;
-}
 
 /* Return the logarithm of X, base 2, considering X unsigned,
    if X is a power of 2.  Otherwise, returns -1.
@@ -2592,14 +2522,11 @@ open_dump_file (suffix, function_name)
   TIMEVAR
     (dump_time,
      {
-       dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
+       dumpname = concat (dump_base_name, suffix, NULL);
 
        if (rtl_dump_file != NULL)
 	 fclose (rtl_dump_file);
   
-       strcpy (dumpname, dump_base_name);
-       strcat (dumpname, suffix);
-       
        rtl_dump_file = fopen (dumpname, "a");
        
        if (rtl_dump_file == NULL)
@@ -2652,13 +2579,8 @@ static void
 clean_dump_file (suffix)
   const char *suffix;
 {
-  char *dumpname;
+  char * const dumpname = concat (dump_base_name, suffix, NULL);
 
-  dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
-
-  strcpy (dumpname, dump_base_name);
-  strcat (dumpname, suffix);
-       
   rtl_dump_file = fopen (dumpname, "w");
 
   if (rtl_dump_file == NULL)
@@ -3097,10 +3019,7 @@ compile_file (name)
 	  strip_off_ending (dumpname, len);
 	  strcat (dumpname, ".s");
 	  if (asm_file_name == 0)
-	    {
-	      asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
-	      strcpy (asm_file_name, dumpname);
-	    }
+	    asm_file_name = xstrdup (dumpname);
 	  if (!strcmp (asm_file_name, "-"))
 	    asm_out_file = stdout;
 	  else


More information about the Gcc-patches mailing list