From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mimir.eigenstate.org ([206.124.132.107]) by ewsd; Fri Jul 10 00:12:49 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 0fa45f05 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Thu, 9 Jul 2020 21:12:41 -0700 (PDT) Message-ID: <3D93F0DE46D6A592DD3A6D46B07136EE@eigenstate.org> To: 9front@9front.org Subject: Re: [9front] x509.c for ape in libsec.a Date: Thu, 9 Jul 2020 21:12:40 -0700 From: ori@eigenstate.org In-Reply-To: <2FA65B5D5E2F244D28960EE0246D34B9@hera.eonet.ne.jp> 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: lossless pipelining optimizer >> The cpp time stamped Oct 7, 2019 does right thing, but that of Jul 17, >> 2020 fails. > s/Jul 17 2020/Jun 17 2020/ > > sorry > > Kenji 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 ... This diff seems to work, but it's late and it needs more testing. I've run it against our base system, netsurf, and perl. diff -r 7bd3f3b9dc76 sys/src/cmd/cpp/macro.c --- a/sys/src/cmd/cpp/macro.c Sun Jul 05 22:15:02 2020 +0200 +++ b/sys/src/cmd/cpp/macro.c Thu Jul 09 21:10:36 2020 -0700 @@ -169,15 +169,32 @@ } if (np->flag&ISMAC) builtin(trp, np->val); - else { + else expand(trp, np); - } tp = trp->tp; } if (flag) unsetsource(); } +void +hsspread(Tokenrow *ntr, Tokenrow *trp, Nlist *np) +{ + Token *tp; + int hs; + + hs = newhideset(trp->tp->hideset, np); + /* distribute hidesets */ + for (tp=ntr->bp; tplp; tp++) { + if (tp->type!=NAME) + continue; + if (tp->hideset==0) + tp->hideset = hs; + else + tp->hideset = unionhideset(tp->hideset, hs); + } +} + /* * Expand the macro whose name is np, at token trp->tp, in the tokenrow. * Return trp->tp at the first token next to be expanded @@ -186,17 +203,18 @@ void expand(Tokenrow *trp, Nlist *np) { + static int depth; 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; + hsspread(&ntr, trp, np); substargs(np, &ntr, atr); } else { ntokc = gatherargs(trp, atr, (np->flag&ISVARMAC) ? rowlen(np->ap) : 0, &narg); @@ -215,16 +233,9 @@ dofree(atr[i]->bp); dofree(atr[i]); } + hsspread(&ntr, trp, np); } - hs = newhideset(trp->tp->hideset, np); - for (tp=ntr.bp; tptype==NAME) { - if (tp->hideset==0) - tp->hideset = hs; - else - tp->hideset = unionhideset(tp->hideset, hs); - } - } + ntr.tp = ntr.bp; insertrow(trp, ntokc, &ntr); trp->tp -= rowlen(&ntr); @@ -343,6 +354,7 @@ } return 0; } + /* * substitute the argument list into the replacement string * This would be simple except for ## and # @@ -408,7 +420,7 @@ if(ttr.tp->hideset == 0) ttr.tp->hideset = hs; else - ttr.tp->hideset = unionhideset(ttr.tp->hideset, hs); + ttr.tp->hideset = unionhideset(rtr->tp->hideset, hs); expandrow(&ttr, (char*)np->name); for(tp = ttr.bp; tp != ttr.lp; tp++) if(tp->type == COMMA)