zsh-workers
 help / color / mirror / code / Atom feed
* Mysteriously changing parameters and options within a function.
@ 2003-07-19  2:06 Philippe Troin
  2003-07-21 16:57 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Troin @ 2003-07-19  2:06 UTC (permalink / raw)
  To: zsh-workers

Consider the following function whose purpose is mostly evident:

check-missing-locals() {
  local -A parms_before options_before ignored_params
  local i xit
  xit=0
  ignored_params=(parms_before 1
  		      options_before 1
  		      parameters 1
  		      i 1
  		      xit 1
  		      parameters 1
  		      functions 1
  		      aliases 1
  		      galiases 1
  		      history 1
  		      historywords 1
  		      widgets 1
  		      options 1
                      modules 1
  		      LINENO 1
  		      ERRNO 1
  		      RANDOM 1
  		      TTYIDLE 1
  		      SECONDS 1
  		      status 1
  		      '?' 1
  		      _ 1
  		      pipestatus 1
  	       )
  for i in ${(k)parameters}
  do
    (( $+ignored_params[$i] )) && continue
    parms_before[$i]=${(P)i}
  done
  options_before=(${(kv)options})
  eval $*
  for i in ${(ko)options}
  do
    if [[ $options[$i] != $options_before[$i] ]]
    then
      echo "$0: changed option $i: $options_before[$i] " \
           "vs. $options[$i]" 1>&2
      xit=1
    fi
  done
  for i in ${(ko)parms_before}
  do
    (( $+ignored_params[$i] )) && continue
    if (( ! $+parameters[$i] ))
    then
      echo "$0: unset parameter $i" 1>&2
      xit=1
    fi
  done
  for i in ${(ko)parameters}
  do
    (( $+ignored_params[$i] )) && continue
    if (( ! $+parms_before[$i] ))
    then
      echo "$0: set parameter $i" 1>&2
      xit=1
    fi
  done
  for i in ${(ko)parms_before}
  do
    (( $+ignored_params[$i] )) && continue
    if (( $+parameters[$i] && $+parms_before[$i] )) \
       && [[ ${(P)i} != $parms_before[$i] ]]
    then
      echo "$0: changed parameter $i: ${(q)parms_before[$i]}" \
           " vs. ${(qP)i}" 1>&2
      xit=1
    fi
  done
  return $xit
}

Its purpose is to detect if any command (or function actually) has
forgotten to declare a parameter or option as local.

Eg. (intended,.but not actual output):

  % check-missing-locals somevar=1 
  check-missing-locals: set parameter somevar
  % check-missing-locals somevar=2
  check-missing-locals: changed parameter somevar: 1  vs. 2
  % check-missing-locals unset somevar
  check-missing-locals: unset parameter somevar
  % check-missing-locals setopt octal_zeroes
  check-missing-locals: changed option octalzeroes: off  vs. on

However, I get this:

% check-missing-locals :
check-missing-locals: changed option braceexpand: on  vs. off
check-missing-locals: unset parameter LANG
check-missing-locals: unset parameter LC_ALL
check-missing-locals: unset parameter LC_COLLATE
check-missing-locals: unset parameter LC_CTYPE
check-missing-locals: unset parameter LC_MESSAGES
check-missing-locals: unset parameter LC_NUMERIC
check-missing-locals: unset parameter LC_TIME

What makes LANG, LC_* and the braceexpand option appear to be in
different states at the beginning and the end of the function?

Phil.


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

* Re: Mysteriously changing parameters and options within a function.
  2003-07-19  2:06 Mysteriously changing parameters and options within a function Philippe Troin
@ 2003-07-21 16:57 ` Peter Stephenson
  2003-07-22 20:00   ` Philippe Troin
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2003-07-21 16:57 UTC (permalink / raw)
  To: zsh-workers

