zsh-workers
 help / color / mirror / code / Atom feed
* bug : _make and special parameters
@ 2006-11-08 19:42 arno.
  2006-11-09 10:50 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: arno. @ 2006-11-08 19:42 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]

Hi,
I downloaded qiv sources, went in the right directory, typed "make" and 
<TAB>

I got the error :  (eval):1: read-only variable: CURSOR

This is because in _make, Makefile lines are parsed to find for 
variables declarations, and then assigned with : 
eval $var=\$val

But in qiv Makefile, there is the line :
CURSOR = 84
and CURSOR is a parameter special in zsh.

That problem could happen with any special parameters.

I found a solution by adding the line 
typeset -h $var 
just before eval

I don't known if there could be drawbacks with my fix, but I still send 
it.

arno.


? _make.patch
Index: Completion/Unix/Command/_make
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_make,v
retrieving revision 1.17
diff -u -r1.17 _make
--- Completion/Unix/Command/_make	9 Feb 2006 14:51:32 -0000	1.17
+++ Completion/Unix/Command/_make	8 Nov 2006 19:31:11 -0000
@@ -60,6 +60,7 @@
 	    var=${input%%[ $TAB]#=*}
 	    val=${input#*=}
 	    val=${val##[ $TAB]#}
+       local -h $var
 	    eval $var=\$val
 	    ;;
 	([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
@@ -67,6 +68,7 @@
 	    val=${input#*=}
 	    val=${val##[ $TAB]#}
 	    val=$(expandVars 10 $val)
+       local -h $var
 	    eval $var=\$val
 	    ;;
 	([[:alnum:]][^$TAB:=]#:[^=]*)

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: bug : _make and special parameters
  2006-11-08 19:42 bug : _make and special parameters arno.
@ 2006-11-09 10:50 ` Peter Stephenson
  2006-11-10  9:56   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2006-11-09 10:50 UTC (permalink / raw)
  To: zsh-workers

> I downloaded qiv sources, went in the right directory, typed "make" and
> <TAB>
> 
> I got the error :  (eval):1: read-only variable: CURSOR
> 
> This is because in _make, Makefile lines are parsed to find for
> variables declarations, and then assigned with :
> eval $var=\$val
> 
> But in qiv Makefile, there is the line :
> CURSOR = 84
> and CURSOR is a parameter special in zsh.
> 
> That problem could happen with any special parameters.
> 
> I found a solution by adding the line
> typeset -h $var
> just before eval

I think you've got the right sort of idea.  However, parseMakefile can
run recursively, because it handles include declarations, so the
variables need to go in the top-level namespace.  There's no easy way of
ensuring this, unfortunately, since there's no way of making the
parameter local (necessary since the global parameter is special) but at
a particular level.  So I'll commit your patch for now.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

* Re: bug : _make and special parameters
  2006-11-09 10:50 ` Peter Stephenson
@ 2006-11-10  9:56   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2006-11-10  9:56 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson <pws@csr.com> wrote:
> parseMakefile can
> run recursively, because it handles include declarations, so the
> variables need to go in the top-level namespace.  There's no easy way of
> ensuring this, unfortunately, since there's no way of making the
> parameter local (necessary since the global parameter is special) but at
> a particular level.  So I'll commit your patch for now.

Here's another version: only variables that match existing specials are
declared as local and hidden.

I wrote this just to hedge my bets, leaving everything working for most
variables but fixing arno's problem if they happen to match specials, but
it's actually slightly better: the first "local" will hide the special and
the ${(tP)$var} won't show up a special any more, so the hiding variable
won't subsequently be relocalised.  However, you still lose the scope if
the variable was first mentioned in an included makefile, so it's not a
complete fix.  You could do that with two scans, but it doesn't seem worth
it.

Index: Completion/Unix/Command/_make
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_make,v
retrieving revision 1.18
diff -u -r1.18 _make
--- Completion/Unix/Command/_make	9 Nov 2006 10:52:46 -0000	1.18
+++ Completion/Unix/Command/_make	10 Nov 2006 09:56:03 -0000
@@ -51,6 +51,12 @@
     done
 }
 
+# parseMakefile only runs inside $(...), so it doesn't matter that
+# it pollutes the global namespace, setting zsh variables to
+# make variables.  The difficult case is where a make variable
+# is special in zsh; we use local -h to hide those.  This
+# isn't a complete solution since it means variables defined in
+# included Makefiles are undefined before returning to the parent.
 parseMakefile() {
     local input var val TAB=$'\t' dir=$1
 
@@ -60,7 +66,7 @@
 	    var=${input%%[ $TAB]#=*}
 	    val=${input#*=}
 	    val=${val##[ $TAB]#}
-	    local -h $var
+	    [[ ${(tP)var} = *special ]] && local -h $var
 	    eval $var=\$val
 	    ;;
 	([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
@@ -68,7 +74,7 @@
 	    val=${input#*=}
 	    val=${val##[ $TAB]#}
 	    val=$(expandVars 10 $val)
-	    local -h $var
+	    [[ ${(tP)var} = *special ]] && local -h $var
 	    eval $var=\$val
 	    ;;
 	([[:alnum:]][^$TAB:=]#:[^=]*)

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

end of thread, other threads:[~2006-11-10  9:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-08 19:42 bug : _make and special parameters arno.
2006-11-09 10:50 ` Peter Stephenson
2006-11-10  9:56   ` Peter Stephenson

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