1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/*
\funcref{discard}{VAR\_ discard (\params)}
{
{VAR\_} {v} {variable to discard}
}
{variable, possibly after discarding}
{}
{}
{discard.c}
{
Function {\em discard()} may be called when a variable or
intermediate result is no longer needed. The function checks if the
type of the variable is {\em e\_list} or {\em e\_str}; if so, the
associated memory possibly may be freed.
Whether the associated memory actually may be freed depends on the
{\em vu.i$\rightarrow$count} field of the variable; since several
variables may point to the same occupied memory. If this count is 1,
then memory actually may be freed.
If the associated memory may not be freed due to multiple occupation,
then the {\em vu.i$\rightarrow$count} field is simply decreased.
}
*/
#include "icm-exec.h"
VAR_ discard (v)
VAR_ v;
{
register unsigned
i;
if ( (v.type & (e_str | e_list)) && v.vu.i && v.vu.i->count)
{
v.vu.i->count --;
if (! v.vu.i->count)
{
if (v.type & e_str)
xrealloc (v.vu.i->ls.str, 0);
else
{
for (i = 0; i < v.vu.i->ls.list.size; i++)
xrealloc (v.vu.i->ls.list.element [i], 0);
xrealloc (v.vu.i->ls.list.element, 0);
}
v.vu.i = xrealloc (v.vu.i, 0);
}
}
return (v);
}
|