This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
PATCH to use xcalloc
- To: egcs at egcs dot cygnus dot com
- Subject: PATCH to use xcalloc
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Fri, 03 Sep 1999 16:29:21 -0700
- Organization: CodeSourcery, LLC
I committed the following inoccuous patch, off the GC branch, to the
mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
Sat May 16 14:24:34 1998 Richard Henderson <rth@cygnus.com>
* dbxout.c (dbxout_init): Use xcalloc instead of xmalloc+bzero.
* dwarf2out.c (dwarf2out_frame_init): Likewise.
* final.c (shorten_branches): Likewise.
* global.c (global_alloc): Likewise.
* haifa-sched.c (build_control_flow): Likewise.
* stmt.c (check_for_full_enumeration_handling): Likewise.
(estimate_case_costs): Likewise.
Index: dbxout.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/dbxout.c,v
retrieving revision 1.36
diff -c -p -r1.36 dbxout.c
*** dbxout.c 1999/08/31 01:01:14 1.36
--- dbxout.c 1999/09/03 21:06:25
*************** dbxout_init (asm_file, input_file_name,
*** 381,388 ****
asmfile = asm_file;
typevec_len = 100;
! typevec = (struct typeinfo *) xmalloc (typevec_len * sizeof typevec[0]);
! bzero ((char *) typevec, typevec_len * sizeof typevec[0]);
/* Convert Ltext into the appropriate format for local labels in case
the system doesn't insert underscores in front of user generated
--- 381,387 ----
asmfile = asm_file;
typevec_len = 100;
! typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
/* Convert Ltext into the appropriate format for local labels in case
the system doesn't insert underscores in front of user generated
Index: dwarf2out.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/dwarf2out.c,v
retrieving revision 1.110
diff -c -p -r1.110 dwarf2out.c
*** dwarf2out.c 1999/09/02 17:29:17 1.110
--- dwarf2out.c 1999/09/03 21:06:32
*************** void
*** 1985,1993 ****
dwarf2out_frame_init ()
{
/* Allocate the initial hunk of the fde_table. */
! fde_table
! = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
! bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
fde_table_allocated = FDE_TABLE_INCREMENT;
fde_table_in_use = 0;
--- 1985,1991 ----
dwarf2out_frame_init ()
{
/* Allocate the initial hunk of the fde_table. */
! fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
fde_table_allocated = FDE_TABLE_INCREMENT;
fde_table_in_use = 0;
*************** dwarf2out_init (asm_out_file, main_input
*** 10016,10023 ****
primary_filename = main_input_filename;
/* Allocate the initial hunk of the file_table. */
! file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
! bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
file_table_allocated = FILE_TABLE_INCREMENT;
/* Skip the first entry - file numbers begin at 1. */
--- 10014,10020 ----
primary_filename = main_input_filename;
/* Allocate the initial hunk of the file_table. */
! file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
file_table_allocated = FILE_TABLE_INCREMENT;
/* Skip the first entry - file numbers begin at 1. */
*************** dwarf2out_init (asm_out_file, main_input
*** 10025,10061 ****
/* Allocate the initial hunk of the decl_die_table. */
decl_die_table
! = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
! bzero ((char *) decl_die_table,
! DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
decl_die_table_in_use = 0;
/* Allocate the initial hunk of the decl_scope_table. */
decl_scope_table
! = (decl_scope_node *) xmalloc (DECL_SCOPE_TABLE_INCREMENT
! * sizeof (decl_scope_node));
! bzero ((char *) decl_scope_table,
! DECL_SCOPE_TABLE_INCREMENT * sizeof (decl_scope_node));
decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
decl_scope_depth = 0;
/* Allocate the initial hunk of the abbrev_die_table. */
abbrev_die_table
! = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
! * sizeof (dw_die_ref));
! bzero ((char *) abbrev_die_table,
! ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
/* Zero-th entry is allocated, but unused */
abbrev_die_table_in_use = 1;
/* Allocate the initial hunk of the line_info_table. */
line_info_table
! = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
! * sizeof (dw_line_info_entry));
! bzero ((char *) line_info_table,
! LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
/* Zero-th entry is allocated, but unused */
line_info_table_in_use = 1;
--- 10022,10050 ----
/* Allocate the initial hunk of the decl_die_table. */
decl_die_table
! = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
decl_die_table_in_use = 0;
/* Allocate the initial hunk of the decl_scope_table. */
decl_scope_table
! = (decl_scope_node *) xcalloc (DECL_SCOPE_TABLE_INCREMENT,
! sizeof (decl_scope_node));
decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
decl_scope_depth = 0;
/* Allocate the initial hunk of the abbrev_die_table. */
abbrev_die_table
! = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
! sizeof (dw_die_ref));
abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
/* Zero-th entry is allocated, but unused */
abbrev_die_table_in_use = 1;
/* Allocate the initial hunk of the line_info_table. */
line_info_table
! = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
! sizeof (dw_line_info_entry));
line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
/* Zero-th entry is allocated, but unused */
line_info_table_in_use = 1;
Index: final.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/final.c,v
retrieving revision 1.90
diff -c -p -r1.90 final.c
*** final.c 1999/09/02 05:42:03 1.90
--- final.c 1999/09/03 21:06:34
*************** shorten_branches (first)
*** 1025,1034 ****
max_labelno = max_label_num ();
min_labelno = get_first_label_num ();
! label_align = (struct label_alignment *) xmalloc (
! (max_labelno - min_labelno + 1) * sizeof (struct label_alignment));
! bzero ((char *) label_align,
! (max_labelno - min_labelno + 1) * sizeof (struct label_alignment));
uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
--- 1025,1032 ----
max_labelno = max_label_num ();
min_labelno = get_first_label_num ();
! label_align = (struct label_alignment **)
! xcalloc ((max_labelno - min_labelno + 1), sizeof (struct label_alignment));
uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
*************** shorten_branches (first)
*** 1148,1171 ****
/* Allocate the rest of the arrays. */
insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
- insn_addresses = (int *) xmalloc (max_uid * sizeof (int));
insn_lengths_max_uid = max_uid;
/* Syntax errors can lead to labels being outside of the main insn stream.
Initialize insn_addresses, so that we get reproducible results. */
! bzero ((char *)insn_addresses, max_uid * sizeof *insn_addresses);
! uid_align = (rtx *) xmalloc (max_uid * sizeof *uid_align);
! varying_length = (char *) xmalloc (max_uid * sizeof (char));
- bzero (varying_length, max_uid);
-
/* Initialize uid_align. We scan instructions
from end to start, and keep in align_tab[n] the last seen insn
that does an alignment of at least n+1, i.e. the successor
in the alignment chain for an insn that does / has a known
alignment of n. */
!
! bzero ((char *) uid_align, max_uid * sizeof *uid_align);
for (i = MAX_CODE_ALIGN; --i >= 0; )
align_tab[i] = NULL_RTX;
--- 1146,1164 ----
/* Allocate the rest of the arrays. */
insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
insn_lengths_max_uid = max_uid;
/* Syntax errors can lead to labels being outside of the main insn stream.
Initialize insn_addresses, so that we get reproducible results. */
! insn_addresses = (int *) xcalloc (max_uid, sizeof (int));
! varying_length = (char *) xcalloc (max_uid, sizeof (char));
/* Initialize uid_align. We scan instructions
from end to start, and keep in align_tab[n] the last seen insn
that does an alignment of at least n+1, i.e. the successor
in the alignment chain for an insn that does / has a known
alignment of n. */
! uid_align = (rtx *) xcalloc (max_uid, sizeof *uid_align);
for (i = MAX_CODE_ALIGN; --i >= 0; )
align_tab[i] = NULL_RTX;
Index: global.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/global.c,v
retrieving revision 1.32
diff -c -p -r1.32 global.c
*** global.c 1999/08/12 22:53:28 1.32
--- global.c 1999/09/03 21:06:35
*************** global_alloc (file)
*** 486,495 ****
/* We used to use alloca here, but the size of what it would try to
allocate would occasionally cause it to exceed the stack limit and
cause unpredictable core dumps. Some examples were > 2Mb in size. */
! conflicts = (INT_TYPE *) xmalloc (max_allocno * allocno_row_words
! * sizeof (INT_TYPE));
! bzero ((char *) conflicts,
! max_allocno * allocno_row_words * sizeof (INT_TYPE));
allocnos_live = (INT_TYPE *) alloca (allocno_row_words * sizeof (INT_TYPE));
--- 486,493 ----
/* We used to use alloca here, but the size of what it would try to
allocate would occasionally cause it to exceed the stack limit and
cause unpredictable core dumps. Some examples were > 2Mb in size. */
! conflicts = (INT_TYPE *) xcalloc (max_allocno * allocno_row_words,
! sizeof (INT_TYPE));
allocnos_live = (INT_TYPE *) alloca (allocno_row_words * sizeof (INT_TYPE));
Index: haifa-sched.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/haifa-sched.c,v
retrieving revision 1.100
diff -c -p -r1.100 haifa-sched.c
*** haifa-sched.c 1999/08/28 23:20:34 1.100
--- haifa-sched.c 1999/09/03 21:06:40
*************** build_control_flow (s_preds, s_succs, nu
*** 1085,1097 ****
/* Account for entry/exit edges. */
nr_edges += 2;
! in_edges = (int *) xmalloc (n_basic_blocks * sizeof (int));
! out_edges = (int *) xmalloc (n_basic_blocks * sizeof (int));
! bzero ((char *) in_edges, n_basic_blocks * sizeof (int));
! bzero ((char *) out_edges, n_basic_blocks * sizeof (int));
!
! edge_table = (haifa_edge *) xmalloc ((nr_edges) * sizeof (haifa_edge));
! bzero ((char *) edge_table, ((nr_edges) * sizeof (haifa_edge)));
nr_edges = 0;
for (i = 0; i < n_basic_blocks; i++)
--- 1085,1093 ----
/* Account for entry/exit edges. */
nr_edges += 2;
! in_edges = (int *) xcalloc (n_basic_blocks, sizeof (int));
! out_edges = (int *) xcalloc (n_basic_blocks, sizeof (int));
! edge_table = (haifa_edge *) xcalloc (nr_edges, sizeof (haifa_edge));
nr_edges = 0;
for (i = 0; i < n_basic_blocks; i++)
Index: stmt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/stmt.c,v
retrieving revision 1.82
diff -c -p -r1.82 stmt.c
*** stmt.c 1999/09/02 22:10:15 1.82
--- stmt.c 1999/09/03 21:06:43
*************** check_for_full_enumeration_handling (typ
*** 4900,4911 ****
bytes_needed = (size + HOST_BITS_PER_CHAR) / HOST_BITS_PER_CHAR;
if (size > 0 && size < 600000
! /* We deliberately use malloc here - not xmalloc. */
! && (cases_seen = (unsigned char *) malloc (bytes_needed)) != NULL)
{
long i;
tree v = TYPE_VALUES (type);
- bzero (cases_seen, bytes_needed);
/* The time complexity of this code is normally O(N), where
N being the number of members in the enumerated type.
--- 4900,4910 ----
bytes_needed = (size + HOST_BITS_PER_CHAR) / HOST_BITS_PER_CHAR;
if (size > 0 && size < 600000
! /* We deliberately use calloc here - not xcalloc. */
! && (cases_seen = (unsigned char *) calloc (bytes_needed, 1)) != NULL)
{
long i;
tree v = TYPE_VALUES (type);
/* The time complexity of this code is normally O(N), where
N being the number of members in the enumerated type.
*************** estimate_case_costs (node)
*** 5469,5476 ****
if (cost_table == NULL)
{
! cost_table = ((short *) xmalloc (129 * sizeof (short))) + 1;
! bzero ((char *) (cost_table - 1), 129 * sizeof (short));
for (i = 0; i < 128; i++)
{
--- 5468,5474 ----
if (cost_table == NULL)
{
! cost_table = ((short *) xcalloc (129, sizeof (short))) + 1;
for (i = 0; i < 128; i++)
{