[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
27-fyi-more-memory-macros.patch
From: |
Akim Demaille |
Subject: |
27-fyi-more-memory-macros.patch |
Date: |
Mon, 19 Nov 2001 10:03:53 +0100 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* src/system.h (LIST_FREE, shortcpy): New.
* src/LR0.c: Use them.
* src/output.c (free_itemsets, free_reductions, free_shifts):
Remove, replaced by LIST_FREE.
Index: src/LR0.c
--- src/LR0.c Sat, 17 Nov 2001 16:51:03 +0100 akim
+++ src/LR0.c Sat, 17 Nov 2001 16:56:10 +0100 akim
@@ -196,9 +196,6 @@
{
int n;
core *p;
- short *isp1;
- short *isp2;
- short *iend;
#if TRACE
fprintf (stderr, "Entering new_state, symbol = %d\n", symbol);
@@ -207,18 +204,14 @@
if (nstates >= MAXSHORT)
fatal (_("too many states (max %d)"), MAXSHORT);
- isp1 = kernel_base[symbol];
- iend = kernel_end[symbol];
- n = iend - isp1;
+ n = kernel_end[symbol] - kernel_base[symbol];
p = CORE_ALLOC (n);
p->accessing_symbol = symbol;
p->number = nstates;
p->nitems = n;
- isp2 = p->items;
- while (isp1 < iend)
- *isp2++ = *isp1++;
+ shortcpy (p->items, kernel_base[symbol], n);
last_state->next = p;
last_state = p;
@@ -359,21 +352,13 @@
save_shifts (void)
{
shifts *p;
- short *sp1;
- short *sp2;
- short *send;
p = SHIFTS_ALLOC (nshifts);
p->number = this_state->number;
p->nshifts = nshifts;
- sp1 = shiftset;
- sp2 = p->shifts;
- send = shiftset + nshifts;
-
- while (sp1 < send)
- *sp2++ = *sp1++;
+ shortcpy (p->shifts, shiftset, nshifts);
if (last_shift)
{
@@ -602,8 +587,6 @@
save_reductions (void)
{
short *isp;
- short *rp1;
- short *rp2;
int item;
int count;
reductions *p;
@@ -629,12 +612,7 @@
p->number = this_state->number;
p->nreds = count;
- rp1 = redset;
- rp2 = p->rules;
- rend = rp1 + count;
-
- for (/* nothing */; rp1 < rend; ++rp1, ++rp2)
- *rp2 = *rp1;
+ shortcpy (p->rules, redset, count);
if (last_reduction)
{
Index: src/lalr.c
--- src/lalr.c Fri, 16 Nov 2001 01:00:46 +0100 akim
+++ src/lalr.c Sat, 17 Nov 2001 16:59:15 +0100 akim
@@ -653,14 +653,7 @@
/* Free LOOKBACK. */
for (i = 0; i < state_table[nstates].lookaheads; i++)
- {
- shorts *sptmp;
- for (sp = lookback[i]; sp; sp = sptmp)
- {
- sptmp = sp->next;
- XFREE (sp);
- }
- }
+ LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
XFREE (F);
Index: src/output.c
--- src/output.c Fri, 16 Nov 2001 01:37:30 +0100 akim
+++ src/output.c Sat, 17 Nov 2001 17:04:50 +0100 akim
@@ -761,33 +761,6 @@
static void
-free_shifts (void)
-{
- shifts *sp, *sptmp; /* JF derefrenced freed ptr */
-
- for (sp = first_shift; sp; sp = sptmp)
- {
- sptmp = sp->next;
- XFREE (sp);
- }
-}
-
-
-static void
-free_reductions (void)
-{
- reductions *rp, *rptmp; /* JF fixed freed ptr */
-
- for (rp = first_reduction; rp; rp = rptmp)
- {
- rptmp = rp->next;
- XFREE (rp);
- }
-}
-
-
-
-static void
save_column (int symbol, int default_state)
{
int i;
@@ -1136,8 +1109,8 @@
width = XCALLOC (short, nvectors);
token_actions ();
- free_shifts ();
- free_reductions ();
+ LIST_FREE (shifts, first_shift);
+ LIST_FREE (reductions, first_reduction);
XFREE (LA);
XFREE (LAruleno);
@@ -1306,18 +1279,6 @@
}
-static void
-free_itemsets (void)
-{
- core *cp, *cptmp;
- for (cp = first_state; cp; cp = cptmp)
- {
- cptmp = cp->next;
- XFREE (cp);
- }
-}
-
-
/*----------------------------------------------------------.
| Output the parsing tables and the parser code to ftable. |
`----------------------------------------------------------*/
@@ -1349,7 +1310,7 @@
if (!no_parser_flag)
obstack_sgrow (&table_obstack, "#include <stdio.h>\n\n");
- free_itemsets ();
+ LIST_FREE (core, first_state);
output_defines ();
output_token_translations ();
/* if (semantic_parser) */
Index: src/system.h
--- src/system.h Thu, 15 Nov 2001 08:56:59 +0100 akim
+++ src/system.h Sat, 17 Nov 2001 17:04:16 +0100 akim
@@ -279,6 +279,21 @@
#endif
+/* As memcpy, but for shorts. */
+#define shortcpy(Dest, Src, Num) \
+ memcpy (Dest, Src, Num * sizeof (short))
+
+/* Free a linked list. */
+#define LIST_FREE(Type, List) \
+do { \
+ Type *_node, *_next; \
+ for (_node = List; _node; _node = _next) \
+ { \
+ _next = _node->next; \
+ XFREE (_node); \
+ } \
+} while (0)
+
/*---------------------------------.
| Debugging the memory allocator. |
`---------------------------------*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 27-fyi-more-memory-macros.patch,
Akim Demaille <=