From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@9fans.net Subject: Re: [9fans] Local variables and rc functions From: "Russ Cox" Date: Thu, 14 Aug 2008 10:32:11 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20080814142940.252CB1E8C35@holo.morphisms.net> Topicbox-Message-UUID: fe27729a-ead3-11e9-9d60-3106f5b1d025 > Is this a bug? > > % fn foo { echo $bar } > % bar=baz foo > > % > > I would expect to see baz instead of a blank line. Yes, it is a bug. The fix is: diff -r f7e7b9ab4cfb src/cmd/rc/simple.c --- a/src/cmd/rc/simple.c Sun Jul 20 06:17:17 2008 -0400 +++ b/src/cmd/rc/simple.c Thu Aug 14 10:27:08 2008 -0400 @@ -130,7 +130,7 @@ execfunc(var *func) starval = runq->argv->words; runq->argv->words = 0; poplist(); - start(func->fn, func->pc, (struct var *)0); + start(func->fn, func->pc, runq->local); runq->local = newvar(strdup("*"), runq->local); runq->local->val = starval; runq->local->changed = 1; There's also a small performance bug here: diff -r f7e7b9ab4cfb src/cmd/rc/code.c --- a/src/cmd/rc/code.c Sun Jul 20 06:17:17 2008 -0400 +++ b/src/cmd/rc/code.c Thu Aug 14 10:27:08 2008 -0400 @@ -339,9 +339,9 @@ outcode(tree *t, int eflag) outcode(c0, eflag); emitf(Xlocal); } - t = tt; - outcode(c2, eflag); - for(;t->type=='=';t = c2) emitf(Xunlocal); + outcode(t, eflag); + for(t = tt; t->type=='='; t = c2) + emitf(Xunlocal); } else{ for(t = tt;t;t = c2){ Both fixes are in plan9port. Russ