Philippe Troin wrote:
> However, I get this:
> 
> % check-missing-locals :
> check-missing-locals: changed option braceexpand: on  vs. off
> check-missing-locals: unset parameter LANG
> check-missing-locals: unset parameter LC_ALL
> check-missing-locals: unset parameter LC_COLLATE
> check-missing-locals: unset parameter LC_CTYPE
> check-missing-locals: unset parameter LC_MESSAGES
> check-missing-locals: unset parameter LC_NUMERIC
> check-missing-locals: unset parameter LC_TIME
> 
> What makes LANG, LC_* and the braceexpand option appear to be in
> different states at the beginning and the end of the function?

I don't think the parameter module should be showing unset parameters
when you ask it for a list of parameters which are set.

I can't show up the bug with braceexpand, which is probably something
different.  There was a bug fixed back in March:

	* 18325: Src/Modules/parameter.c: options on by default weren't
	handled correctly.

but I don't think that's it either.

Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.23
diff -u -r1.23 parameter.c
--- Src/Modules/parameter.c	7 Mar 2003 12:31:12 -0000	1.23
+++ Src/Modules/parameter.c	21 Jul 2003 16:54:48 -0000
@@ -181,6 +181,8 @@
 
     for (i = 0; i < realparamtab->hsize; i++)
 	for (hn = realparamtab->nodes[i]; hn; hn = hn->next) {
+	    if (((Param)hn)->flags & PM_UNSET)
+		continue;
 	    pm.nam = hn->nam;
 	    if (func != scancountparams &&
 		((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Mysteriously changing parameters and options within a function.
  2003-07-21 16:57 ` Peter Stephenson
@ 2003-07-22 20:00   ` Philippe Troin
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Troin @ 2003-07-22 20:00 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

Peter Stephenson <pws@csr.com> writes:

> Philippe Troin wrote:
> > However, I get this:
> > 
> > % check-missing-locals :
> > check-missing-locals: changed option braceexpand: on  vs. off
> > check-missing-locals: unset parameter LANG
> > check-missing-locals: unset parameter LC_ALL
> > check-missing-locals: unset parameter LC_COLLATE
> > check-missing-locals: unset parameter LC_CTYPE
> > check-missing-locals: unset parameter LC_MESSAGES
> > check-missing-locals: unset parameter LC_NUMERIC
> > check-missing-locals: unset parameter LC_TIME
> > 
> > What makes LANG, LC_* and the braceexpand option appear to be in
> > different states at the beginning and the end of the function?
> 
> I don't think the parameter module should be showing unset parameters
> when you ask it for a list of parameters which are set.
> 
> I can't show up the bug with braceexpand, which is probably something
> different.  There was a bug fixed back in March:
> 
> 	* 18325: Src/Modules/parameter.c: options on by default weren't
> 	handled correctly.
> 
> but I don't think that's it either.

I cannot see the braceexpand problem with the current CVS tree.

> 
> Index: Src/Modules/parameter.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
> retrieving revision 1.23
> diff -u -r1.23 parameter.c
> --- Src/Modules/parameter.c	7 Mar 2003 12:31:12 -0000	1.23
> +++ Src/Modules/parameter.c	21 Jul 2003 16:54:48 -0000
> @@ -181,6 +181,8 @@
>  
>      for (i = 0; i < realparamtab->hsize; i++)
>  	for (hn = realparamtab->nodes[i]; hn; hn = hn->next) {
> +	    if (((Param)hn)->flags & PM_UNSET)
> +		continue;
>  	    pm.nam = hn->nam;
>  	    if (func != scancountparams &&
>  		((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||

I can confirm that this patch fixes the problem for LANG and the LC_*
variables.

Please consider applying the patch to CVS.

Phil.


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

end of thread, other threads:[~2003-07-22 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-19  2:06 Mysteriously changing parameters and options within a function Philippe Troin
2003-07-21 16:57 ` Peter Stephenson
2003-07-22 20:00   ` Philippe Troin

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