+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>
PR fortran/48588
lvalue.ts = sym->ts;
if (sym->as)
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.where = sym->declared_at;
}
gfc_entry_list;
-#define gfc_get_entry_list() \
- (gfc_entry_list *) gfc_getmem(sizeof(gfc_entry_list))
+#define gfc_get_entry_list() XCNEW (gfc_entry_list)
/* Lists of rename info for the USE statement. */
}
gfc_use_list;
-#define gfc_get_use_list() \
- (gfc_use_list *) gfc_getmem(sizeof(gfc_use_list))
+#define gfc_get_use_list() XCNEW (gfc_use_list)
/* Within a namespace, symbols are pointed to by symtree nodes that
are linked together in a balanced binary tree. There can be
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
numbers. The first set of integer parameters define all there is
void gfc_end_source_files (void);
/* misc.c */
-void *gfc_getmem (size_t) ATTRIBUTE_MALLOC;
int gfc_terminal_width (void);
void gfc_clear_ts (gfc_typespec *);
FILE *gfc_open_file (const char *);
#include "system.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. */
if (gfc_option.module_dir != NULL)
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);
gfc_add_include_path (gfc_option.module_dir, true, false);
}
}
- result = (char *) gfc_getmem (len);
+ result = XCNEWVEC (char, len);
pos = 0;
for (j = 1; j < save_decoded_options_count; j++)
total_var = gfc_count_forall_iterators (code);
/* 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
/* Add line. */
- b = (gfc_linebuf *) gfc_getmem (gfc_linebuf_header_size
- + (len + 1) * sizeof (gfc_char_t));
+ b = (gfc_linebuf *) xcalloc (1, gfc_linebuf_header_size
+ + (len + 1) * sizeof (gfc_char_t));
b->location
= linemap_line_start (line_table, current_file->line++, 120);
gfc_array_size (array, &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);
mask_ctor = NULL;
resultsize = mpz_get_ui (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);
for (i = 0; i < resultsize; ++i)
{
else
{
result->representation.string =
- (char *) gfc_getmem (result->representation.length + 1);
+ XCNEWVEC (char, result->representation.length + 1);
memcpy (result->representation.string, buffer,
result->representation.length);
result->representation.string[result->representation.length] = '\0';
gfc_conv_const_charlen (sym->ts.u.cl);
/* Create the segment_info and fill it in. */
- s = (segment_info *) gfc_getmem (sizeof (segment_info));
+ s = XCNEW (segment_info);
s->sym = sym;
/* We will use this type when building the segment aggregate type. */
s->field = gfc_sym_type (sym);
gfc_equiv_info *s;
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;
c->sym->ns->equiv_lists = l;
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;
l->equiv = s;
s->sym = f->sym;
/* Now absorb all the initializer data into a single vector,
whilst checking for overlapping, unequal values. */
- data = (unsigned char*)gfc_getmem ((size_t)length);
- chk = (unsigned char*)gfc_getmem ((size_t)length);
+ data = XCNEWVEC (unsigned char, (size_t)length);
+ chk = XCNEWVEC (unsigned char, (size_t)length);
/* TODO - change this when default initialization is implemented. */
memset (data, '\0', (size_t)length);
n = 0;
for (fargs = sym->formal; fargs; fargs = fargs->next)
n++;
- saved_vars = (gfc_saved_var *)gfc_getmem (n * sizeof (gfc_saved_var));
- temp_vars = (tree *)gfc_getmem (n * sizeof (tree));
+ saved_vars = XCNEWVEC (gfc_saved_var, n);
+ temp_vars = XCNEWVEC (tree, n);
for (fargs = sym->formal, n = 0; fargs; fargs = fargs->next, n++)
{
char * full_name;
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);
full_name = strcat (full_name, "%");
full_name = strcat (full_name, cmp_name);
nvar = n;
/* Allocate the space for var, start, end, step, varexpr. */
- var = (tree *) gfc_getmem (nvar * sizeof (tree));
- start = (tree *) gfc_getmem (nvar * sizeof (tree));
- end = (tree *) gfc_getmem (nvar * sizeof (tree));
- step = (tree *) gfc_getmem (nvar * sizeof (tree));
- varexpr = (gfc_expr **) gfc_getmem (nvar * sizeof (gfc_expr *));
- saved_vars = (gfc_saved_var *) gfc_getmem (nvar * sizeof (gfc_saved_var));
+ var = XCNEWVEC (tree, nvar);
+ start = XCNEWVEC (tree, nvar);
+ end = XCNEWVEC (tree, nvar);
+ step = XCNEWVEC (tree, nvar);
+ varexpr = XCNEWVEC (gfc_expr *, nvar);
+ saved_vars = XCNEWVEC (gfc_saved_var, nvar);
/* Allocate the space for info. */
- info = (forall_info *) gfc_getmem (sizeof (forall_info));
+ info = XCNEW (forall_info);
gfc_start_block (&pre);
gfc_init_block (&post);
gfc_symbol *sym = fa->var->symtree->n.sym;
/* 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. */
tmp = gfc_typenode_for_spec (&sym->ts);