From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26567 invoked from network); 11 Sep 2006 11:04:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.5 (2006-08-29) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Sep 2006 11:04:35 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 80121 invoked from network); 11 Sep 2006 11:04:26 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Sep 2006 11:04:26 -0000 Received: (qmail 25545 invoked by alias); 11 Sep 2006 11:04:23 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22686 Received: (qmail 25536 invoked from network); 11 Sep 2006 11:04:22 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Sep 2006 11:04:22 -0000 Received: (qmail 79849 invoked from network); 11 Sep 2006 11:04:22 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 11 Sep 2006 11:04:20 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly14c.srv.mailcontrol.com (MailControl) with ESMTP id k8BB39AQ023574 for ; Mon, 11 Sep 2006 12:03:53 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Mon, 11 Sep 2006 12:00:03 +0100 Date: Mon, 11 Sep 2006 11:59:55 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: Math assignment to arrays: Is this a bug? Message-Id: <20060911115955.c9e8e5b6.pws@csr.com> In-Reply-To: <060903102801.ZM7627@torch.brasslantern.com> References: <060903102801.ZM7627@torch.brasslantern.com> Organization: Cambridge Silicon Radio X-Mailer: Sylpheed version 2.2.6 (GTK+ 2.6.7; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 11 Sep 2006 11:00:03.0497 (UTC) FILETIME=[6EF21190:01C6D591] X-Scanned-By: MailControl A-07-04-01 (www.mailcontrol.com) on 10.67.0.124 Bart Schaefer wrote: > Try this but be prepared to interrupt it: > > x=() > for (( x=1; x <= 10; x++ )) print $x > > Why doesn't the assignment of 1 to x in the loop reset it from array to > scalar? This is inconsistent with normal assignment, so it probably needs fixing. I've copied the corresponding code from assignsparam(), which has an unset(KSHARRAYS) test there: not sure what that's doing. setiparam() is almost a duplicate of setnparam(); it's not worth having it separate. Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.119 diff -u -r1.119 params.c --- Src/params.c 10 Sep 2006 18:10:49 -0000 1.119 +++ Src/params.c 11 Sep 2006 10:56:46 -0000 @@ -2495,46 +2495,9 @@ return v->pm; } -/**/ -mod_export Param -setiparam(char *s, zlong val) -{ - struct value vbuf; - Value v; - char *t = s, *ss; - Param pm; - mnumber mnval; - - if (!isident(s)) { - zerr("not an identifier: %s", s); - errflag = 1; - return NULL; - } - queue_signals(); - if (!(v = getvalue(&vbuf, &s, 1))) { - if ((ss = strchr(s, '['))) - *ss = '\0'; - if (!(pm = createparam(t, ss ? PM_ARRAY : PM_INTEGER))) - pm = (Param) paramtab->getnode(paramtab, t); - DPUTS(!pm, "BUG: parameter not created"); - if (ss) { - *ss = '['; - } else { - pm->base = outputradix; - } - v = getvalue(&vbuf, &t, 1); - DPUTS(!v, "BUG: value not found for new parameter"); - } - mnval.type = MN_INTEGER; - mnval.u.l = val; - setnumvalue(v, mnval); - unqueue_signals(); - return v->pm; -} /* - * Like setiparam(), but can take an mnumber which can be integer or - * floating. + * Set a generic shell number, floating point or integer. */ /**/ @@ -2543,7 +2506,7 @@ { struct value vbuf; Value v; - char *t = s, *ss = NULL; + char *t = s, *ss; Param pm; if (!isident(s)) { @@ -2552,8 +2515,23 @@ return NULL; } queue_signals(); - if (!(v = getvalue(&vbuf, &s, 1))) { - if ((ss = strchr(s, '['))) + ss = strchr(s, '['); + v = getvalue(&vbuf, &s, 1); + if (v && (v->pm->node.flags & (PM_ARRAY|PM_HASHED)) && + !(v->pm->node.flags & (PM_SPECIAL|PM_TIED)) && + /* + * not sure what KSHARRAYS has got to do with this... + * copied this from assignsparam(). + */ + unset(KSHARRAYS) && !ss) { + unsetparam_pm(v->pm, 0, 1); + s = t; + v = NULL; + } + if (!v) { + /* s has been updated by getvalue, so check again */ + ss = strchr(s, '['); + if (ss) *ss = '\0'; pm = createparam(t, ss ? PM_ARRAY : (val.type & MN_INTEGER) ? PM_INTEGER : PM_FFLOAT); @@ -2573,6 +2551,19 @@ return v->pm; } +/* Simplified interface to setnparam */ + +/**/ +mod_export Param +setiparam(char *s, zlong val) +{ + mnumber mnval; + mnval.type = MN_INTEGER; + mnval.u.l = val; + return setnparam(s, mnval); +} + + /* Unset a parameter */ /**/ Index: Test/C01arith.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C01arith.ztst,v retrieving revision 1.9 diff -u -r1.9 C01arith.ztst --- Test/C01arith.ztst 30 Nov 2004 14:14:57 -0000 1.9 +++ Test/C01arith.ztst 11 Sep 2006 10:56:46 -0000 @@ -97,6 +97,12 @@ 0:setting array elements in math context >array 1 2 + xarr=() + (( xarr = 3 )) + print ${(t)xarr} $xarr +0:converting type from array +>integer 3 + print $(( 13 = 42 )) 1:bad lvalue ?(eval):1: lvalue required -- Peter Stephenson 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