collapse N copies of xmalloc

Zack Weinberg zack@wolery.cumb.org
Thu May 18 11:48:00 GMT 2000


All the genfoo programs have a private copy of xmalloc.  Now we have
gensupport.c, we can collapse all those private copies into there.
The exceptions are gencheck.c and gengenrtl.c, which are not really
"genfoo programs" in the sense of reading md files.  It's not as good
as getting them linked with libiberty, but it's an improvement.

"make clean; make LANGUAGES=c" completes successfully on i386-linux.

zw

	* gensupport.c (xmalloc, xrealloc, xstrdup): Provide.
	* genattr.c, genattrtab.c, gencodes.c, genconfig.c, genemit.c,
	genextract.c, genflags.c, genopinit.c, genoutput.c, genpeep.c,
	genrecog.c: Remove private copies of xmalloc, xrealloc, and
	xstrdup.
===================================================================
Index: genattr.c
--- genattr.c	2000/05/06 22:30:12	1.35
+++ genattr.c	2000/05/18 18:42:36
@@ -183,32 +183,6 @@ write_units (num_units, multiplicity, si
   printf ("#define INSN_QUEUE_SIZE %d\n", q_size);
 }
 
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
 extern int main PARAMS ((int, char **));
 
 int
===================================================================
Index: genattrtab.c
--- genattrtab.c	2000/05/06 22:30:12	1.76
+++ genattrtab.c	2000/05/18 18:42:41
@@ -5856,32 +5856,6 @@ extend_range (range, min, max)
   if (range->max < max) range->max = max;
 }
 
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
 static rtx
 copy_rtx_unchanging (orig)
      register rtx orig;
===================================================================
Index: gencodes.c
--- gencodes.c	2000/05/06 22:30:12	1.30
+++ gencodes.c	2000/05/18 18:42:41
@@ -45,32 +45,6 @@ gen_insn (insn)
 	    insn_code_number);
 }
 
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
 extern int main PARAMS ((int, char **));
 
 int
===================================================================
Index: genconfig.c
--- genconfig.c	2000/05/06 22:30:12	1.36
+++ genconfig.c	2000/05/18 18:42:41
@@ -238,33 +238,6 @@ gen_peephole (peep)
   for (i = 0; i < XVECLEN (peep, 0); i++)
     walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
 }
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
 
 extern int main PARAMS ((int, char **));
 
===================================================================
Index: genemit.c
--- genemit.c	2000/05/06 22:30:12	1.55
+++ genemit.c	2000/05/18 18:42:41
@@ -738,33 +738,6 @@ output_peephole2_scratches (split)
 	insn_nr++;
     }
 }
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
 
 extern int main PARAMS ((int, char **));
 
===================================================================
Index: genextract.c
--- genextract.c	2000/05/06 22:30:12	1.42
+++ genextract.c	2000/05/18 18:42:50
@@ -340,42 +340,6 @@ print_path (path)
     }
 }
 
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  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;
-}
-
 extern int main PARAMS ((int, char **));
 
 int
===================================================================
Index: genflags.c
--- genflags.c	2000/05/06 22:30:13	1.33
+++ genflags.c	2000/05/18 18:42:50
@@ -186,33 +186,6 @@ gen_insn (insn)
 
   obstack_grow (obstack_ptr, &insn, sizeof (rtx));
 }
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
 
 extern int main PARAMS ((int, char **));
 
===================================================================
Index: genopinit.c
--- genopinit.c	2000/05/06 22:30:13	1.39
+++ genopinit.c	2000/05/18 18:42:51
@@ -271,33 +268,6 @@ gen_insn (insn)
     }
 
   printf (";\n");
-}
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
 }
 
 extern int main PARAMS ((int, char **));
===================================================================
Index: genoutput.c
--- genoutput.c	2000/05/06 22:30:13	1.52
+++ genoutput.c	2000/05/18 18:42:51
@@ -862,32 +862,6 @@ gen_split (split)
 
   place_operands (d);
 }
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
 
 extern int main PARAMS ((int, char **));
 
===================================================================
Index: genpeep.c
--- genpeep.c	2000/05/06 22:30:13	1.43
+++ genpeep.c	2000/05/18 18:42:52
@@ -368,32 +368,6 @@ print_code (code)
   for (p1 = GET_RTX_NAME (code); *p1; p1++)
     putchar (TOUPPER(*p1));
 }
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
 
 extern int main PARAMS ((int, char **));
 
===================================================================
Index: genrecog.c
--- genrecog.c	2000/05/09 19:55:47	1.81
+++ genrecog.c	2000/05/18 18:42:53
@@ -2576,42 +2576,6 @@ record_insn_name (code, name)
   insn_name_ptr[code] = new;
 }  
 
-char *
-xstrdup (input)
-  const char *input;
-{
-  register size_t len = strlen (input) + 1;
-  register char *output = xmalloc (len);
-  memcpy (output, input, len);
-  return output;
-}
-
-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)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
-}
-
 static void
 debug_decision_2 (test)
      struct decision_test *test;
===================================================================
Index: gensupport.c
--- gensupport.c	2000/05/08 23:33:23	1.6
+++ gensupport.c	2000/05/18 18:42:53
@@ -847,3 +847,40 @@ read_md_rtx (lineno, seqnr)
 
   return desc;
 }
+
+/* Until we can use the versions in libiberty.  */
+char *
+xstrdup (input)
+  const char *input;
+{
+  register size_t len = strlen (input) + 1;
+  register char *output = xmalloc (len);
+  memcpy (output, input, len);
+  return output;
+}
+
+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)
+    fatal ("virtual memory exhausted");
+  return ptr;
+}
+
+PTR
+xmalloc (size)
+  size_t size;
+{
+  register PTR val = (PTR) malloc (size);
+
+  if (val == 0)
+    fatal ("virtual memory exhausted");
+  return val;
+}


More information about the Gcc-patches mailing list