Commit 93acb62c by Janne Blomqvist

Replace gfc_getmem with XCNEW, XCNEWVEC or xcalloc

From-SVN: r172728
parent 60bea929
2011-04-19 Janne Blomqvist <jb@gcc.gnu.org>
* misc.c (gfc_getmem): Remove function.
* gfortran.h: Remove gfc_getmem prototype. Replace gfc_getmem
usage with XCNEW or XCNEWVEC.
* expr.c (gfc_check_assign_symbol): Replace gfc_getmem usage with
XCNEW or XCNEWVEC.
* options.c (gfc_handle_module_path_options)
(gfc_get_option_string): Likewise.
* resolve.c (gfc_resolve_forall): Likewise.
* simplify.c (simplify_transformation_to_array): Likewise.
* target-memory.c (gfc_target_interpret_expr): Likewise.
* trans-common.c (get_segment_info, copy_equiv_list_to_ns)
(get_init_field): Likewise.
* trans-expr.c (gfc_conv_statement_function): Likewise.
* trans-io.c (nml_full_name): Likewise.
* trans-stmt.c (gfc_trans_forall_1): Likewise.
* scanner.c (load_file): Replace gfc_getmem usage with xcalloc.
2011-04-19 Tobias Burnus <burnus@net-b.de> 2011-04-19 Tobias Burnus <burnus@net-b.de>
PR fortran/48588 PR fortran/48588
......
...@@ -3583,7 +3583,7 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_expr *rvalue) ...@@ -3583,7 +3583,7 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_expr *rvalue)
lvalue.ts = sym->ts; lvalue.ts = sym->ts;
if (sym->as) if (sym->as)
lvalue.rank = sym->as->rank; lvalue.rank = sym->as->rank;
lvalue.symtree = (gfc_symtree *) gfc_getmem (sizeof (gfc_symtree)); lvalue.symtree = XCNEW (gfc_symtree);
lvalue.symtree->n.sym = sym; lvalue.symtree->n.sym = sym;
lvalue.where = sym->declared_at; lvalue.where = sym->declared_at;
......
...@@ -1272,8 +1272,7 @@ typedef struct gfc_entry_list ...@@ -1272,8 +1272,7 @@ typedef struct gfc_entry_list
} }
gfc_entry_list; gfc_entry_list;
#define gfc_get_entry_list() \ #define gfc_get_entry_list() XCNEW (gfc_entry_list)
(gfc_entry_list *) gfc_getmem(sizeof(gfc_entry_list))
/* Lists of rename info for the USE statement. */ /* Lists of rename info for the USE statement. */
...@@ -1302,8 +1301,7 @@ typedef struct gfc_use_list ...@@ -1302,8 +1301,7 @@ typedef struct gfc_use_list
} }
gfc_use_list; gfc_use_list;
#define gfc_get_use_list() \ #define gfc_get_use_list() XCNEW (gfc_use_list)
(gfc_use_list *) gfc_getmem(sizeof(gfc_use_list))
/* Within a namespace, symbols are pointed to by symtree nodes that /* Within a namespace, symbols are pointed to by symtree nodes that
are linked together in a balanced binary tree. There can be are linked together in a balanced binary tree. There can be
...@@ -1783,7 +1781,7 @@ typedef struct gfc_expr ...@@ -1783,7 +1781,7 @@ typedef struct gfc_expr
gfc_expr; gfc_expr;
#define gfc_get_shape(rank) ((mpz_t *) gfc_getmem((rank)*sizeof(mpz_t))) #define gfc_get_shape(rank) (XCNEWVEC (mpz_t, (rank)))
/* Structures for information associated with different kinds of /* Structures for information associated with different kinds of
numbers. The first set of integer parameters define all there is numbers. The first set of integer parameters define all there is
...@@ -2369,7 +2367,6 @@ void gfc_start_source_files (void); ...@@ -2369,7 +2367,6 @@ void gfc_start_source_files (void);
void gfc_end_source_files (void); void gfc_end_source_files (void);
/* misc.c */ /* misc.c */
void *gfc_getmem (size_t) ATTRIBUTE_MALLOC;
int gfc_terminal_width (void); int gfc_terminal_width (void);
void gfc_clear_ts (gfc_typespec *); void gfc_clear_ts (gfc_typespec *);
FILE *gfc_open_file (const char *); FILE *gfc_open_file (const char *);
......
...@@ -23,24 +23,6 @@ along with GCC; see the file COPYING3. If not see ...@@ -23,24 +23,6 @@ along with GCC; see the file COPYING3. If not see
#include "system.h" #include "system.h"
#include "gfortran.h" #include "gfortran.h"
/* Get a block of memory. Many callers assume that the memory we
return is zeroed. */
void *
gfc_getmem (size_t n)
{
void *p;
if (n == 0)
return NULL;
p = xmalloc (n);
if (p == NULL)
gfc_fatal_error ("Allocation would exceed memory limit -- malloc() failed");
memset (p, 0, n);
return p;
}
/* Get terminal width. */ /* Get terminal width. */
......
...@@ -471,7 +471,7 @@ gfc_handle_module_path_options (const char *arg) ...@@ -471,7 +471,7 @@ gfc_handle_module_path_options (const char *arg)
if (gfc_option.module_dir != NULL) if (gfc_option.module_dir != NULL)
gfc_fatal_error ("gfortran: Only one -J option allowed"); gfc_fatal_error ("gfortran: Only one -J option allowed");
gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2); gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
strcpy (gfc_option.module_dir, arg); strcpy (gfc_option.module_dir, arg);
gfc_add_include_path (gfc_option.module_dir, true, false); gfc_add_include_path (gfc_option.module_dir, true, false);
...@@ -1056,7 +1056,7 @@ gfc_get_option_string (void) ...@@ -1056,7 +1056,7 @@ gfc_get_option_string (void)
} }
} }
result = (char *) gfc_getmem (len); result = XCNEWVEC (char, len);
pos = 0; pos = 0;
for (j = 1; j < save_decoded_options_count; j++) for (j = 1; j < save_decoded_options_count; j++)
......
...@@ -8598,7 +8598,7 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns, int forall_save) ...@@ -8598,7 +8598,7 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns, int forall_save)
total_var = gfc_count_forall_iterators (code); total_var = gfc_count_forall_iterators (code);
/* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */ /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
var_expr = (gfc_expr **) gfc_getmem (total_var * sizeof (gfc_expr *)); var_expr = XCNEWVEC (gfc_expr *, total_var);
} }
/* The information about FORALL iterator, including FORALL index start, end /* The information about FORALL iterator, including FORALL index start, end
......
...@@ -2012,8 +2012,8 @@ load_file (const char *realfilename, const char *displayedname, bool initial) ...@@ -2012,8 +2012,8 @@ load_file (const char *realfilename, const char *displayedname, bool initial)
/* Add line. */ /* Add line. */
b = (gfc_linebuf *) gfc_getmem (gfc_linebuf_header_size b = (gfc_linebuf *) xcalloc (1, gfc_linebuf_header_size
+ (len + 1) * sizeof (gfc_char_t)); + (len + 1) * sizeof (gfc_char_t));
b->location b->location
= linemap_line_start (line_table, current_file->line++, 120); = linemap_line_start (line_table, current_file->line++, 120);
......
...@@ -517,7 +517,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d ...@@ -517,7 +517,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d
gfc_array_size (array, &size); gfc_array_size (array, &size);
arraysize = mpz_get_ui (size); arraysize = mpz_get_ui (size);
arrayvec = (gfc_expr**) gfc_getmem (sizeof (gfc_expr*) * arraysize); arrayvec = XCNEWVEC (gfc_expr*, arraysize);
array_ctor = gfc_constructor_first (array->value.constructor); array_ctor = gfc_constructor_first (array->value.constructor);
mask_ctor = NULL; mask_ctor = NULL;
...@@ -543,7 +543,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d ...@@ -543,7 +543,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d
resultsize = mpz_get_ui (size); resultsize = mpz_get_ui (size);
mpz_clear (size); mpz_clear (size);
resultvec = (gfc_expr**) gfc_getmem (sizeof (gfc_expr*) * resultsize); resultvec = XCNEWVEC (gfc_expr*, resultsize);
result_ctor = gfc_constructor_first (result->value.constructor); result_ctor = gfc_constructor_first (result->value.constructor);
for (i = 0; i < resultsize; ++i) for (i = 0; i < resultsize; ++i)
{ {
......
...@@ -569,7 +569,7 @@ gfc_target_interpret_expr (unsigned char *buffer, size_t buffer_size, ...@@ -569,7 +569,7 @@ gfc_target_interpret_expr (unsigned char *buffer, size_t buffer_size,
else else
{ {
result->representation.string = result->representation.string =
(char *) gfc_getmem (result->representation.length + 1); XCNEWVEC (char, result->representation.length + 1);
memcpy (result->representation.string, buffer, memcpy (result->representation.string, buffer,
result->representation.length); result->representation.length);
result->representation.string[result->representation.length] = '\0'; result->representation.string[result->representation.length] = '\0';
......
...@@ -133,7 +133,7 @@ get_segment_info (gfc_symbol * sym, HOST_WIDE_INT offset) ...@@ -133,7 +133,7 @@ get_segment_info (gfc_symbol * sym, HOST_WIDE_INT offset)
gfc_conv_const_charlen (sym->ts.u.cl); gfc_conv_const_charlen (sym->ts.u.cl);
/* Create the segment_info and fill it in. */ /* Create the segment_info and fill it in. */
s = (segment_info *) gfc_getmem (sizeof (segment_info)); s = XCNEW (segment_info);
s->sym = sym; s->sym = sym;
/* We will use this type when building the segment aggregate type. */ /* We will use this type when building the segment aggregate type. */
s->field = gfc_sym_type (sym); s->field = gfc_sym_type (sym);
...@@ -155,14 +155,14 @@ copy_equiv_list_to_ns (segment_info *c) ...@@ -155,14 +155,14 @@ copy_equiv_list_to_ns (segment_info *c)
gfc_equiv_info *s; gfc_equiv_info *s;
gfc_equiv_list *l; gfc_equiv_list *l;
l = (gfc_equiv_list *) gfc_getmem (sizeof (gfc_equiv_list)); l = XCNEW (gfc_equiv_list);
l->next = c->sym->ns->equiv_lists; l->next = c->sym->ns->equiv_lists;
c->sym->ns->equiv_lists = l; c->sym->ns->equiv_lists = l;
for (f = c; f; f = f->next) for (f = c; f; f = f->next)
{ {
s = (gfc_equiv_info *) gfc_getmem (sizeof (gfc_equiv_info)); s = XCNEW (gfc_equiv_info);
s->next = l->equiv; s->next = l->equiv;
l->equiv = s; l->equiv = s;
s->sym = f->sym; s->sym = f->sym;
...@@ -505,8 +505,8 @@ get_init_field (segment_info *head, tree union_type, tree *field_init, ...@@ -505,8 +505,8 @@ get_init_field (segment_info *head, tree union_type, tree *field_init,
/* Now absorb all the initializer data into a single vector, /* Now absorb all the initializer data into a single vector,
whilst checking for overlapping, unequal values. */ whilst checking for overlapping, unequal values. */
data = (unsigned char*)gfc_getmem ((size_t)length); data = XCNEWVEC (unsigned char, (size_t)length);
chk = (unsigned char*)gfc_getmem ((size_t)length); chk = XCNEWVEC (unsigned char, (size_t)length);
/* TODO - change this when default initialization is implemented. */ /* TODO - change this when default initialization is implemented. */
memset (data, '\0', (size_t)length); memset (data, '\0', (size_t)length);
......
...@@ -3957,8 +3957,8 @@ gfc_conv_statement_function (gfc_se * se, gfc_expr * expr) ...@@ -3957,8 +3957,8 @@ gfc_conv_statement_function (gfc_se * se, gfc_expr * expr)
n = 0; n = 0;
for (fargs = sym->formal; fargs; fargs = fargs->next) for (fargs = sym->formal; fargs; fargs = fargs->next)
n++; n++;
saved_vars = (gfc_saved_var *)gfc_getmem (n * sizeof (gfc_saved_var)); saved_vars = XCNEWVEC (gfc_saved_var, n);
temp_vars = (tree *)gfc_getmem (n * sizeof (tree)); temp_vars = XCNEWVEC (tree, n);
for (fargs = sym->formal, n = 0; fargs; fargs = fargs->next, n++) for (fargs = sym->formal, n = 0; fargs; fargs = fargs->next, n++)
{ {
......
...@@ -1450,7 +1450,7 @@ nml_full_name (const char* var_name, const char* cmp_name) ...@@ -1450,7 +1450,7 @@ nml_full_name (const char* var_name, const char* cmp_name)
char * full_name; char * full_name;
full_name_length = strlen (var_name) + strlen (cmp_name) + 1; full_name_length = strlen (var_name) + strlen (cmp_name) + 1;
full_name = (char*)gfc_getmem (full_name_length + 1); full_name = XCNEWVEC (char, full_name_length + 1);
strcpy (full_name, var_name); strcpy (full_name, var_name);
full_name = strcat (full_name, "%"); full_name = strcat (full_name, "%");
full_name = strcat (full_name, cmp_name); full_name = strcat (full_name, cmp_name);
......
...@@ -3455,15 +3455,15 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info) ...@@ -3455,15 +3455,15 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info)
nvar = n; nvar = n;
/* Allocate the space for var, start, end, step, varexpr. */ /* Allocate the space for var, start, end, step, varexpr. */
var = (tree *) gfc_getmem (nvar * sizeof (tree)); var = XCNEWVEC (tree, nvar);
start = (tree *) gfc_getmem (nvar * sizeof (tree)); start = XCNEWVEC (tree, nvar);
end = (tree *) gfc_getmem (nvar * sizeof (tree)); end = XCNEWVEC (tree, nvar);
step = (tree *) gfc_getmem (nvar * sizeof (tree)); step = XCNEWVEC (tree, nvar);
varexpr = (gfc_expr **) gfc_getmem (nvar * sizeof (gfc_expr *)); varexpr = XCNEWVEC (gfc_expr *, nvar);
saved_vars = (gfc_saved_var *) gfc_getmem (nvar * sizeof (gfc_saved_var)); saved_vars = XCNEWVEC (gfc_saved_var, nvar);
/* Allocate the space for info. */ /* Allocate the space for info. */
info = (forall_info *) gfc_getmem (sizeof (forall_info)); info = XCNEW (forall_info);
gfc_start_block (&pre); gfc_start_block (&pre);
gfc_init_block (&post); gfc_init_block (&post);
...@@ -3475,7 +3475,7 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info) ...@@ -3475,7 +3475,7 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info)
gfc_symbol *sym = fa->var->symtree->n.sym; gfc_symbol *sym = fa->var->symtree->n.sym;
/* Allocate space for this_forall. */ /* Allocate space for this_forall. */
this_forall = (iter_info *) gfc_getmem (sizeof (iter_info)); this_forall = XCNEW (iter_info);
/* Create a temporary variable for the FORALL index. */ /* Create a temporary variable for the FORALL index. */
tmp = gfc_typenode_for_spec (&sym->ts); tmp = gfc_typenode_for_spec (&sym->ts);
......
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