From 93acb62caabb343900fb68d3bd76dd36406a7ad4 Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Tue, 19 Apr 2011 20:42:51 +0300 Subject: [PATCH] Replace gfc_getmem with XCNEW, XCNEWVEC or xcalloc From-SVN: r172728 --- gcc/fortran/ChangeLog | 19 +++++++++++++++++++ gcc/fortran/expr.c | 2 +- gcc/fortran/gfortran.h | 9 +++------ gcc/fortran/misc.c | 18 ------------------ gcc/fortran/options.c | 4 ++-- gcc/fortran/resolve.c | 2 +- gcc/fortran/scanner.c | 4 ++-- gcc/fortran/simplify.c | 4 ++-- gcc/fortran/target-memory.c | 2 +- gcc/fortran/trans-common.c | 10 +++++----- gcc/fortran/trans-expr.c | 4 ++-- gcc/fortran/trans-io.c | 2 +- gcc/fortran/trans-stmt.c | 16 ++++++++-------- 13 files changed, 47 insertions(+), 49 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c60ba46edebf..c6d92959eeab 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,22 @@ +2011-04-19 Janne Blomqvist + + * 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 PR fortran/48588 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 1e316534388f..42b65c6a36b6 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3583,7 +3583,7 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_expr *rvalue) 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; diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index ce11c077beea..1d725e43169c 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1272,8 +1272,7 @@ typedef struct gfc_entry_list } 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. */ @@ -1302,8 +1301,7 @@ typedef struct gfc_use_list } 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 @@ -1783,7 +1781,7 @@ typedef struct 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 numbers. The first set of integer parameters define all there is @@ -2369,7 +2367,6 @@ void gfc_start_source_files (void); 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 *); diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c index a54ffc09d6d6..127404782570 100644 --- a/gcc/fortran/misc.c +++ b/gcc/fortran/misc.c @@ -23,24 +23,6 @@ along with GCC; see the file COPYING3. If not see #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. */ diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index a4d9a66062c1..bc65f6bf66b7 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -471,7 +471,7 @@ gfc_handle_module_path_options (const char *arg) 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); @@ -1056,7 +1056,7 @@ gfc_get_option_string (void) } } - result = (char *) gfc_getmem (len); + result = XCNEWVEC (char, len); pos = 0; for (j = 1; j < save_decoded_options_count; j++) diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 09cfe78de780..c10161213197 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -8598,7 +8598,7 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns, int forall_save) 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 diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index 7f99eb8b9133..f99429a7cc0b 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -2012,8 +2012,8 @@ load_file (const char *realfilename, const char *displayedname, bool initial) /* 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); diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index c2ece959a8f8..4c91563389cb 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -517,7 +517,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d 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; @@ -543,7 +543,7 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d 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) { diff --git a/gcc/fortran/target-memory.c b/gcc/fortran/target-memory.c index 03a5b58c8a38..b5c90a7b5d49 100644 --- a/gcc/fortran/target-memory.c +++ b/gcc/fortran/target-memory.c @@ -569,7 +569,7 @@ gfc_target_interpret_expr (unsigned char *buffer, size_t buffer_size, 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'; diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c index a2b260546653..b6318b707ca6 100644 --- a/gcc/fortran/trans-common.c +++ b/gcc/fortran/trans-common.c @@ -133,7 +133,7 @@ get_segment_info (gfc_symbol * sym, HOST_WIDE_INT offset) 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); @@ -155,14 +155,14 @@ copy_equiv_list_to_ns (segment_info *c) 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; @@ -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, 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); diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index af19d32867a3..73d8a5f6869f 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -3957,8 +3957,8 @@ gfc_conv_statement_function (gfc_se * se, gfc_expr * expr) 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++) { diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c index a9ad4a68cae2..8021bc672be3 100644 --- a/gcc/fortran/trans-io.c +++ b/gcc/fortran/trans-io.c @@ -1450,7 +1450,7 @@ nml_full_name (const char* var_name, const char* cmp_name) 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); diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 7d72b7e4df84..7e08e8dd07ba 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -3455,15 +3455,15 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info) 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); @@ -3475,7 +3475,7 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info) 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); -- 2.43.5