zsh-workers
 help / color / mirror / code / Atom feed
* $* assignment regression in shwordsplit
@ 2017-04-02 17:45 Martijn Dekker
  2017-04-02 17:49 ` Martijn Dekker
  2017-04-02 17:58 ` Daniel Shahaf
  0 siblings, 2 replies; 4+ messages in thread
From: Martijn Dekker @ 2017-04-02 17:45 UTC (permalink / raw)
  To: Zsh hackers list

In the current zsh development version[*], there is a regression with
assigning "$*" to a variable in shwordsplit mode when IFS is either
unset or empty. The "$*" is only expanded the first time it occurs.

$ Src/zsh -f -c 'set -- one two; unset IFS; var=$*/$*; echo $var $*/$*;
	setopt shwordsplit; var=$*/$*; echo "$var" "$*/$*"'
one two/one two one two/one two
one two/$* one two/one two

$ Src/zsh -f -c 'set -- one two; IFS=; var=$*/$*; echo $var $*/$*;
	setopt shwordsplit; var=$*/$*; echo "$var" "$*/$*"'
onetwo/onetwo onetwo/onetwo
onetwo/$* onetwo/onetwo

Thanks,

- M.

[*] as of commit eaeebeb8bb80cd7e2f5c703c7da31f44a1ab3182


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

* Re: $* assignment regression in shwordsplit
  2017-04-02 17:45 $* assignment regression in shwordsplit Martijn Dekker
@ 2017-04-02 17:49 ` Martijn Dekker
  2017-04-02 17:58 ` Daniel Shahaf
  1 sibling, 0 replies; 4+ messages in thread
From: Martijn Dekker @ 2017-04-02 17:49 UTC (permalink / raw)
  To: Zsh hackers list

Op 02-04-17 om 19:45 schreef Martijn Dekker:
> $ Src/zsh -f -c 'set -- one two; IFS=; var=$*/$*; echo $var $*/$*;
> 	setopt shwordsplit; var=$*/$*; echo "$var" "$*/$*"'
> onetwo/onetwo onetwo/onetwo
> onetwo/$* onetwo/onetwo

Correction, the output of this one is actually:

onetwo/onetwo one two/one two
onetwo/$* onetwo/onetwo

Had accidentally left the output of a previous version of the test that
quoted all 'echo' arguments even before setting shwordsplit. This
correction is just for accuracy, it's not actually relevant to the bug
report.

- M.


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

* Re: $* assignment regression in shwordsplit
  2017-04-02 17:45 $* assignment regression in shwordsplit Martijn Dekker
  2017-04-02 17:49 ` Martijn Dekker
@ 2017-04-02 17:58 ` Daniel Shahaf
  2017-04-02 20:15   ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2017-04-02 17:58 UTC (permalink / raw)
  To: zsh-workers

Martijn Dekker wrote on Sun, Apr 02, 2017 at 19:45:14 +0200:
> In the current zsh development version[*], there is a regression with
> assigning "$*" to a variable in shwordsplit mode when IFS is either
> unset or empty. The "$*" is only expanded the first time it occurs.
> 
> $ Src/zsh -f -c 'set -- one two; unset IFS; var=$*/$*; echo $var $*/$*;
> 	setopt shwordsplit; var=$*/$*; echo "$var" "$*/$*"'
> one two/one two one two/one two
> one two/$* one two/one two
> 
> $ Src/zsh -f -c 'set -- one two; IFS=; var=$*/$*; echo $var $*/$*;
> 	setopt shwordsplit; var=$*/$*; echo "$var" "$*/$*"'
> onetwo/onetwo onetwo/onetwo
> onetwo/$* onetwo/onetwo

Both of these bisect to:

commit 74fe4d0950d5db0bba9d8ec182c4a827728cff60
Author: Barton E. Schaefer <schaefer@zsh.org>
Date:   Mon Feb 20 13:22:55 2017 -0800

    40598: paramsubst() should always return scalar when PREFORK_SINGLE was passed

:100644 100644 0d3352a8e807172c7adcde89a7a769c1c704320c 60a5164d638eba63dcef57a7e7bbf7951ada4426 M      ChangeLog
:040000 040000 843e4c1065cbcdb63fb554ab97de69741351f78c e3d9d89d533c0cd63a7aaa0d714e232e024302ca M      Src



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

* Re: $* assignment regression in shwordsplit
  2017-04-02 17:58 ` Daniel Shahaf
@ 2017-04-02 20:15   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2017-04-02 20:15 UTC (permalink / raw)
  To: zsh-workers

Hrm.  Well, we can do it this way instead, but that changes the effects
of ${(u)...} and and ${^...} in the expansion, requiring an extra level
of nested braces.

Obviously in the bit removed by this patch it's the wrong thing to join
up the entire input linklist.  I guess we'd need to join only the nodes
added around the input node n (plus turn off LF_ARRAY), but there's no
good way to keep track of that (?).  Maybe it would work to join up
everything to the left of n.  Anybody with a clearer idea what's going
on here care to interject?

Meanwhile this fixes the bug without failing the other related tests.

diff --git a/Src/subst.c b/Src/subst.c
index e639c96..5b1bf89 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -446,7 +446,7 @@ singsub(char **s)
  * NULL to use IFS).  The return value is true iff the expansion resulted
  * in an empty list.
  *
- * *ms_flags is set to bits in the enum above as neeed.
+ * *ms_flags is set to bits in the enum above as needed.
  */
 
 /**/
@@ -3779,6 +3779,13 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
      * as a scalar.)
      */
 
+    if (isarr && ssub) {
+	/* prefork() wants a scalar, so join no matter what else */
+	val = sepjoin(aval, NULL, 1);
+	isarr = 0;
+	l->list.flags &= ~LF_ARRAY;
+    }
+
     /*
      * If a multsub result had whitespace at the start and we're
      * splitting and there's a previous string, now's the time to do so.
@@ -4026,18 +4033,6 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 	    y = dupstring(nulstring);
 	setdata(n, (void *) y);
     }
-    if (isarr && ssub) {
-	/* prefork() wants a scalar, so join no matter what else */
-	LinkNode tn;
-
-	aval = hlinklist2array(l, 0);
-	val = sepjoin(aval, NULL, 1);
-	n = firstnode(l);
-	for (tn = lastnode(l); tn && tn != n; tn = lastnode(l))
-	    uremnode(l, tn);
-	setdata(n, (void *) val);
-	l->list.flags &= ~LF_ARRAY;
-    }
     if (eval)
 	*str = (char *) getdata(n);
 


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

end of thread, other threads:[~2017-04-02 20:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-02 17:45 $* assignment regression in shwordsplit Martijn Dekker
2017-04-02 17:49 ` Martijn Dekker
2017-04-02 17:58 ` Daniel Shahaf
2017-04-02 20:15   ` Bart Schaefer

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