zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: BUG: permanent allocation in arrfixenv
Date: Thu, 06 Feb 1997 13:48:50 +0100	[thread overview]
Message-ID: <199702061248.NAA22179@hydra.ifh.de> (raw)

This message arises when editing $path using vared.  Going back to the
call of setaparam() in bin_vared(), zle_main.c around line 618, I see
it's deliberately set up to use PERMALLOC, so I don't really see where
that should be changed.

However, I think the only problem is the zjoin() in arrfixenv().  This
isn't actually called very much, and as far as I can see always in
contexts which know whether they are permanent or not (I think the
colonarrgetfn() return value has to come off the heap).  Further, two
of the uses have explicit PERMALLOC's for the express purpose of
zjoin'ing.  Wouldn't it be better to given zjoin() an explicit
heap/permanent flag?  This is what the following patch does.  It would
be nice if someone else would cast an eye over arrfixenv(), and also
that chunk of bin_print() in builtin.c with the ent->text line changed
to make sure they really are clean now, but it certainly looks that
way.

I altered bin_eval() to use permanent storage because it looked a
little neater.

It looks like there was a bug in zjoin(), which always returned an
unduplicated "" when the array passed to it was empty, though
presumably that never actually happened for various reasons.

It would be possible to do the same with sepjoin(), but the case isn't
so clear cut.

*** Src/builtin.c.zj	Thu Feb  6 12:08:47 1997
--- Src/builtin.c	Thu Feb  6 12:22:56 1997
***************
*** 2099,2126 ****
  	int nwords = 0, nlen, iwords;
  	char **pargs = args;
  
! 	PERMALLOC {
! 	    ent = gethistent(++curhist);
! 	    zsfree(ent->text);
! 	    if (ent->nwords)
! 		zfree(ent->words, ent->nwords*2*sizeof(short));
! 	    while (*pargs++)
! 		nwords++;
! 	    if ((ent->nwords = nwords)) {
! 		ent->words = (short *)zalloc(nwords*2*sizeof(short));
! 		nlen = iwords = 0;
! 		for (pargs = args; *pargs; pargs++) {
! 		    ent->words[iwords++] = nlen;
! 		    nlen += strlen(*pargs);
! 		    ent->words[iwords++] = nlen;
! 		    nlen++;
! 		}
! 	    } else
! 		ent->words = (short *)NULL;
! 	    ent->text = zjoin(args, ' ');
! 	    ent->stim = ent->ftim = time(NULL);
! 	    ent->flags = 0;
! 	} LASTALLOC;
  	return 0;
      }
      /* -u and -p -- output to other than standard output */
--- 2099,2124 ----
  	int nwords = 0, nlen, iwords;
  	char **pargs = args;
  
! 	ent = gethistent(++curhist);
! 	zsfree(ent->text);
! 	if (ent->nwords)
! 	    zfree(ent->words, ent->nwords*2*sizeof(short));
! 	while (*pargs++)
! 	    nwords++;
! 	if ((ent->nwords = nwords)) {
! 	    ent->words = (short *)zalloc(nwords*2*sizeof(short));
! 	    nlen = iwords = 0;
! 	    for (pargs = args; *pargs; pargs++) {
! 		ent->words[iwords++] = nlen;
! 		nlen += strlen(*pargs);
! 		ent->words[iwords++] = nlen;
! 		nlen++;
! 	    }
! 	} else
! 	    ent->words = (short *)NULL;
! 	ent->text = zjoin(args, ' ', 1);
! 	ent->stim = ent->ftim = time(NULL);
! 	ent->flags = 0;
  	return 0;
      }
      /* -u and -p -- output to other than standard output */
***************
*** 2632,2638 ****
  {
      List list;
  
!     inpush(zjoin(argv, ' '), 0, NULL);
      strinbeg();
      stophist = 2;
      list = parse_list();
--- 2630,2636 ----
  {
      List list;
  
!     inpush(zjoin(argv, ' ', 1), INP_FREE, NULL);
      strinbeg();
      stophist = 2;
      list = parse_list();
***************
*** 3194,3202 ****
      of scheduled commands. */
      sch = (struct schedcmd *) zcalloc(sizeof *sch);
      sch->time = t;
!     PERMALLOC {
! 	sch->cmd = zjoin(argv, ' ');
!     } LASTALLOC;
      sch->next = NULL;
      for (sch2 = (struct schedcmd *)&schedcmds; sch2->next; sch2 = sch2->next);
      sch2->next = sch;
--- 3192,3198 ----
      of scheduled commands. */
      sch = (struct schedcmd *) zcalloc(sizeof *sch);
      sch->time = t;
!     sch->cmd = zjoin(argv, ' ', 1);
      sch->next = NULL;
      for (sch2 = (struct schedcmd *)&schedcmds; sch2->next; sch2 = sch2->next);
      sch2->next = sch;
*** Src/params.c.zj	Thu Feb  6 12:08:47 1997
--- Src/params.c	Thu Feb  6 12:14:37 1997
***************
*** 1348,1354 ****
  char *
  colonarrgetfn(Param pm)
  {
!     return zjoin(*(char ***)pm->data, ':');
  }
  
  /**/
--- 1348,1354 ----
  char *
  colonarrgetfn(Param pm)
  {
!     return zjoin(*(char ***)pm->data, ':', 0);
  }
  
  /**/
***************
*** 1788,1797 ****
      int len_s;
      Param pm;
  
-     MUSTUSEHEAP("arrfixenv");
      if (t == path)
  	cmdnamtab->emptytable(cmdnamtab);
!     u = zjoin(t, ':');
      len_s = strlen(s);
      pm = (Param) paramtab->getnode(paramtab, s);
      for (ep = environ; *ep; ep++)
--- 1788,1796 ----
      int len_s;
      Param pm;
  
      if (t == path)
  	cmdnamtab->emptytable(cmdnamtab);
!     u = zjoin(t, ':', 0);
      len_s = strlen(s);
      pm = (Param) paramtab->getnode(paramtab, s);
      for (ep = environ; *ep; ep++)
*** Src/utils.c.zj	Thu Feb  6 12:08:47 1997
--- Src/utils.c	Thu Feb  6 13:27:00 1997
***************
*** 1354,1360 ****
  
  /**/
  char *
! zjoin(char **arr, int delim)
  {
      int len = 0;
      char **s, *ret, *ptr;
--- 1354,1360 ----
  
  /**/
  char *
! zjoin(char **arr, int delim, int useperm)
  {
      int len = 0;
      char **s, *ret, *ptr;
***************
*** 1362,1369 ****
      for (s = arr; *s; s++)
  	len += strlen(*s) + 1;
      if (!len)
! 	return "";
!     ptr = ret = (char *) ncalloc(len);
      for (s = arr; *s; s++) {
  	strucpy(&ptr, *s);
  	if (delim)
--- 1362,1369 ----
      for (s = arr; *s; s++)
  	len += strlen(*s) + 1;
      if (!len)
! 	return useperm ? ztrdup("") : "";
!     ptr = ret = (char *) (useperm ? zalloc(len) : halloc(len));
      for (s = arr; *s; s++) {
  	strucpy(&ptr, *s);
  	if (delim)


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


                 reply	other threads:[~1997-02-06 13:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=199702061248.NAA22179@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).