diff --git a/expr.c b/expr.c index ac4a637..4ea1d87 100644 --- a/expr.c +++ b/expr.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.32 2009/08/28 20:38:41 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.33 2009/08/28 21:01:25 tg Exp $"); /* The order of these enums is constrained by the order of opinfo[] */ enum token { @@ -610,8 +610,8 @@ tempvar(void) vp->areap = ATEMP; #ifdef notyet_ktremove vp->tablep = NULL; - vp->hval = 0; #endif + vp->ua.hval = 0; vp->val.i = 0; vp->name[0] = '\0'; return (vp); diff --git a/funcs.c b/funcs.c index b07e628..b8775d7 100644 --- a/funcs.c +++ b/funcs.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.123 2009/08/28 20:30:56 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.124 2009/08/28 21:01:25 tg Exp $"); #if HAVE_KILLPG /* @@ -1010,7 +1010,9 @@ c_typeset(const char **wp) if ((vp->flag&ARRAY) && any_set) shprintf("%s[%lu]", vp->name, - (unsigned long)vp->index); + vp->flag & AINDEX ? + (unsigned long)vp->ua.index : + 0); else shf_puts(vp->name, shl_stdout); if (thing == '-' && (vp->flag&ISSET)) { diff --git a/main.c b/main.c index 0475320..a729d11 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.141 2009/08/28 20:38:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.142 2009/08/28 21:01:26 tg Exp $"); extern char **environ; @@ -1278,13 +1278,8 @@ texpand(struct table *tp, size_t nsize) for (i = 0; i < osize; i++) if ((tblp = otblp[i]) != NULL) { if ((tblp->flag & DEFINED)) { -#ifdef notyet_ktremove - for (p = &ntblp[tblp->hval & + for (p = &ntblp[tblp->ua.hval & (tp->size - 1)]; *p != NULL; p--) -#else - for (p = &ntblp[hash(tblp->name) & - (tp->size - 1)]; *p != NULL; p--) -#endif if (p == ntblp) /* wrap */ p += tp->size; *p = tblp; @@ -1314,12 +1309,8 @@ ktscan(struct table *tp, const char *n, uint32_t h, struct tbl ***ppp) /* search for name in hashed table */ for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) { -#ifdef notyet_ktremove - if (p->hval == h && !strcmp(p->name, n) && (p->flag & DEFINED)) -#else - if (*p->name == *n && !strcmp(p->name, n) && + if (p->ua.hval == h && !strcmp(p->name, n) && (p->flag & DEFINED)) -#endif goto found; if (pp == tp->tbls) /* wrap */ @@ -1368,8 +1359,8 @@ ktenter(struct table *tp, const char *n, uint32_t h) p->areap = tp->areap; #ifdef notyet_ktremove p->tablep = tp; - p->hval = h; #endif + p->ua.hval = h; p->u2.field = 0; p->u.array = NULL; memcpy(p->name, n, len); @@ -1387,7 +1378,7 @@ ktremove(struct tbl *p) struct tbl **pp; if (p->tablep && p->tablep->size && ktscan(p->tablep, p->name, - p->hval, &pp) == p) { + p->ua.hval, &pp) == p) { /* ktremove p */ *pp = NULL; p->tablep->nfree++; diff --git a/sh.h b/sh.h index 4daa211..6116c61 100644 --- a/sh.h +++ b/sh.h @@ -134,7 +134,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.329 2009/08/28 20:38:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.330 2009/08/28 21:01:26 tg Exp $"); #endif #define MKSH_VERSION "R39 2009/08/08" @@ -874,10 +874,10 @@ struct tbl { /* table item */ int type; /* command type (see below), base (if INTEGER), * or offset from val.s of value (if EXPORT) */ Tflag flag; /* flags */ -#ifdef notyet_ktremove - uint32_t hval; /* hash(name) */ -#endif - uint32_t index; /* index for an array */ + union { + uint32_t hval; /* hash(name) */ + uint32_t index; /* index for an array */ + } ua; char name[4]; /* name -- variable length */ }; @@ -905,6 +905,7 @@ struct tbl { /* table item */ #define LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */ #define EXPRINEVAL BIT(23) /* contents currently being evaluated */ #define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */ +#define AINDEX BIT(25) /* array index >0 = ua.index filled in */ /* flag bits used for taliases/builtins/aliases/keywords/functions */ #define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */ #define FINUSE BIT(9) /* function being executed */ diff --git a/var.c b/var.c index 48d9ef0..da319da 100644 --- a/var.c +++ b/var.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.81 2009/08/28 20:38:43 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.82 2009/08/28 21:01:27 tg Exp $"); /* * Variables @@ -1241,35 +1241,34 @@ arraysearch(struct tbl *vp, uint32_t val) size_t len; vp->flag |= ARRAY|DEFINED; - vp->index = 0; /* The table entry is always [0] */ if (val == 0) return (vp); prev = vp; curr = vp->u.array; - while (curr && curr->index < val) { + while (curr && curr->ua.index < val) { prev = curr; curr = curr->u.array; } - if (curr && curr->index == val) { + if (curr && curr->ua.index == val) { if (curr->flag&ISSET) return (curr); new = curr; } else new = NULL; len = strlen(vp->name) + 1; - if (!new) + if (!new) { new = alloc(offsetof(struct tbl, name[0]) + len, vp->areap); - memcpy(new->name, vp->name, len); - new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL); + memcpy(new->name, vp->name, len); + } + new->flag = (vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL)) | AINDEX; new->type = vp->type; new->areap = vp->areap; new->u2.field = vp->u2.field; - new->index = val; + new->ua.index = val; #ifdef notyet_ktremove /* XXX array indices must not be ktdelete'd, for now */ new->tablep = NULL; - new->hval = vp->hval; #endif if (curr != new) { /* not reusing old array entry */