9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Local variables and rc functions
@ 2008-08-13 21:27 Micah Stetson
  2008-08-14  9:25 ` roger peppe
  0 siblings, 1 reply; 7+ messages in thread
From: Micah Stetson @ 2008-08-13 21:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Is this a bug?

% fn foo { echo $bar }
% bar=baz foo

%

I would expect to see baz instead of a blank line.

Micah



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [9fans] Local variables and rc functions
@ 2008-08-14 14:32 Russ Cox
  2008-08-14 18:10 ` Micah Stetson
  0 siblings, 1 reply; 7+ messages in thread
From: Russ Cox @ 2008-08-14 14:32 UTC (permalink / raw)
  To: 9fans

> 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-08-14 18:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-13 21:27 [9fans] Local variables and rc functions Micah Stetson
2008-08-14  9:25 ` roger peppe
2008-08-14 11:20   ` kazumi iwane
2008-08-14 12:14     ` roger peppe
2008-08-14 12:47       ` kazumi iwane
2008-08-14 14:32 Russ Cox
2008-08-14 18:10 ` Micah Stetson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).