zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: <zsh-workers@zsh.org>
Cc: <chet.ramey@case.edu>
Subject: Re: Bug with bash emulation regarding ':'
Date: Sun, 19 Feb 2012 15:45:15 -0800	[thread overview]
Message-ID: <120219154515.ZM7225@torch.brasslantern.com> (raw)
In-Reply-To: <20120215123641.01e5a4fd@pwslap01u.europe.root.pri>

On Feb 15, 12:36pm, Peter Stephenson wrote:
}
} To get this behaviour in zsh we'd have to do the assignment earlier
} than we currently do.  The assignments around line 2705 of subst.c would
} need to buried inside multsub() in such a way that any splitting owing to
} the top-level settings happened later --- which is very difficult since
} we rely on the nested substitution to do the splitting we see in the
} top-level parameter expansion because it parses it so knows how to split
} it.  Whether there are remaining gotchas owing to ordering I don't know.

I've been puzzling over this on and off for the last few days and it just
doesn't seem as though it ought to be that hard.

There are some comments in subst.c like this one:

	 * This is where we extract a value (we know now we have
	 * one) into the local parameters for a scalar (val) or
	 * array (aval) value.  TODO: move val and aval into
	 * a structure with a discriminator.  Hope we can make
	 * more things array values at this point and dearrayify later.
	 * v->isarr tells us whether the stuff from down below looks
	 * like an array.

So at first I was thinking that it might be time to do that, so multsub
could for example return both the split and not-split expansions of the
right-side of the assignment and the caller would then use one for the
assignment and the other for the inline expansion.  But then I traced
the call and discovered that the newlines have already been removed and
rejoined as spaces before multsub even returns; the call that handles
this branch doesn't even pass down the aval parameter.

Hence it appears "we rely on the nested substitution to do the splitting
we see in the top-level parameter expansion" is incorrect, at least in
this instance?

Consequently I tried this:

--- ../zsh-forge/current/Src/subst.c	2012-02-12 13:31:49.000000000 -0800
+++ Src/subst.c	2012-02-19 15:19:49.000000000 -0800
@@ -2693,7 +2693,7 @@
 		*idend = '\0';
 		val = dupstring(s);
 		if (spsep || !arrasg) {
-		    multsub(&val, PREFORK_NOSHWORDSPLIT, NULL, &isarr, NULL);
+		    multsub(&val, PREFORK_SINGLE|PREFORK_NOSHWORDSPLIT, NULL,
&isarr, NULL);
 		} else {
 		    if (spbreak)
 			split_flags = PREFORK_SPLIT|PREFORK_SHWORDSPLIT;

This faithfully reproduces the bash behavior in several tests I tried.
In fact it may be that PREFORK_SINGLE is the only thing needed there,
and PREFORK_NOSHWORDSPLIT is extraneous?  (Aside:  My first thought
was to use PREFORK_ASSIGN, but that's only used in filesub.  A more
thorough approach might be to teach multsub about assignment context.)

Have I missed something important?

(Chet Cc'd just for interest, he can probably be dropped from further
discussion on this topic.)


  reply	other threads:[~2012-02-19 23:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-29  2:46 Felipe Contreras
2012-01-29  5:31 ` Benjamin R. Haskell
2012-01-29 13:44   ` Felipe Contreras
2012-01-29 14:25     ` Mikael Magnusson
2012-01-29 14:27       ` Mikael Magnusson
2012-01-29 18:38       ` Vincent Lefevre
2012-01-29 18:53         ` Mikael Magnusson
2012-01-29 19:01           ` Vincent Lefevre
2012-01-29 20:30             ` Peter Stephenson
2012-01-29 21:05               ` Mikael Magnusson
2012-01-30 22:15       ` Felipe Contreras
2012-01-30 22:18         ` Mikael Magnusson
2012-01-29 18:36 ` Peter Stephenson
2012-02-01  4:29   ` Bart Schaefer
2012-02-01 16:29     ` Bart Schaefer
2012-02-05 20:11       ` Peter Stephenson
2012-02-05 21:21         ` Bart Schaefer
2012-02-10 21:04           ` Peter Stephenson
2012-02-11 21:08             ` Bart Schaefer
2012-02-12 20:29               ` Peter Stephenson
2012-02-14 17:41         ` Peter Stephenson
2012-02-14 23:30           ` Chet Ramey
2012-02-15 12:36             ` Peter Stephenson
2012-02-19 23:45               ` Bart Schaefer [this message]
2012-02-20  8:48                 ` Bart Schaefer
2012-02-20 10:59                 ` Peter Stephenson
2012-02-20 17:09                   ` Bart Schaefer
2012-01-30 19:22 ` Felipe Contreras
2012-02-10 11:08 Jilles Tjoelker

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=120219154515.ZM7225@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=chet.ramey@case.edu \
    --cc=zsh-workers@zsh.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).