From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mimir.eigenstate.org ([206.124.132.107]) by ewsd; Sun Jul 12 21:39:22 EDT 2020 Received: from abbatoir.fios-router.home (pool-74-101-2-6.nycmny.fios.verizon.net [74.101.2.6]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 51d0b12b (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Sun, 12 Jul 2020 18:39:07 -0700 (PDT) Message-ID: <0721D0AD992D75DF6B9C990154CC1CFE@eigenstate.org> To: 9front@9front.org Subject: Re: [9front] x509.c for ape in libsec.a Date: Sun, 12 Jul 2020 18:39:06 -0700 From: ori@eigenstate.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: social agile DOM-aware full-stack-based browser extension factory-based component backend >> Alright, I think I have a fix for this issue. We need to put the >> macro into the hideset before doing the final pass, or there's >> potential for macro expansion to cycle in some cases. >> >> expand(A) => B >> expand(B) => A >> expand(A) => B > > Thank you very much Ori. > > Yes, it works fine here, too. > > Kenji It isn't quite right, though I haven't found any real-world code that causes the problem, just artificial test cases. I think this one should be regression-free. diff -r 0cfcc2f8b898 sys/src/cmd/cpp/cpp.h --- a/sys/src/cmd/cpp/cpp.h Sat Jul 11 13:28:58 2020 -0700 +++ b/sys/src/cmd/cpp/cpp.h Sun Jul 12 18:38:00 2020 -0700 @@ -110,7 +110,7 @@ void expand(Tokenrow *, Nlist *); void builtin(Tokenrow *, int); int gatherargs(Tokenrow *, Tokenrow **, int, int *); -void substargs(Nlist *, Tokenrow *, Tokenrow **); +void substargs(Nlist *, Tokenrow *, Tokenrow **, int); void expandrow(Tokenrow *, char *); void maketokenrow(int, Tokenrow *); Tokenrow *copytokenrow(Tokenrow *, Tokenrow *); diff -r 0cfcc2f8b898 sys/src/cmd/cpp/macro.c --- a/sys/src/cmd/cpp/macro.c Sat Jul 11 13:28:58 2020 -0700 +++ b/sys/src/cmd/cpp/macro.c Sun Jul 12 18:38:00 2020 -0700 @@ -169,9 +169,8 @@ } if (np->flag&ISMAC) builtin(trp, np->val); - else { + else expand(trp, np); - } tp = trp->tp; } if (flag) @@ -186,18 +185,19 @@ void expand(Tokenrow *trp, Nlist *np) { + static int depth; + int ntokc, narg, i, hs; + Tokenrow *atr[NARG+1]; Tokenrow ntr; - int ntokc, narg, i; Token *tp; - Tokenrow *atr[NARG+1]; - int hs; + depth++; copytokenrow(&ntr, np->vp); /* copy macro value */ if (np->ap==NULL) { /* parameterless */ ntokc = 1; /* substargs for handling # and ## */ atr[0] = nil; - substargs(np, &ntr, atr); + substargs(np, &ntr, atr, trp->tp->hideset); } else { ntokc = gatherargs(trp, atr, (np->flag&ISVARMAC) ? rowlen(np->ap) : 0, &narg); if (narg<0) { /* not actually a call (no '(') */ @@ -210,12 +210,13 @@ trp->tp += ntokc; return; } - substargs(np, &ntr, atr); /* put args into replacement */ + substargs(np, &ntr, atr, trp->tp->hideset); /* put args into replacement */ for (i=0; ibp); dofree(atr[i]); } } + hs = newhideset(trp->tp->hideset, np); for (tp=ntr.bp; tptype==NAME) { @@ -343,19 +344,20 @@ } return 0; } + /* * substitute the argument list into the replacement string * This would be simple except for ## and # */ void -substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr) +substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr, int hideset) { Tokenrow ttr, rp, rn; Token *tp, *ap, *an, *pp, *pn; int ntok, argno, hs; for (rtr->tp=rtr->bp; rtr->tplp; ) { - if(rtr->tp->hideset && checkhideset(rtr->tp->hideset, np)) { + if(rtr->tp->hideset && checkhideset(hideset, np)) { rtr->tp++; } else if (rtr->tp->type==SHARP) { /* string operator */ tp = rtr->tp; @@ -405,10 +407,10 @@ *ttr.tp = *rtr->tp; hs = newhideset(rtr->tp->hideset, np); - if(ttr.tp->hideset == 0) + if(hideset == 0) ttr.tp->hideset = hs; else - ttr.tp->hideset = unionhideset(ttr.tp->hideset, hs); + ttr.tp->hideset = unionhideset(hideset, hs); expandrow(&ttr, (char*)np->name); for(tp = ttr.bp; tp != ttr.lp; tp++) if(tp->type == COMMA)