From da2a7671e11663b9ad941aa3e1f3014d6ad950cb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 10 Dec 2004 07:50:44 +0000 Subject: [PATCH] * src/system.h (CALLOC, MALLOC, REALLOC): Remove. All callers changed to use xcalloc, xnmalloc, xnrealloc, respectively, unless otherwise specified below. * src/LR0.c (allocate_itemsets): Use xnmalloc, not xcalloc, to allocate kernel_base, kernel_items, kernel_size, since they needn't be initialized to 0. (allocate_storgae): Likewise, for shiftset, redset, shift_symbol. * src/closure.c (new_closure): Likewise, for itemset. * src/derives.c (derives_compute): Likewise, for delts, derives, q. * src/lalr.c (set_goto_map): Likewise, for temp_map. (initialize_F): Likewise, for reads, edge, reads[i], includes[i]. (build_relations): Likewise for edge, states1, includes. * src/nullable.c (nullable_compute): Likewise, for squeue, relts. * src/reader.c (packgram): Likewise, for ritem, rules. * src/reduce.c (nonterminals_reduce): Likewise for nontermmap. * src/relation.c (relation_digraph): Likewise for VERTICES. (relation_transpose): Likewise for new_R, end_R. * src/symtab.c (symbols_token_translations_init): Likewise for token_translations. * src/tables.c (save_row): Likewise for froms, tos, conflict_tos. (token_actions): Likewise for yydefact, actrow, conflrow, conflict_list. (save_column): Likewise for froms[symno], tos[symno]. (goto_actions): Likewise for state_count. (pack_table): Likewise for base, pos, check. (tables_generate): Likewise for width. * src/LR0.c (set_states): Don't reuse kernel_size and kernel_base for initial core. Just have a separate core, so we needn't worry about whether kernel_size and kernel_base are initialized. * src/LR0.c (shift_symbol, redset, shiftset, kernel_base, kernel_size, kernel_items): Remove unnecessary initialization. * src/conflicts.c (conflicts): Likewise. * src/derives.c (derives): Likewise. * src/muscle_tablc (muscle_insert): Likewise. * src/relation.c (relation_digraph): Likewise. * src/tables.c (froms, tos, conflict_tos, tally, width, actrow, order, conflrow, conflict_table, conflict_list, table, check): Likewise. * src/closure.c (new_closure): Arg is of type unsigned int, not int. This is because all callers pass unsigned int. * src/closure.h (new_closure): Likewise. * src/lalr.c (initialize_F): Initialize reads[i] in all cases. (build_relations): Initialize includes[i] in all cases. * src/reader.c (packgram): Always initialize rules[ruleno].prec and rules[ruleno].precsym. Initialize members in order. * src/relation.c (relation_transpose): Always initialize new_R[i] and end_R[i]. * src/table.c (conflict_row): Initialize 0 at end of conflict_list. * src/output.c (prepare_actions): Pass 0 instead of conflict_list[0]; conflict_list[0] was always 0, but now it isn't initialized. * src/table.c (table_grow): When conflict_table grew, the grown area wasn't cleared. Fix this. --- ChangeLog | 65 +++++++++++++++++++++++++++++++++++++++ src/closure.c | 7 +++-- src/closure.h | 2 +- src/conflicts.c | 6 ++-- src/derives.c | 10 +++--- src/lalr.c | 36 ++++++++++++---------- src/muscle_tab.c | 6 ++-- src/nullable.c | 10 +++--- src/output.c | 20 ++++++------ src/reader.c | 12 +++++--- src/reduce.c | 6 ++-- src/relation.c | 30 +++++++++--------- src/symlist.c | 2 +- src/symtab.c | 7 +++-- src/tables.c | 80 +++++++++++++++++++++++++----------------------- src/vcg.c | 12 ++------ 16 files changed, 191 insertions(+), 120 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca598cba..b88b18f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,68 @@ +2004-12-08 Paul Eggert + + * src/system.h (CALLOC, MALLOC, REALLOC): Remove. All callers + changed to use xcalloc, xnmalloc, xnrealloc, respectively, + unless otherwise specified below. + + * src/LR0.c (allocate_itemsets): Use xnmalloc, not xcalloc, + to allocate kernel_base, kernel_items, kernel_size, since + they needn't be initialized to 0. + (allocate_storgae): Likewise, for shiftset, redset, shift_symbol. + * src/closure.c (new_closure): Likewise, for itemset. + * src/derives.c (derives_compute): Likewise, for delts, derives, q. + * src/lalr.c (set_goto_map): Likewise, for temp_map. + (initialize_F): Likewise, for reads, edge, reads[i], includes[i]. + (build_relations): Likewise for edge, states1, includes. + * src/nullable.c (nullable_compute): Likewise, for squeue, relts. + * src/reader.c (packgram): Likewise, for ritem, rules. + * src/reduce.c (nonterminals_reduce): Likewise for nontermmap. + * src/relation.c (relation_digraph): Likewise for VERTICES. + (relation_transpose): Likewise for new_R, end_R. + * src/symtab.c (symbols_token_translations_init): Likewise for + token_translations. + * src/tables.c (save_row): Likewise for froms, tos, conflict_tos. + (token_actions): Likewise for yydefact, actrow, conflrow, + conflict_list. + (save_column): Likewise for froms[symno], tos[symno]. + (goto_actions): Likewise for state_count. + (pack_table): Likewise for base, pos, check. + (tables_generate): Likewise for width. + + * src/LR0.c (set_states): Don't reuse kernel_size and kernel_base + for initial core. Just have a separate core, so we needn't worry + about whether kernel_size and kernel_base are initialized. + + * src/LR0.c (shift_symbol, redset, shiftset, kernel_base, + kernel_size, kernel_items): Remove unnecessary initialization. + * src/conflicts.c (conflicts): Likewise. + * src/derives.c (derives): Likewise. + * src/muscle_tablc (muscle_insert): Likewise. + * src/relation.c (relation_digraph): Likewise. + * src/tables.c (froms, tos, conflict_tos, tally, width, actrow, order, + conflrow, conflict_table, conflict_list, table, check): + Likewise. + + * src/closure.c (new_closure): Arg is of type unsigned int, not int. + This is because all callers pass unsigned int. + * src/closure.h (new_closure): Likewise. + + * src/lalr.c (initialize_F): Initialize reads[i] in all cases. + (build_relations): Initialize includes[i] in all cases. + * src/reader.c (packgram): Always initialize rules[ruleno].prec + and rules[ruleno].precsym. Initialize members in order. + * src/relation.c (relation_transpose): Always initialize new_R[i] + and end_R[i]. + * src/table.c (conflict_row): Initialize 0 at end of conflict_list. + + * src/output.c (prepare_actions): Pass 0 instead of conflict_list[0]; + conflict_list[0] was always 0, but now it isn't initialized. + + * src/table.c (table_grow): When conflict_table grew, the grown + area wasn't cleared. Fix this. + + * lib/.cvsignore: Add strdup.c, strdup.h. + * m4/.cvsignore: Add strdup.m4. + 2004-12-07 Paul Eggert * src/lalr.h (GOTO_NUMBER_MAXIMUM): New macro. diff --git a/src/closure.c b/src/closure.c index 0b06e99c..f530e6af 100644 --- a/src/closure.c +++ b/src/closure.c @@ -1,6 +1,7 @@ /* Closures for Bison - Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004 Free Software + Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -180,9 +181,9 @@ set_fderives (void) void -new_closure (int n) +new_closure (unsigned int n) { - CALLOC (itemset, n); + itemset = xnmalloc (n, sizeof *itemset); ruleset = bitset_create (nrules, BITSET_FIXED); diff --git a/src/closure.h b/src/closure.h index 8cc4feb2..82a8ccf9 100644 --- a/src/closure.h +++ b/src/closure.h @@ -29,7 +29,7 @@ data so that closure can be called. n is the number of elements to allocate for itemset. */ -void new_closure (int n); +void new_closure (unsigned int n); /* Given the kernel (aka core) of a state (a vector of item numbers diff --git a/src/conflicts.c b/src/conflicts.c index bf5d6435..bcd6c846 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -38,7 +38,7 @@ /* -1 stands for not specified. */ int expected_sr_conflicts = -1; int expected_rr_conflicts = -1; -static char *conflicts = NULL; +static char *conflicts; struct obstack solved_conflicts_obstack; static bitset shift_set; @@ -305,9 +305,9 @@ conflicts_solve (void) { state_number i; /* List of look-ahead tokens on which we explicitly raise a syntax error. */ - symbol **errors = MALLOC (errors, ntokens + 1); + symbol **errors = xnmalloc (ntokens + 1, sizeof *errors); - CALLOC (conflicts, nstates); + conflicts = xcalloc (nstates, sizeof *conflicts); shift_set = bitset_create (ntokens, BITSET_FIXED); look_ahead_set = bitset_create (ntokens, BITSET_FIXED); obstack_init (&solved_conflicts_obstack); diff --git a/src/derives.c b/src/derives.c index 14e7817a..0810a726 100644 --- a/src/derives.c +++ b/src/derives.c @@ -37,7 +37,7 @@ typedef struct rule_list rule *value; } rule_list; -rule ***derives = NULL; +rule ***derives; static void print_derives (void) @@ -70,12 +70,12 @@ derives_compute (void) /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules whose LHS is NTERM. */ - rule_list **dset = CALLOC (dset, nvars); + rule_list **dset = xcalloc (nvars, sizeof *dset); /* DELTS[RULE] -- There are NRULES rule number to attach to nterms. Instead of performing NRULES allocations for each, have an array indexed by rule numbers. */ - rule_list *delts = CALLOC (delts, nrules); + rule_list *delts = xnmalloc (nrules, sizeof *delts); for (r = nrules - 1; r >= 0; --r) { @@ -90,8 +90,8 @@ derives_compute (void) /* DSET contains what we need under the form of a linked list. Make it a single array. */ - CALLOC (derives, nvars); - CALLOC (q, nvars + nrules); + derives = xnmalloc (nvars, sizeof *derives); + q = xnmalloc (nvars + nrules, sizeof *q); for (i = ntokens; i < nsyms; i++) { diff --git a/src/lalr.c b/src/lalr.c index 5fa1c1b7..e69c05c7 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -80,8 +80,8 @@ set_goto_map (void) state_number s; goto_number *temp_map; - CALLOC (goto_map, nvars + 1); - CALLOC (temp_map, nvars + 1); + goto_map = xcalloc (nvars + 1, sizeof *goto_map); + temp_map = xnmalloc (nvars + 1, sizeof *temp_map); ngotos = 0; for (s = 0; s < nstates; ++s) @@ -116,8 +116,8 @@ set_goto_map (void) temp_map[nsyms - ntokens] = ngotos; } - CALLOC (from_state, ngotos); - CALLOC (to_state, ngotos); + from_state = xcalloc (ngotos, sizeof *from_state); + to_state = xcalloc (ngotos, sizeof *to_state); for (s = 0; s < nstates; ++s) { @@ -170,8 +170,8 @@ map_goto (state_number s0, symbol_number sym) static void initialize_F (void) { - goto_number **reads = CALLOC (reads, ngotos); - goto_number *edge = CALLOC (edge, ngotos + 1); + goto_number **reads = xnmalloc (ngotos, sizeof *reads); + goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge); goto_number nedges = 0; goto_number i; @@ -194,10 +194,12 @@ initialize_F (void) edge[nedges++] = map_goto (stateno, sym); } - if (nedges) + if (nedges == 0) + reads[i] = NULL; + else { - CALLOC (reads[i], nedges + 1); - memcpy (reads[i], edge, nedges * sizeof (edge[0])); + reads[i] = xnmalloc (nedges + 1, sizeof reads[i][0]); + memcpy (reads[i], edge, nedges * sizeof edge[0]); reads[i][nedges] = END_NODE; nedges = 0; } @@ -217,7 +219,7 @@ static void add_lookback_edge (state *s, rule *r, goto_number gotono) { int ri = state_reduction_find (s, r); - goto_list *sp = MALLOC (sp, 1); + goto_list *sp = xmalloc (sizeof *sp); sp->next = lookback[(s->reductions->look_ahead_tokens - LA) + ri]; sp->value = gotono; lookback[(s->reductions->look_ahead_tokens - LA) + ri] = sp; @@ -228,11 +230,11 @@ add_lookback_edge (state *s, rule *r, goto_number gotono) static void build_relations (void) { - goto_number *edge = CALLOC (edge, ngotos + 1); - state_number *states1 = CALLOC (states1, ritem_longest_rhs () + 1); + goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge); + state_number *states1 = xnmalloc (ritem_longest_rhs () + 1, sizeof *states1); goto_number i; - CALLOC (includes, ngotos); + includes = xnmalloc (ngotos, sizeof *includes); for (i = 0; i < ngotos; i++) { @@ -276,10 +278,12 @@ build_relations (void) } } - if (nedges) + if (nedges == 0) + includes[i] = NULL; + else { int j; - CALLOC (includes[i], nedges + 1); + includes[i] = xnmalloc (nedges + 1, sizeof includes[i][0]); for (j = 0; j < nedges; j++) includes[i][j] = edge[j]; includes[i][nedges] = END_NODE; @@ -381,7 +385,7 @@ initialize_LA (void) nLA = 1; pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); - CALLOC (lookback, nLA); + lookback = xcalloc (nLA, sizeof *lookback); /* Initialize the members LOOK_AHEAD_TOKENS for each state whose reductions require look-ahead tokens. */ diff --git a/src/muscle_tab.c b/src/muscle_tab.c index bf5c4dd3..c1f675b9 100644 --- a/src/muscle_tab.c +++ b/src/muscle_tab.c @@ -99,7 +99,7 @@ void muscle_insert (const char *key, char *value) { muscle_entry probe; - muscle_entry *entry = NULL; + muscle_entry *entry; probe.key = key; entry = hash_lookup (muscle_table, &probe); @@ -107,7 +107,7 @@ muscle_insert (const char *key, char *value) if (!entry) { /* First insertion in the hash. */ - MALLOC (entry, 1); + entry = xmalloc (sizeof *entry); entry->key = key; hash_insert (muscle_table, entry); } @@ -133,7 +133,7 @@ muscle_grow (const char *key, const char *val, const char *separator) if (!entry) { /* First insertion in the hash. */ - MALLOC (entry, 1); + entry = xmalloc (sizeof *entry); entry->key = key; hash_insert (muscle_table, entry); entry->value = xstrdup (val); diff --git a/src/nullable.c b/src/nullable.c index 497ec0ad..feee2950 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -61,16 +61,16 @@ nullable_compute (void) symbol_number *s2; rule_list *p; - symbol_number *squeue = CALLOC (squeue, nvars); - short int *rcount = CALLOC (rcount, nrules); + symbol_number *squeue = xnmalloc (nvars, sizeof *squeue); + short int *rcount = xcalloc (nrules, sizeof *rcount); /* RITEM contains all the rules, including useless productions. Hence we must allocate room for useless nonterminals too. */ - rule_list **rsets = CALLOC (rsets, nvars); + rule_list **rsets = xcalloc (nvars, sizeof *rsets); /* This is said to be more elements than we actually use. Supposedly NRITEMS - NRULES is enough. But why take the risk? */ - rule_list *relts = CALLOC (relts, nritems + nvars + 1); + rule_list *relts = xnmalloc (nritems + nvars + 1, sizeof *relts); - CALLOC (nullable, nvars); + nullable = xcalloc (nvars, sizeof *nullable); s1 = s2 = squeue; p = relts; diff --git a/src/output.c b/src/output.c index a77546f1..bcfc514e 100644 --- a/src/output.c +++ b/src/output.c @@ -192,7 +192,7 @@ prepare_symbols (void) /* Output YYTOKNUM. */ { int i; - int *values = MALLOC (values, ntokens); + int *values = xnmalloc (ntokens, sizeof *values); for (i = 0; i < ntokens; ++i) values[i] = symbols[i]->user_token_number; muscle_insert_int_table ("toknum", values, @@ -212,13 +212,13 @@ prepare_rules (void) { rule_number r; unsigned int i = 0; - item_number *rhs = MALLOC (rhs, nritems); - unsigned int *prhs = MALLOC (prhs, nrules); - unsigned int *rline = MALLOC (rline, nrules); - symbol_number *r1 = MALLOC (r1, nrules); - unsigned int *r2 = MALLOC (r2, nrules); - short int *dprec = MALLOC (dprec, nrules); - short int *merger = MALLOC (merger, nrules); + item_number *rhs = xnmalloc (nritems, sizeof *rhs); + unsigned int *prhs = xnmalloc (nrules, sizeof *prhs); + unsigned int *rline = xnmalloc (nrules, sizeof *rline); + symbol_number *r1 = xnmalloc (nrules, sizeof *r1); + unsigned int *r2 = xnmalloc (nrules, sizeof *r2); + short int *dprec = xnmalloc (nrules, sizeof *dprec); + short int *merger = xnmalloc (nrules, sizeof *merger); for (r = 0; r < nrules; ++r) { @@ -272,7 +272,7 @@ static void prepare_states (void) { state_number i; - symbol_number *values = MALLOC (values, nstates); + symbol_number *values = xnmalloc (nstates, sizeof *values); for (i = 0; i < nstates; ++i) values[i] = states[i]->accessing_symbol; muscle_insert_symbol_number_table ("stos", values, @@ -498,7 +498,7 @@ prepare_actions (void) muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table, conflict_table[0], 1, high + 1); muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list, - conflict_list[0], 1, conflict_list_cnt); + 0, 1, conflict_list_cnt); } diff --git a/src/reader.c b/src/reader.c index 1cd035cc..e7016b23 100644 --- a/src/reader.c +++ b/src/reader.c @@ -108,7 +108,7 @@ get_merge_function (uniqstr name, uniqstr type, location loc) break; if (syms->next == NULL) { - MALLOC (syms->next, 1); + syms->next = xmalloc (sizeof syms->next[0]); syms->next->name = uniqstr_new (name); syms->next->type = uniqstr_new (type); syms->next->next = NULL; @@ -387,8 +387,8 @@ packgram (void) rule_number ruleno = 0; symbol_list *p = grammar; - CALLOC (ritem, nritems); - CALLOC (rules, nrules); + ritem = xnmalloc (nritems, sizeof *ritem); + rules = xnmalloc (nrules, sizeof *rules); while (p) { @@ -397,12 +397,14 @@ packgram (void) rules[ruleno].number = ruleno; rules[ruleno].lhs = p->sym; rules[ruleno].rhs = ritem + itemno; + rules[ruleno].prec = NULL; + rules[ruleno].dprec = p->dprec; + rules[ruleno].merger = p->merger; + rules[ruleno].precsym = NULL; rules[ruleno].location = p->location; rules[ruleno].useful = true; rules[ruleno].action = p->action; rules[ruleno].action_location = p->action_location; - rules[ruleno].dprec = p->dprec; - rules[ruleno].merger = p->merger; p = p->next; while (p && p->sym) diff --git a/src/reduce.c b/src/reduce.c index b9b6a3dd..b53948f9 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -247,7 +247,7 @@ reduce_grammar_tables (void) { int useful = 0; int useless = nrules - nuseless_productions; - rule *rules_sorted = MALLOC (rules_sorted, nrules); + rule *rules_sorted = xnmalloc (nrules, sizeof *rules_sorted); rule_number r; for (r = 0; r < nrules; ++r) rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r]; @@ -291,7 +291,7 @@ nonterminals_reduce (void) /* Map the nonterminals to their new index: useful first, useless afterwards. Kept for later report. */ - symbol_number *nontermmap = CALLOC (nontermmap, nvars); + symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap); n = ntokens; for (i = ntokens; i < nsyms; i++) if (bitset_test (V, i)) @@ -307,7 +307,7 @@ nonterminals_reduce (void) /* Shuffle elements of tables indexed by symbol number. */ { - symbol **symbols_sorted = MALLOC (symbols_sorted, nvars); + symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted); for (i = ntokens; i < nsyms; i++) symbols[i]->number = nontermmap[i - ntokens]; diff --git a/src/relation.c b/src/relation.c index 92d090ef..ecfc126d 100644 --- a/src/relation.c +++ b/src/relation.c @@ -98,16 +98,13 @@ relation_digraph (relation r, size_t size, bitsetv *function) unsigned int i; infinity = size + 2; - CALLOC (INDEX, size + 1); - CALLOC (VERTICES, size + 1); + INDEX = xcalloc (size + 1, sizeof *INDEX); + VERTICES = xnmalloc (size + 1, sizeof *VERTICES); top = 0; R = r; F = *function; - for (i = 0; i < size; i++) - INDEX[i] = 0; - for (i = 0; i < size; i++) if (INDEX[i] == 0 && R[i]) traverse (i); @@ -127,11 +124,11 @@ void relation_transpose (relation *R_arg, int n) { /* The result. */ - relation new_R = CALLOC (new_R, n); + relation new_R = xnmalloc (n, sizeof *new_R); /* END_R[I] -- next entry of NEW_R[I]. */ - relation end_R = CALLOC (end_R, n); + relation end_R = xnmalloc (n, sizeof *end_R); /* NEDGES[I] -- total size of NEW_R[I]. */ - int *nedges = CALLOC (nedges, n); + int *nedges = xcalloc (n, sizeof *nedges); int i, j; if (trace_flag & trace_sets) @@ -148,13 +145,16 @@ relation_transpose (relation *R_arg, int n) /* Allocate. */ for (i = 0; i < n; i++) - if (nedges[i] > 0) - { - relation_node *sp = CALLOC (sp, nedges[i] + 1); - sp[nedges[i]] = END_NODE; - new_R[i] = sp; - end_R[i] = sp; - } + { + relation_node *sp = NULL; + if (nedges[i] > 0) + { + sp = xnmalloc (nedges[i] + 1, sizeof *sp); + sp[nedges[i]] = END_NODE; + } + new_R[i] = sp; + end_R[i] = sp; + } /* Store. */ for (i = 0; i < n; i++) diff --git a/src/symlist.c b/src/symlist.c index 5b25ac56..c7510c43 100644 --- a/src/symlist.c +++ b/src/symlist.c @@ -32,7 +32,7 @@ symbol_list * symbol_list_new (symbol *sym, location loc) { - symbol_list *res = MALLOC (res, 1); + symbol_list *res = xmalloc (sizeof *res); res->next = NULL; res->sym = sym; res->location = loc; diff --git a/src/symtab.c b/src/symtab.c index 3bc01871..c0368f71 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -48,7 +48,7 @@ location startsymbol_location; static symbol * symbol_new (uniqstr tag, location loc) { - symbol *res = MALLOC (res, 1); + symbol *res = xmalloc (sizeof *res); uniqstr_assert (tag); res->tag = tag; @@ -587,7 +587,8 @@ symbols_token_translations_init (void) max_user_token_number = this->user_token_number; } - CALLOC (token_translations, max_user_token_number + 1); + token_translations = xnmalloc (max_user_token_number + 1, + sizeof *token_translations); /* Initialize all entries for literal tokens to 2, the internal token number for $undefined, which represents all invalid inputs. @@ -606,7 +607,7 @@ symbols_token_translations_init (void) void symbols_pack (void) { - CALLOC (symbols, nsyms); + symbols = xcalloc (nsyms, sizeof *symbols); symbols_do (symbol_check_alias_consistency_processor, NULL); symbols_do (symbol_pack_processor, NULL); diff --git a/src/tables.c b/src/tables.c index a1d1522d..ba2c7a0e 100644 --- a/src/tables.c +++ b/src/tables.c @@ -81,11 +81,11 @@ int nvectors; #define BASE_MAXIMUM INT_MAX #define BASE_MINIMUM INT_MIN -static base_number **froms = NULL; -static base_number **tos = NULL; -static unsigned int **conflict_tos = NULL; -static short int *tally = NULL; -static base_number *width = NULL; +static base_number **froms; +static base_number **tos; +static unsigned int **conflict_tos; +static short int *tally; +static base_number *width; /* For a given state, N = ACTROW[SYMBOL]: @@ -97,12 +97,12 @@ static base_number *width = NULL; typedef short int action_number; #define ACTION_NUMBER_MINIMUM SHRT_MIN -static action_number *actrow = NULL; +static action_number *actrow; /* FROMS and TOS are reordered to be compressed. ORDER[VECTOR] is the new vector number of VECTOR. We skip `empty' vectors (i.e., TALLY[VECTOR] = 0), and call these `entries'. */ -static vector_number *order = NULL; +static vector_number *order; static int nentries; base_number *base = NULL; @@ -112,9 +112,9 @@ base_number *base = NULL; base_number base_ninf = 0; static base_number *pos = NULL; -static unsigned int *conflrow = NULL; -unsigned int *conflict_table = NULL; -unsigned int *conflict_list = NULL; +static unsigned int *conflrow; +unsigned int *conflict_table; +unsigned int *conflict_list; int conflict_list_cnt; static int conflict_list_free; @@ -122,8 +122,8 @@ static int conflict_list_free; with more or less the original hard-coded value (which was SHRT_MAX). */ static int table_size = 32768; -base_number *table = NULL; -base_number *check = NULL; +base_number *table; +base_number *check; /* The value used in TABLE to denote explicit syntax errors (%nonassoc), a negative infinite. First defaults to ACTION_NUMBER_MININUM, but in order to keep small tables, renumbered as TABLE_ERROR, which @@ -153,13 +153,15 @@ table_grow (int desired) fprintf (stderr, "growing table and check from: %d to %d\n", old_size, table_size); - REALLOC (table, table_size); - REALLOC (check, table_size); - REALLOC (conflict_table, table_size); + table = xnrealloc (table, table_size, sizeof *table); + conflict_table = xnrealloc (conflict_table, table_size, + sizeof *conflict_table); + check = xnrealloc (check, table_size, sizeof *check); for (/* Nothing. */; old_size < table_size; ++old_size) { table[old_size] = 0; + conflict_table[old_size] = 0; check[old_size] = -1; } } @@ -208,6 +210,7 @@ conflict_row (state *s) /* Leave a 0 at the end. */ if (conflict_list_free <= 0) abort (); + conflict_list[conflict_list_cnt] = 0; conflict_list_cnt += 1; conflict_list_free -= 1; } @@ -373,7 +376,7 @@ save_row (state_number s) base_number *sp; base_number *sp1; base_number *sp2; - unsigned int *sp3 IF_LINT (= NULL); + unsigned int *sp3; /* Number of non default actions in S. */ count = 0; @@ -385,9 +388,10 @@ save_row (state_number s) return; /* Allocate non defaulted actions. */ - froms[s] = sp = CALLOC (sp1, count); - tos[s] = CALLOC (sp2, count); - conflict_tos[s] = nondeterministic_parser ? CALLOC (sp3, count) : NULL; + froms[s] = sp = sp1 = xnmalloc (count, sizeof *sp1); + tos[s] = sp2 = xnmalloc (count, sizeof *sp2); + conflict_tos[s] = sp3 = + nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL; /* Store non defaulted actions. */ for (i = 0; i < ntokens; i++) @@ -421,12 +425,12 @@ token_actions (void) int nconflict = nondeterministic_parser ? conflicts_total_count () : 0; - CALLOC (yydefact, nstates); + yydefact = xnmalloc (nstates, sizeof *yydefact); - CALLOC (actrow, ntokens); - CALLOC (conflrow, ntokens); + actrow = xnmalloc (ntokens, sizeof *actrow); + conflrow = xnmalloc (ntokens, sizeof *conflrow); - CALLOC (conflict_list, 1 + 2 * nconflict); + conflict_list = xnmalloc (1 + 2 * nconflict, sizeof *conflict_list); conflict_list_free = 2 * nconflict; conflict_list_cnt = 1; @@ -491,8 +495,8 @@ save_column (symbol_number sym, state_number default_state) return; /* Allocate room for non defaulted gotos. */ - froms[symno] = sp = CALLOC (sp1, count); - tos[symno] = CALLOC (sp2, count); + froms[symno] = sp = sp1 = xnmalloc (count, sizeof *sp1); + tos[symno] = sp2 = xnmalloc (count, sizeof *sp2); /* Store the state numbers of the non defaulted gotos. */ for (i = begin; i < end; i++) @@ -554,8 +558,8 @@ static void goto_actions (void) { symbol_number i; - short int *state_count = CALLOC (state_count, nstates); - MALLOC (yydefgoto, nvars); + short int *state_count = xnmalloc (nstates, sizeof *state_count); + yydefgoto = xnmalloc (nvars, sizeof *yydefgoto); /* For a given nterm I, STATE_COUNT[S] is the number of times there is a GOTO to S on I. */ @@ -751,11 +755,11 @@ pack_table (void) { int i; - CALLOC (base, nvectors); - CALLOC (pos, nentries); - CALLOC (table, table_size); - CALLOC (conflict_table, table_size); - CALLOC (check, table_size); + base = xnmalloc (nvectors, sizeof *base); + pos = xnmalloc (nentries, sizeof *pos); + table = xcalloc (table_size, sizeof *table); + conflict_table = xcalloc (table_size, sizeof *conflict_table); + check = xnmalloc (table_size, sizeof *check); lowzero = 0; high = 0; @@ -810,11 +814,11 @@ tables_generate (void) nvectors = state_number_as_int (nstates) + nvars; - CALLOC (froms, nvectors); - CALLOC (tos, nvectors); - CALLOC (conflict_tos, nvectors); - CALLOC (tally, nvectors); - CALLOC (width, nvectors); + froms = xcalloc (nvectors, sizeof *froms); + tos = xcalloc (nvectors, sizeof *tos); + conflict_tos = xcalloc (nvectors, sizeof *conflict_tos); + tally = xcalloc (nvectors, sizeof *tally); + width = xnmalloc (nvectors, sizeof *width); token_actions (); @@ -823,7 +827,7 @@ tables_generate (void) free (from_state); free (to_state); - CALLOC (order, nvectors); + order = xcalloc (nvectors, sizeof *order); sort_actions (); pack_table (); free (order); diff --git a/src/vcg.c b/src/vcg.c index d6ae21f8..d5f88141 100644 --- a/src/vcg.c +++ b/src/vcg.c @@ -418,9 +418,7 @@ add_edge (graph *g, edge *e) void add_classname (graph *g, int val, const char *name) { - struct classname *classname; - - MALLOC (classname, 1); + struct classname *classname = xmalloc (sizeof *classname); classname->no = val; classname->name = name; classname->next = g->classname; @@ -430,9 +428,7 @@ add_classname (graph *g, int val, const char *name) void add_infoname (graph *g, int integer, const char *str) { - struct infoname *infoname; - - MALLOC (infoname, 1); + struct infoname *infoname = xmalloc (sizeof *infoname); infoname->integer = integer; infoname->chars = str; infoname->next = g->infoname; @@ -444,9 +440,7 @@ void add_colorentry (graph *g, int color_idx, int red_cp, int green_cp, int blue_cp) { - struct colorentry *ce; - - MALLOC (ce, 1); + struct colorentry *ce = xmalloc (sizeof *ce); ce->color_index = color_idx; ce->red_cp = red_cp; ce->green_cp = green_cp; -- 2.45.2