From f4ab07b48c747e8dade9ee85369445de3a10d669 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 8 May 2016 22:07:09 +0200 Subject: [PATCH] Add typeset -C to control whether to assert the cached length --- Src/builtin.c | 8 ++++---- Src/params.c | 29 ++++++++++++++++++----------- Src/subst.c | 8 ++++++-- Src/zsh.h | 3 ++- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Src/builtin.c b/Src/builtin.c index 6ce313d88..ba7136eb4 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -55,7 +55,7 @@ static struct builtin builtins[] = BUILTIN("cd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_CD, "qsPL", NULL), BUILTIN("chdir", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_CD, "qsPL", NULL), BUILTIN("continue", BINF_PSPECIAL, bin_break, 0, 1, BIN_CONTINUE, NULL, NULL), - BUILTIN("declare", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%acfghi:%klmprtuxz", NULL), + BUILTIN("declare", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "ACE:%F:%HL:%R:%TUZ:%acfghi:%klmprtuxz", NULL), BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "clpv", NULL), BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmprs", NULL), BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL), @@ -88,7 +88,7 @@ static struct builtin builtins[] = BUILTIN("jobs", 0, bin_fg, 0, -1, BIN_JOBS, "dlpZrs", NULL), BUILTIN("kill", BINF_HANDLES_OPTS, bin_kill, 0, -1, 0, NULL, NULL), BUILTIN("let", 0, bin_let, 1, -1, 0, NULL, NULL), - BUILTIN("local", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%achi:%lprtux", NULL), + BUILTIN("local", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "ACE:%F:%HL:%R:%TUZ:%achi:%lprtux", NULL), BUILTIN("log", 0, bin_log, 0, 0, 0, NULL, NULL), BUILTIN("logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL), @@ -108,7 +108,7 @@ static struct builtin builtins[] = BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL), BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "IlLnr", NULL), BUILTIN("read", 0, bin_read, 0, -1, 0, "cd:ek:%lnpqrst:%zu:AE", NULL), - BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, BIN_READONLY, "AE:%F:%HL:%R:%TUZ:%acfghi:%lptux", "r"), + BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, BIN_READONLY, "ACE:%F:%HL:%R:%TUZ:%acfghi:%lptux", "r"), BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"), BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL), BUILTIN("set", BINF_PSPECIAL | BINF_HANDLES_OPTS, bin_set, 0, -1, 0, NULL, NULL), @@ -122,7 +122,7 @@ static struct builtin builtins[] = BUILTIN("trap", BINF_PSPECIAL | BINF_HANDLES_OPTS, bin_trap, 0, -1, 0, NULL, NULL), BUILTIN("true", 0, bin_true, 0, -1, 0, NULL, NULL), BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsSw", "v"), - BUILTIN("typeset", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%acfghi:%klprtuxmz", NULL), + BUILTIN("typeset", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "ACE:%F:%HL:%R:%TUZ:%acfghi:%klprtuxmz", NULL), BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL), BUILTIN("unalias", 0, bin_unhash, 0, -1, BIN_UNALIAS, "ams", NULL), BUILTIN("unfunction", 0, bin_unhash, 1, -1, BIN_UNFUNCTION, "m", "f"), diff --git a/Src/params.c b/Src/params.c index 4a5db3c1d..2e4dd4ee6 100644 --- a/Src/params.c +++ b/Src/params.c @@ -28,7 +28,6 @@ */ #include -//#define assert(x) #include "zsh.mdh" #include "params.pro" @@ -1470,7 +1469,8 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w, return !down; if (v->pm->node.flags & PM_CACHELEN) { len = arrcachelen(v->pm); - assert(len == arrlen(ta)); + if (v->pm->node.flags & PM_CHECKLEN) + assert(len == arrlen(ta)); } else len = arrlen(ta); if (beg < 0) @@ -1497,7 +1497,8 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w, ta = sepsplit(d = s = getstrvalue(v), sep, 1, 1); if (v->pm->node.flags & PM_CACHELEN) { len = arrcachelen(v->pm); - assert(len == arrlen(ta)); + if (v->pm->node.flags & PM_CHECKLEN) + assert(len == arrlen(ta)); } else len = arrlen(ta); if (beg < 0) @@ -2051,7 +2052,8 @@ getstrvalue(Value v) else { if (v->pm->node.flags & PM_CACHELEN) { int len = arrcachelen(v->pm); - assert(v->pm->length == arrlen(ss)); + if (v->pm->node.flags & PM_CHECKLEN) + assert(v->pm->length == arrlen(ss)); if (v->start < 0) v->start += len; s = (v->start >= len || v->start < 0) ? @@ -2258,7 +2260,8 @@ getarrvalue(Value v) return s; if (v->pm->node.flags & PM_CACHELEN) { int len = arrcachelen(v->pm); - assert(v->pm->length == arrlen(s)); + if (v->pm->node.flags & PM_CHECKLEN) + assert(v->pm->length == arrlen(s)); if (v->start < 0) v->start += v->pm->length; if (v->end < 0) @@ -2612,9 +2615,10 @@ setarrvalue(Value v, char **val) int post_assignment_length; int i; - if (v->pm->node.flags & PM_CACHELEN) - assert(v->pm->length == arrlen(old)); - else + if (v->pm->node.flags & PM_CACHELEN) { + if (v->pm->node.flags & PM_CHECKLEN) + assert(v->pm->length == arrlen(old)); + } else pre_assignment_length = arrlen(old); q = old; @@ -2728,7 +2732,8 @@ getaparam(char *s, int *len) if (len) { if (v->pm->node.flags & PM_CACHELEN) { *len = arrcachelen(v->pm); - assert (*len == arrlen(v->pm->gsu.a->getfn(v->pm))); + if (v->pm->node.flags & PM_CHECKLEN) + assert (*len == arrlen(v->pm->gsu.a->getfn(v->pm))); } else *len = arrlen(v->pm->gsu.a->getfn(v->pm)); } @@ -3006,7 +3011,8 @@ assignaparam(char *s, char **val, int flags) v->start = //arrlen(v->pm->gsu.a->getfn(v->pm)); arrcachelen(v->pm); - assert(v->pm->length == arrlen(v->pm->gsu.a->getfn(v->pm))); + if (v->pm->node.flags & PM_CHECKLEN) + assert(v->pm->length == arrlen(v->pm->gsu.a->getfn(v->pm))); } else { v->start = arrlen(v->pm->gsu.a->getfn(v->pm)); @@ -3022,7 +3028,8 @@ assignaparam(char *s, char **val, int flags) v->end //= arrlen(v->pm->gsu.a->getfn(v->pm)) + v->end; += arrcachelen(v->pm); - assert(v->pm->length == arrlen(v->pm->gsu.a->getfn(v->pm))); + if (v->pm->node.flags & PM_CHECKLEN) + assert(v->pm->length == arrlen(v->pm->gsu.a->getfn(v->pm))); } else { v->end = arrlen(v->pm->gsu.a->getfn(v->pm)) + v->end; diff --git a/Src/subst.c b/Src/subst.c index cc59c74d4..7081d467d 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -27,6 +27,8 @@ * */ +#include + #include "zsh.mdh" #include "subst.pro" @@ -2551,9 +2553,11 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * to avoid the multsub() horror. */ int tmplen; - if (v->pm->node.flags & PM_CACHELEN) + if (v->pm->node.flags & PM_CACHELEN) { tmplen = arrcachelen(v->pm); - else + if (v->pm->node.flags & PM_CHECKLEN) + assert(tmplen == arrlen(v->pm->gsu.a->getfn(v->pm))); + } else tmplen = arrlen(v->pm->gsu.a->getfn(v->pm)); if (v->start < 0) diff --git a/Src/zsh.h b/Src/zsh.h index bf89272f2..fe88efe69 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1792,6 +1792,7 @@ struct tieddata { #define PM_KSHSTORED (1<<17) /* function stored in ksh form */ #define PM_ZSHSTORED (1<<18) /* function stored in zsh form */ #define PM_CACHELEN (1<<19) /* length is cached */ +#define PM_CHECKLEN (1<<20) /* cached length is checked */ /* Remaining flags do not correspond directly to command line arguments */ #define PM_LOCAL (1<<21) /* this parameter will be made local */ @@ -1810,7 +1811,7 @@ struct tieddata { #define PM_NAMEDDIR (1<<30) /* has a corresponding nameddirtab entry */ /* The option string corresponds to the first of the variables above */ -#define TYPESET_OPTSTR "aiEFALRZlurtxUhHTkzc" +#define TYPESET_OPTSTR "aiEFALRZlurtxUhHTkzcC" /* These typeset options take an optional numeric argument */ #define TYPESET_OPTNUM "LRZiEF"