9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: 9fans@9fans.net
Subject: Re: [9fans] Local variables and rc functions
Date: Thu, 14 Aug 2008 10:32:11 -0400	[thread overview]
Message-ID: <20080814142940.252CB1E8C35@holo.morphisms.net> (raw)

> 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



             reply	other threads:[~2008-08-14 14:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-14 14:32 Russ Cox [this message]
2008-08-14 18:10 ` Micah Stetson
  -- strict thread matches above, loose matches on Subject: below --
2008-08-13 21:27 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080814142940.252CB1E8C35@holo.morphisms.net \
    --to=rsc@swtch.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).