Commit f4ce9d90 by Kaveh R. Ghazi Committed by Kaveh Ghazi

server.c (load_data, run_shell): Use xmalloc, xrealloc & xcalloc in lieu of…

server.c (load_data, run_shell): Use xmalloc, xrealloc & xcalloc in lieu of malloc, realloc & calloc.

	* fixinc/server.c (load_data, run_shell): Use xmalloc, xrealloc &
	xcalloc in lieu of malloc, realloc & calloc.

	* gencheck.c (xmalloc): Use really_call_malloc, not malloc.

	* gengenrtl.c (xmalloc): Likewise.

	* gensupport.c (xcalloc, xrealloc, xmalloc): Use the
	really_call_* memory allocation routines.

	* stmt.c (check_for_full_enumeration_handling): Use
	really_call_calloc, not calloc.

	* system.h (really_call_malloc, really_call_calloc,
	really_call_realloc): Define.
	(malloc, realloc, calloc, strdup, bzero, bcmp, rindex): Poison.

f:
	* fini.c (main): Use really_call_malloc, not malloc.

From-SVN: r40360
parent 0eac2984
2001-03-09 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* fixinc/server.c (load_data, run_shell): Use xmalloc, xrealloc &
xcalloc in lieu of malloc, realloc & calloc.
* gencheck.c (xmalloc): Use really_call_malloc, not malloc.
* gengenrtl.c (xmalloc): Likewise.
* gensupport.c (xcalloc, xrealloc, xmalloc): Use the
really_call_* memory allocation routines.
* stmt.c (check_for_full_enumeration_handling): Use
really_call_calloc, not calloc.
* system.h (really_call_malloc, really_call_calloc,
really_call_realloc): Define.
(malloc, realloc, calloc, strdup, bzero, bcmp, rindex): Poison.
Fri Mar 9 18:39:19 2001 Jeffrey A Law (law@cygnus.com) Fri Mar 9 18:39:19 2001 Jeffrey A Law (law@cygnus.com)
* pa.md (builtin_longjmp): Rework slightly to work for PA64 too. * pa.md (builtin_longjmp): Rework slightly to work for PA64 too.
......
Fri Mar 9 22:52:55 2001 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* fini.c (main): Use really_call_malloc, not malloc.
Thu Mar 8 13:27:47 2001 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> Thu Mar 8 13:27:47 2001 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* com.c: Don't rely on the POSIX macro to define autoconf stuff. * com.c: Don't rely on the POSIX macro to define autoconf stuff.
......
...@@ -367,7 +367,7 @@ main (int argc, char **argv) ...@@ -367,7 +367,7 @@ main (int argc, char **argv)
/* Make new name object to store name and its keyword. */ /* Make new name object to store name and its keyword. */
newname = (name) malloc (sizeof (*newname)); newname = (name) really_call_malloc (sizeof (*newname));
newname->namelen = strlen (buf); newname->namelen = strlen (buf);
newname->kwlen = strlen (kwname); newname->kwlen = strlen (kwname);
total_length = newname->kwlen + fixlengths; total_length = newname->kwlen + fixlengths;
......
...@@ -93,10 +93,7 @@ load_data (fp) ...@@ -93,10 +93,7 @@ load_data (fp)
t_bool got_done = BOOL_FALSE; t_bool got_done = BOOL_FALSE;
text_size = sizeof (z_line) * 2; text_size = sizeof (z_line) * 2;
pz_scan = pz_text = malloc (text_size); pz_scan = pz_text = xmalloc (text_size);
if (pz_text == (char *) NULL)
return (char *) NULL;
for (;;) for (;;)
{ {
...@@ -120,18 +117,9 @@ load_data (fp) ...@@ -120,18 +117,9 @@ load_data (fp)
if (text_size - used_ct < sizeof (z_line)) if (text_size - used_ct < sizeof (z_line))
{ {
size_t off = (size_t) (pz_scan - pz_text); size_t off = (size_t) (pz_scan - pz_text);
void *p;
text_size += 4096; text_size += 4096;
p = realloc ((void *) pz_text, text_size); pz_text = xrealloc ((void *) pz_text, text_size);
if (p == (void *) NULL)
{
fprintf (stderr, "Failed to get 0x%08lX bytes\n",
(long) text_size);
free ((void *) pz_text);
return (char *) NULL;
}
pz_text = (char *) p;
pz_scan = pz_text + off; pz_scan = pz_text + off;
} }
} }
...@@ -146,7 +134,7 @@ load_data (fp) ...@@ -146,7 +134,7 @@ load_data (fp)
while ((pz_scan > pz_text) && ISSPACE (pz_scan[-1])) while ((pz_scan > pz_text) && ISSPACE (pz_scan[-1]))
pz_scan--; pz_scan--;
*pz_scan = NUL; *pz_scan = NUL;
return realloc ((void *) pz_text, strlen (pz_text) + 1); return xrealloc ((void *) pz_text, strlen (pz_text) + 1);
} }
...@@ -284,11 +272,8 @@ run_shell (pz_cmd) ...@@ -284,11 +272,8 @@ run_shell (pz_cmd)
/* IF it is still not running, THEN return the nil string. */ /* IF it is still not running, THEN return the nil string. */
if (server_id <= 0) if (server_id <= 0)
{ {
char *pz = (char *) malloc (1);
fprintf (stderr, zNoServer, pz_cmd); fprintf (stderr, zNoServer, pz_cmd);
if (pz != (char *) NULL) return xcalloc (1, 1);
*pz = '\0';
return pz;
} }
/* Make sure the process will pay attention to us, send the /* Make sure the process will pay attention to us, send the
...@@ -302,11 +287,8 @@ run_shell (pz_cmd) ...@@ -302,11 +287,8 @@ run_shell (pz_cmd)
THEN return an empty string. */ THEN return an empty string. */
if (server_id == NULLPROCESS) if (server_id == NULLPROCESS)
{ {
char *pz = (char *) malloc (1);
fprintf (stderr, zNoServer, pz_cmd); fprintf (stderr, zNoServer, pz_cmd);
if (pz != (char *) NULL) return xcalloc (1, 1);
*pz = '\0';
return pz;
} }
/* Now try to read back all the data. If we fail due to either a /* Now try to read back all the data. If we fail due to either a
...@@ -326,9 +308,7 @@ run_shell (pz_cmd) ...@@ -326,9 +308,7 @@ run_shell (pz_cmd)
fprintf (stderr, "CLOSING SHELL SERVER - command failure:\n\t%s\n", fprintf (stderr, "CLOSING SHELL SERVER - command failure:\n\t%s\n",
pz_cmd); pz_cmd);
pz = (char *) malloc (1); pz = xcalloc (1, 1);
if (pz != (char *) NULL)
*pz = '\0';
} }
#ifdef DEBUG #ifdef DEBUG
fprintf( stderr, "run_shell command success: %s\n", pz ); fprintf( stderr, "run_shell command success: %s\n", pz );
......
...@@ -75,7 +75,7 @@ PTR ...@@ -75,7 +75,7 @@ PTR
xmalloc (nbytes) xmalloc (nbytes)
size_t nbytes; size_t nbytes;
{ {
register PTR tmp = (PTR) malloc (nbytes); register PTR tmp = (PTR) really_call_malloc (nbytes);
if (!tmp) if (!tmp)
{ {
......
...@@ -389,7 +389,7 @@ PTR ...@@ -389,7 +389,7 @@ PTR
xmalloc (nbytes) xmalloc (nbytes)
size_t nbytes; size_t nbytes;
{ {
register PTR tmp = (PTR) malloc (nbytes); register PTR tmp = (PTR) really_call_malloc (nbytes);
if (!tmp) if (!tmp)
{ {
......
...@@ -871,7 +871,7 @@ xcalloc (nelem, elsize) ...@@ -871,7 +871,7 @@ xcalloc (nelem, elsize)
if (nelem == 0 || elsize == 0) if (nelem == 0 || elsize == 0)
nelem = elsize = 1; nelem = elsize = 1;
newmem = calloc (nelem, elsize); newmem = really_call_calloc (nelem, elsize);
if (!newmem) if (!newmem)
fatal ("virtual memory exhausted"); fatal ("virtual memory exhausted");
return (newmem); return (newmem);
...@@ -884,9 +884,9 @@ xrealloc (old, size) ...@@ -884,9 +884,9 @@ xrealloc (old, size)
{ {
register PTR ptr; register PTR ptr;
if (old) if (old)
ptr = (PTR) realloc (old, size); ptr = (PTR) really_call_realloc (old, size);
else else
ptr = (PTR) malloc (size); ptr = (PTR) really_call_malloc (size);
if (!ptr) if (!ptr)
fatal ("virtual memory exhausted"); fatal ("virtual memory exhausted");
return ptr; return ptr;
...@@ -896,7 +896,7 @@ PTR ...@@ -896,7 +896,7 @@ PTR
xmalloc (size) xmalloc (size)
size_t size; size_t size;
{ {
register PTR val = (PTR) malloc (size); register PTR val = (PTR) really_call_malloc (size);
if (val == 0) if (val == 0)
fatal ("virtual memory exhausted"); fatal ("virtual memory exhausted");
......
...@@ -5193,7 +5193,8 @@ check_for_full_enumeration_handling (type) ...@@ -5193,7 +5193,8 @@ check_for_full_enumeration_handling (type)
/* We deliberately use calloc here, not cmalloc, so that we can suppress /* We deliberately use calloc here, not cmalloc, so that we can suppress
this optimization if we don't have enough memory rather than this optimization if we don't have enough memory rather than
aborting, as xmalloc would do. */ aborting, as xmalloc would do. */
&& (cases_seen = (unsigned char *) calloc (bytes_needed, 1)) != NULL) && (cases_seen =
(unsigned char *) really_call_calloc (bytes_needed, 1)) != NULL)
{ {
HOST_WIDE_INT i; HOST_WIDE_INT i;
tree v = TYPE_VALUES (type); tree v = TYPE_VALUES (type);
......
...@@ -577,4 +577,29 @@ typedef char _Bool; ...@@ -577,4 +577,29 @@ typedef char _Bool;
#define TRUE true #define TRUE true
#define FALSE false #define FALSE false
/* As the last action in this file, we poison the identifiers that
shouldn't be used. Note, luckily gcc-3.0's token-based integrated
preprocessor won't trip on poisoned identifiers that arrive from
the expansion of macros. E.g. #define strrchr rindex, won't error
if rindex is poisoned after this directive is issued and later on
strrchr is called.
Note: We define bypass macros for the few cases where we really
want to use the libc memory allocation routines. Otherwise we
insist you use the "x" versions from libiberty. */
#define really_call_malloc malloc
#define really_call_calloc calloc
#define really_call_realloc realloc
#if (GCC_VERSION >= 3000)
#pragma GCC poison malloc realloc calloc strdup
/* Note: not all uses of `bcopy' and `index' (esp. variable names)
have been eliminated. */
#pragma GCC poison bzero bcmp rindex
#endif /* GCC >= 3.0 */
#endif /* __GCC_SYSTEM_H__ */ #endif /* __GCC_SYSTEM_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment