this is a rather stupid diff: give ktsearch/ktenter the capability to

return information needed to do a real ktremove instead of the pseudo
ktdelete operation which merely unsets the DEFINED flag to mark it as
eligible for texpand garbage collection (even worse, !DEFINED entries
are still counted)
This commit is contained in:
tg
2009-08-28 19:57:43 +00:00
parent cd7f3fd836
commit 7240c843ce
9 changed files with 95 additions and 55 deletions

31
var.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.78 2009/08/28 18:54:01 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.79 2009/08/28 19:57:43 tg Exp $");
/*
* Variables
@ -128,7 +128,8 @@ initvar(void)
ktinit(&specials, APERM,
/* must be 80% of 2^n (currently 12 specials) */ 16);
for (i = 0; names[i].name; i++) {
tp = ktenter(&specials, names[i].name, hash(names[i].name));
tp = ktenter(&specials, names[i].name, hash(names[i].name),
NULL);
tp->flag = DEFINED|ISSET;
tp->type = names[i].v;
}
@ -225,7 +226,7 @@ global(const char *n)
return (vp);
}
for (l = e->loc; ; l = l->next) {
vp = ktsearch(&l->vars, n, h);
vp = ktsearch(&l->vars, n, h, NULL);
if (vp != NULL) {
if (array)
return (arraysearch(vp, val));
@ -235,7 +236,7 @@ global(const char *n)
if (l->next == NULL)
break;
}
vp = ktenter(&l->vars, n, h);
vp = ktenter(&l->vars, n, h, NULL);
if (array)
vp = arraysearch(vp, val);
vp->flag |= DEFINED;
@ -265,12 +266,13 @@ local(const char *n, bool copy)
vp->areap = ATEMP;
return (vp);
}
vp = ktenter(&l->vars, n, h);
vp = ktenter(&l->vars, n, h, NULL);
if (copy && !(vp->flag & DEFINED)) {
struct block *ll = l;
struct tbl *vq = NULL;
while ((ll = ll->next) && !(vq = ktsearch(&ll->vars, n, h)))
while ((ll = ll->next) && !(vq = ktsearch(&ll->vars, n, h,
NULL)))
;
if (vq) {
vp->flag |= vq->flag &
@ -892,7 +894,8 @@ makenv(void)
/* unexport any redefined instances */
for (l2 = l->next; l2 != NULL; l2 = l2->next) {
vp2 = ktsearch(&l2->vars, vp->name, h);
vp2 = ktsearch(&l2->vars, vp->name, h,
NULL);
if (vp2 != NULL)
vp2->flag &= ~EXPORT;
}
@ -1026,7 +1029,7 @@ special(const char *name)
{
struct tbl *tp;
tp = ktsearch(&specials, name, hash(name));
tp = ktsearch(&specials, name, hash(name), NULL);
return (tp && (tp->flag & ISSET) ? tp->type : V_NONE);
}
@ -1034,15 +1037,15 @@ special(const char *name)
static void
unspecial(const char *name)
{
struct tbl *tp;
struct table_entry te = { NULL, NULL };
tp = ktsearch(&specials, name, hash(name));
if (tp)
ktdelete(tp);
ktsearch(&specials, name, hash(name), &te);
if (te.ep)
ktremove(&te);
}
static time_t seconds; /* time SECONDS last set */
static int user_lineno; /* what user set $LINENO to */
static time_t seconds; /* time SECONDS last set */
static int user_lineno; /* what user set $LINENO to */
static void
getspec(struct tbl *vp)