zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: "Array" variables that aren't set, and NO_UNSET
Date: Tue, 23 Jul 1996 14:17:00 +0200	[thread overview]
Message-ID: <199607231217.OAA16524@hydra.ifh.de> (raw)
In-Reply-To: "schaefer@candle.brasslantern.com"'s message of "Mon, 22 Jul 1996 12:35:29 MET." <960722123529.ZM9604@candle.brasslantern.com>

schaefer@candle.brasslantern.com wrote:
> Consider:
> 
> zsh% setopt | grep set
> nounset             off
> zsh% echo ${thisisnotavariable}
> 
> zsh% echo ${thisisnotavariable[1]}
> zsh: closing brace expected
> zsh% 
> 
> Why is it a *syntax* error to subscript a variable that's not set, when
> it is not a syntax error to refer to the string value of such a variable?

This does seem inconsistent.  The problem is that getvalue() doesn't
bother parsing any further if it finds the variable is unset.

This patch is one suggestion, though I suspect there may be others.
Parsing continues (that's the first hunk), and one then has to be
careful that the parameter struct v->pm is not dereferenced since it
may now be null (that's all the rest).  The change to check this in
getstrvalue() is necessary; the changes in getintvalue() and
getarrvalue() shouldn't be if everything is going according to plan,
but I have made them anyway.

It's very intricate, so it's rather hard to be completely certain
v->pm won't get dereferenced.  Perhaps there's a better way of doing
it.  Make v->pm instead reference a dummy scalar?  That's hard too,
since if getvalue() returns non-zero then v->pm is liable to be
hijacked and altered.  I'm not sure there's currently any way of making
readonlyness watertight.

*** Src/params.c~	Mon Jul  1 19:10:53 1996
--- Src/params.c	Tue Jul 23 13:49:28 1996
***************
*** 549,560 ****
  	if (sav)
  	    *s = sav;
  	*pptr = s;
- 	if (!pm || (pm->flags & PM_UNSET))
- 	    return NULL;
  	v = (Value) hcalloc(sizeof *v);
! 	if (PM_TYPE(pm->flags) == PM_ARRAY)
  	    v->isarr = isvarat ? -1 : 1;
! 	v->pm = pm;
  	v->inv = 0;
  	v->a = 0;
  	v->b = -1;
--- 549,558 ----
  	if (sav)
  	    *s = sav;
  	*pptr = s;
  	v = (Value) hcalloc(sizeof *v);
! 	if (pm && PM_TYPE(pm->flags) == PM_ARRAY)
  	    v->isarr = isvarat ? -1 : 1;
! 	v->pm = (pm && !(pm->flags & PM_UNSET)) ? pm : NULL;
  	v->inv = 0;
  	v->a = 0;
  	v->b = -1;
***************
*** 602,608 ****
  			while (*s != ']' && *s != Outbrack)
  			    s++;
  			*pptr = s;
! 			return v;
  		    }
  		} else {
  		    if (a > 0)
--- 600,606 ----
  			while (*s != ']' && *s != Outbrack)
  			    s++;
  			*pptr = s;
! 			return v->pm ? v : NULL;
  		    }
  		} else {
  		    if (a > 0)
***************
*** 642,648 ****
  	zerr("subscript to %s: %d", (v->b < 0) ? "small" : "big", v->b);
  	return NULL;
      }
!     return v;
  }
  
  /**/
--- 640,646 ----
  	zerr("subscript to %s: %d", (v->b < 0) ? "small" : "big", v->b);
  	return NULL;
      }
!     return v->pm ? v : NULL;
  }
  
  /**/
***************
*** 652,658 ****
      char *s, **ss;
      static char buf[(SIZEOF_LONG * 8) + 4];
  
!     if (!v)
  	return "";
      if (v->inv) {
  	sprintf(buf, "%d", v->a);
--- 650,656 ----
      char *s, **ss;
      static char buf[(SIZEOF_LONG * 8) + 4];
  
!     if (!v || !v->pm)
  	return "";
      if (v->inv) {
  	sprintf(buf, "%d", v->a);
***************
*** 704,710 ****
  {
      char **s;
  
!     if (!v)
  	return arrdup(nular);
      if (v->inv) {
  	char buf[DIGBUFSIZE];
--- 702,708 ----
  {
      char **s;
  
!     if (!v || !v->pm)
  	return arrdup(nular);
      if (v->inv) {
  	char buf[DIGBUFSIZE];
***************
*** 736,742 ****
  long
  getintvalue(Value v)
  {
!     if (!v || v->isarr)
  	return 0;
      if (v->inv)
  	return v->a;
--- 734,740 ----
  long
  getintvalue(Value v)
  {
!     if (!v || !v->pm || v->isarr)
  	return 0;
      if (v->inv)
  	return v->a;

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



      reply	other threads:[~1996-07-23 12:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-22 19:35 Bart Schaefer
1996-07-23 12:17 ` Peter Stephenson [this message]

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=199607231217.OAA16524@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).