From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1318 invoked from network); 4 Mar 2006 09:28:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 Mar 2006 09:28:44 -0000 Received: (qmail 85356 invoked from network); 4 Mar 2006 09:28:38 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 Mar 2006 09:28:38 -0000 Received: (qmail 12407 invoked by alias); 4 Mar 2006 09:28:35 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22320 Received: (qmail 12397 invoked from network); 4 Mar 2006 09:28:34 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 4 Mar 2006 09:28:34 -0000 Received: (qmail 85060 invoked from network); 4 Mar 2006 09:28:34 -0000 Received: from flock1.newmail.ru (80.68.241.157) by a.mx.sunsite.dk with SMTP; 4 Mar 2006 09:28:34 -0000 Received: (qmail 22900 invoked from network); 4 Mar 2006 09:28:33 -0000 Received: from unknown (HELO cooker.local) (arvidjaar@newmail.ru@83.237.228.20) by smtpd.newmail.ru with SMTP; 4 Mar 2006 09:28:33 -0000 From: Andrey Borzenkov To: "Zsh-workers" Subject: [PATCH] Re: dirstack history: loving zsh, crashing zsh... User-Agent: KMail/1.9.1 References: <20060302175252.GA31734@let.rug.nl> <200603041104.48265.arvidjaar@mail.ru> In-Reply-To: <200603041104.48265.arvidjaar@mail.ru> MIME-Version: 1.0 Date: Sat, 4 Mar 2006 12:28:28 +0300 Content-Type: multipart/signed; boundary="nextPart19683682.rO8nrqIjOp"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200603041228.32123.arvidjaar@newmail.ru> --nextPart19683682.rO8nrqIjOp Content-Type: multipart/mixed; boundary="Boundary-01=_A3VCEhBhKiJk98h" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_A3VCEhBhKiJk98h Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Saturday 04 March 2006 11:04, Andrey Borzenkov wrote: > [moved to workers] > > On Thursday 02 March 2006 20:52, Francisco Borges wrote: > > % typeset -U dirstack > > > > and the shell crashed. > > The problem is rather non-trivial. dirsgetfn returns array built on-the-f= ly > in heap, while typeset -U calls uniqarray() that tries to zfree array > elements. There are at least two problems here: > > - typeset -U is not prepared to deal with "pseudo" parameters at all. It > assumes a->getfn() returns pointer to real parameter value. So it would > have not worked for dirstack anyway > > - I was about to change typeset -U to pm->gsu.a->setfn(pm, > pm->gsu.a->getfn(pm)) (basically doing foo=3D($foo)) and adding uniqarray > call to dirssetfn() when I realized that it would not help at all in this > case as dirssetfn() tries to free passed value too; so it would have > crashed just the same. > > Apparently to solve it in general we need one of > > - per-parameter type ->uniq function (is it an overkill?) Possibly > generalized to per-parameter ->setflags function. > > - some way to know if passed pointer was allocated from heap or not. I > guess it should be possible; something like isheap(p)? > Assuming the issue with freeing heap memory is resolved, the patch adds=20 support for -U to dirstack. It also adds framework for adding uniqueness=20 support to any parameter by changing typeset to simply do equiv. of=20 'foo=3D($foo)'. It also uncovered one case of using free() instead of zfree= ();=20 assuming previous patch is accepted it is necessary to audit code and repla= ce=20 all plain free() with zfree(). =2Dandrey --Boundary-01=_A3VCEhBhKiJk98h Content-Type: text/x-diff; charset="iso-8859-1"; name="dirstack_-U_support.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dirstack_-U_support.patch" Index: Src/builtin.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.151 diff -u -p -r1.151 builtin.c =2D-- Src/builtin.c 7 Nov 2005 09:37:34 -0000 1.151 +++ Src/builtin.c 4 Mar 2006 09:19:18 -0000 @@ -1920,24 +1920,17 @@ typeset_single(char *cname, char *pname, zerrnam(cname, "%s: restricted", pname, 0); return pm; } + pm->flags =3D (pm->flags | (on & ~PM_READONLY)) & ~(off | PM_UNSET); if ((on & PM_UNIQUE) && !(pm->flags & PM_READONLY & ~off)) { Param apm; =2D char **x; =2D if (PM_TYPE(pm->flags) =3D=3D PM_ARRAY) { =2D x =3D (*pm->gsu.a->getfn)(pm); =2D uniqarray(x); =2D if (pm->ename && x) =2D arrfixenv(pm->ename, x); =2D } else if (PM_TYPE(pm->flags) =3D=3D PM_SCALAR && pm->ename && =2D (apm =3D =2D (Param) paramtab->getnode(paramtab, pm->ename))) { =2D x =3D (*apm->gsu.a->getfn)(apm); =2D uniqarray(x); =2D if (x) =2D arrfixenv(pm->nam, x); =2D } + + if (PM_TYPE(pm->flags) =3D=3D PM_ARRAY) + apm =3D pm; + else if (PM_TYPE(pm->flags) =3D=3D PM_SCALAR && pm->ename) + apm =3D (Param) paramtab->getnode(paramtab, pm->ename); + if (apm) + apm->gsu.a->setfn(pm, apm->gsu.a->getfn(apm)); } =2D pm->flags =3D (pm->flags | (on & ~PM_READONLY)) & ~(off | PM_UNSET); if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) { if (typeset_setwidth(cname, pm, ops, on, 0)) return NULL; Index: Src/utils.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.118 diff -u -p -r1.118 utils.c =2D-- Src/utils.c 1 Mar 2006 14:50:52 -0000 1.118 +++ Src/utils.c 4 Mar 2006 09:19:21 -0000 @@ -2499,7 +2499,7 @@ freearray(char **s) =20 while (*s) zsfree(*s++); =2D free(t); + zfree(t, 0); } =20 /**/ Index: Src/Modules/parameter.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v retrieving revision 1.35 diff -u -p -r1.35 parameter.c =2D-- Src/Modules/parameter.c 10 Mar 2005 17:56:05 -0000 1.35 +++ Src/Modules/parameter.c 4 Mar 2006 09:19:21 -0000 @@ -929,15 +929,19 @@ scanpmmodules(UNUSED(HashTable ht), Scan =20 /**/ static void =2Ddirssetfn(UNUSED(Param pm), char **x) +dirssetfn(Param pm, char **x) { char **ox =3D x; =20 if (!incleanup) { freelinklist(dirstack, freestr); dirstack =3D znewlinklist(); =2D while (x && *x) =2D zaddlinknode(dirstack, ztrdup(*x++)); + if (x) { + if (pm->flags & PM_UNIQUE) + uniqarray(x); + while (*x) + zaddlinknode(dirstack, ztrdup(*x++)); + } } if (ox) freearray(ox); --Boundary-01=_A3VCEhBhKiJk98h-- --nextPart19683682.rO8nrqIjOp Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (GNU/Linux) iD8DBQBECV3AR6LMutpd94wRAiCCAJ4qN6u92H4b69lxM/7VyFtc3qduigCgmgFw Nfr/gX+Y4PgpamB6u+3clEg= =AeLY -----END PGP SIGNATURE----- --nextPart19683682.rO8nrqIjOp--