Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

dynamic multios



-----BEGIN PGP SIGNED MESSAGE-----

This patch makes multios dynamically resizeable.  The recent patch to
make zsh warn instead of running off the end of the struct should *not*
be applied first; back it out if you've already applied it.

I implement this by resizing the struct multio as required.  This causes
some overhead when building up a very large multio (order n^2 ultimately),
but there is no overhead for multios less than 9 files, and the overhead
is quite small in any usual case.  It is certainly preferable to the
other obvious method, of forking off an intermediate cat/tee process,
as could be done by calling closemn() when the struct fills up.

 -zefram

      Index: Src/exec.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/exec.c,v
      retrieving revision 1.36
      diff -c -r1.36 exec.c
      *** exec.c	1996/11/15 00:40:12	1.36
      --- exec.c	1996/11/15 03:10:19
      ***************
      *** 1047,1054 ****
        	    mfds[fd1]->pipe = pipes[1 - rflag];
        	    redup(pipes[rflag], fd1);
        	    mfds[fd1]->ct = 2;
      ! 	} else			/* add another fd to an already split stream */
        	    mfds[fd1]->fds[mfds[fd1]->ct++] = movefd(fd2);
            }
            if (subsh_close >= 0 && !fdtable[subsh_close])
        	subsh_close = -1;
      --- 1047,1060 ----
        	    mfds[fd1]->pipe = pipes[1 - rflag];
        	    redup(pipes[rflag], fd1);
        	    mfds[fd1]->ct = 2;
      ! 	} else {		/* add another fd to an already split stream */
      ! 	    if(!(mfds[fd1]->ct % MULTIOUNIT)) {
      ! 		int new = sizeof(struct multio) + sizeof(int) * mfds[fd1]->ct;
      ! 		int old = new - sizeof(int) * MULTIOUNIT;
      ! 		mfds[fd1] = hrealloc((char *)mfds[fd1], old, new);
      ! 	    }
        	    mfds[fd1]->fds[mfds[fd1]->ct++] = movefd(fd2);
      + 	}
            }
            if (subsh_close >= 0 && !fdtable[subsh_close])
        	subsh_close = -1;
      Index: Src/zsh.h
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/zsh.h,v
      retrieving revision 1.25
      diff -c -r1.25 zsh.h
      *** zsh.h	1996/11/08 01:23:12	1.25
      --- zsh.h	1996/11/15 03:09:36
      ***************
      *** 480,488 ****
            List loop;			/* list to execute until condition met */
        };
        
      ! /* The maximum number of redirections you *
      !  * can have on a single file descriptor.  */
      ! #define MAXREDIRECT 16
        
        /* A multio is a list of fds associated with a certain fd.       *
         * Thus if you do "foo >bar >ble", the multio for fd 1 will have *
      --- 480,488 ----
            List loop;			/* list to execute until condition met */
        };
        
      ! /* The number of fds space is allocated for  *
      !  * each time a multio must increase in size. */
      ! #define MULTIOUNIT 8
        
        /* A multio is a list of fds associated with a certain fd.       *
         * Thus if you do "foo >bar >ble", the multio for fd 1 will have *
      ***************
      *** 496,508 ****
            int ct;			/* # of redirections on this fd                 */
            int rflag;			/* 0 if open for reading, 1 if open for writing */
            int pipe;			/* fd of pipe if ct > 1                         */
      !     int fds[MAXREDIRECT];	/* list of src/dests redirected to/from this fd */
        };
      - 
      - struct fdpair {
      -     int fd1, fd2;
      - };
      - 
        
        /* variable assignment tree element */
        
      --- 496,503 ----
            int ct;			/* # of redirections on this fd                 */
            int rflag;			/* 0 if open for reading, 1 if open for writing */
            int pipe;			/* fd of pipe if ct > 1                         */
      !     int fds[MULTIOUNIT];	/* list of src/dests redirected to/from this fd */
        };
        
        /* variable assignment tree element */
        

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMovig3D/+HJTpU/hAQF64AP9GnytLZP9Dwo/hlltw3ICCQM9BzKjHWOn
lENcSFXdIEpIWoKPDDN4pHYNe5x08WU54xUJZDerEEtarCzMYFzrGNTGKkiqSOf0
Qo3swujwKR5p58E3jQjL4khtGiLtft2YbBWFGbO005+BmQ02iBQatFH1m8VKGnWy
HgEdjPR/Rgk=
=sTKP
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author