Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/ksh resolve conflicts



details:   https://anonhg.NetBSD.org/src/rev/22252054c79d
branches:  trunk
changeset: 477542:22252054c79d
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Wed Oct 20 15:09:58 1999 +0000

description:
resolve conflicts

diffstat:

 bin/ksh/Makefile   |    8 +-
 bin/ksh/alloc.c    |  706 ++++++++++++++++++++++++++++++++++++++++++++--------
 bin/ksh/c_ksh.c    |  234 +++++++++++------
 bin/ksh/c_sh.c     |  179 +++++++++++--
 bin/ksh/c_test.c   |   70 ++++-
 bin/ksh/c_ulimit.c |   38 ++-
 bin/ksh/edit.c     |   39 +-
 bin/ksh/emacs.c    |   86 +++--
 bin/ksh/eval.c     |   99 ++++---
 bin/ksh/exec.c     |  194 ++++++++------
 bin/ksh/expand.h   |   13 +-
 bin/ksh/expr.c     |  145 +++++----
 bin/ksh/history.c  |   18 +-
 bin/ksh/io.c       |   96 ++++++-
 bin/ksh/jobs.c     |   72 +++-
 bin/ksh/lex.c      |  467 +++++++++++++++++++++-------------
 bin/ksh/lex.h      |   13 +-
 bin/ksh/mail.c     |   33 +-
 bin/ksh/main.c     |  142 ++++++----
 bin/ksh/misc.c     |  180 +++++++-----
 bin/ksh/path.c     |   18 +-
 bin/ksh/proto.h    |   22 +-
 bin/ksh/sh.h       |   88 ++++-
 bin/ksh/shf.c      |   41 ++-
 bin/ksh/shf.h      |    9 +-
 bin/ksh/syn.c      |  209 +++++++-------
 bin/ksh/table.h    |   19 +-
 bin/ksh/trap.c     |   13 +-
 bin/ksh/tree.c     |  142 +++++++++-
 bin/ksh/tree.h     |   19 +-
 bin/ksh/var.c      |  168 +++++++++--
 bin/ksh/version.c  |    4 +-
 bin/ksh/vi.c       |   11 +-
 33 files changed, 2511 insertions(+), 1084 deletions(-)

diffs (truncated from 7095 to 300 lines):

diff -r 3c00efe7f4e4 -r 22252054c79d bin/ksh/Makefile
--- a/bin/ksh/Makefile  Wed Oct 20 14:57:57 1999 +0000
+++ b/bin/ksh/Makefile  Wed Oct 20 15:09:58 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.11 1997/10/22 01:36:36 lukem Exp $
+#      $NetBSD: Makefile,v 1.12 1999/10/20 15:09:58 hubertf Exp $
 
 CPPFLAGS+=     -DHAVE_CONFIG_H -I.
 
@@ -7,7 +7,7 @@
        eval.c exec.c expr.c history.c io.c jobs.c lex.c mail.c \
        main.c misc.c path.c shf.c sigact.c syn.c table.c trap.c \
        tree.c tty.c var.c version.c vi.c
-DPSRCS=        emacs.out siglist.out
+DPSRCS=        emacs.out siglist.out ksh.1
 
 # needs tbl for the man page.
 USETBL= 
@@ -22,6 +22,10 @@
        sh $(.CURDIR)/emacs-gen.sh $(.CURDIR)/emacs.c > tmpemacs.out
        mv tmpemacs.out emacs.out
 
+ksh.1: ksh.Man mkman
+       sh $(.CURDIR)/mkman ksh $(.CURDIR)/ksh.Man >tmpksh.1
+       mv tmpksh.1 ksh.1
+
 emacs.o:       emacs.out
 trap.o:                siglist.out
 
diff -r 3c00efe7f4e4 -r 22252054c79d bin/ksh/alloc.c
--- a/bin/ksh/alloc.c   Wed Oct 20 14:57:57 1999 +0000
+++ b/bin/ksh/alloc.c   Wed Oct 20 15:09:58 1999 +0000
@@ -1,42 +1,131 @@
-/*     $NetBSD: alloc.c,v 1.3 1997/07/20 17:41:59 christos Exp $       */
+/*     $NetBSD: alloc.c,v 1.4 1999/10/20 15:09:58 hubertf Exp $        */
 
 /*
  * area-based allocation built on malloc/free
  */
 
 #include "sh.h"
+
+#ifdef TEST_ALLOC
+# define shellf        printf
+# ifndef DEBUG_ALLOC
+#  define DEBUG_ALLOC
+# endif /* DEBUG_ALLOC */
+#endif /* TEST_ALLOC */
+
 #ifdef MEM_DEBUG
-# undef alloc
-# undef aresize
-# undef afree
-#endif /* MEM_DEBUG */
+
+/*
+ * Special versions of alloc routines if doing mem_debug
+ */
+Area *
+_chmem_ainit(ap, file, line)
+       Area *ap;
+       const char *file;
+       int line;
+{
+       ap->freelist = (struct Block *) _chmem_newpool("ainit", (char *) 0, -1,
+                                               file, line);
+       if (!ap->freelist)
+           aerror(ap, "ainit failed (ie, newpool)");
+       return ap;
+}
+
+/* free all object in Area */
+void
+_chmem_afreeall(ap, file, line)
+       Area *ap;
+       const char *file;
+       int line;
+{
+       _chmem_delpool((Chmem_poolp) ap->freelist, 0, file, line);
+       /* Kind of ugly, but it works */
+       _chmem_ainit(ap, file, line);
+}
 
-#define        ICELLS  100             /* number of Cells in small Block */
+/* allocate object from Area */
+void *
+_chmem_alloc(size, ap, file, line)
+       size_t size;
+       Area *ap;
+       const char *file;
+       int line;
+{
+       return _chmem_mallocp((Chmem_poolp) ap->freelist, size, file, line);
+}
+
+/* change size of object -- like realloc */
+void *
+_chmem_aresize(ptr, size, ap, file, line)
+       void *ptr;
+       size_t size;
+       Area *ap;
+       const char *file;
+       int line;
+{
+       if (!ptr)
+               /* Done as realloc(0, size) is not portable */
+               return _chmem_mallocp((Chmem_poolp) ap->freelist, size,
+                                       file, line);
+       else
+               return _chmem_reallocp((Chmem_poolp) ap->freelist, ptr, size,
+                                       file, line);
+}
+
+void
+_chmem_afree(ptr, ap, file, line)
+       void *ptr;
+       Area *ap;
+       const char *file;
+       int line;
+{
+       return _chmem_freep((Chmem_poolp) ap->freelist, ptr, file, line);
+}
+
+#else /* MEM_DEBUG */
+
+# if DEBUG_ALLOC
+void acheck ARGS((Area *ap));
+#  define ACHECK(ap)   acheck(ap)
+# else /* DEBUG_ALLOC */
+#  define ACHECK(ap)
+# endif /* DEBUG_ALLOC */
+
+#define        ICELLS  200             /* number of Cells in small Block */
 
 typedef union Cell Cell;
 typedef struct Block Block;
 
 /*
  * The Cells in a Block are organized as a set of objects.
- * Each object (pointed to by dp) begins with a size in (dp-1)->size,
+ * Each object (pointed to by dp) begins with the block it is in
+ * (dp-2)->block, then has a size in (dp-1)->size, which is
  * followed with "size" data Cells.  Free objects are
  * linked together via dp->next.
  */
 
+#define NOBJECT_FIELDS 2       /* the block and size `fields' */
+
 union Cell {
        size_t  size;
        Cell   *next;
+       Block  *block;
        struct {int _;} junk;   /* alignment */
+       double djunk;           /* alignment */
 };
 
 struct Block {
        Block  *next;           /* list of Blocks in Area */
+       Block  *prev;           /* previous block in list */
        Cell   *freelist;       /* object free list */
        Cell   *last;           /* &b.cell[size] */
        Cell    cell [1];       /* [size] Cells for allocation */
 };
 
-static Block aempty = {&aempty, aempty.cell, aempty.cell};
+static Block aempty = {&aempty, &aempty, aempty.cell, aempty.cell};
+
+static void ablockfree ARGS((Block *bp, Area *ap));
+static void *asplit ARGS((Area *ap, Block *bp, Cell *fp, Cell *fpp, int cells));
 
 /* create empty Area */
 Area *
@@ -44,6 +133,7 @@
        register Area *ap;
 {
        ap->freelist = &aempty;
+       ACHECK(ap);
        return ap;
 }
 
@@ -55,15 +145,17 @@
        register Block *bp;
        register Block *tmp;
 
+       ACHECK(ap);
        bp = ap->freelist;
        if (bp != NULL && bp != &aempty) {
                do {
-                       tmp = bp->next;
-                       free((void*)bp);
-                       bp = tmp;
+                       tmp = bp;
+                       bp = bp->next;
+                       free((void*)tmp);
                } while (bp != ap->freelist);
                ap->freelist = &aempty;
        }
+       ACHECK(ap);
 }
 
 /* allocate object from Area */
@@ -72,63 +164,99 @@
        size_t size;
        register Area *ap;
 {
-       int cells, split;
-       register Block *bp;
-       register Cell *dp, *fp, *fpp;
+       int cells, acells;
+       Block *bp = 0;
+       Cell *fp = 0, *fpp = 0;
 
-       if (size <= 0) {
+       ACHECK(ap);
+       if (size <= 0)
                aerror(ap, "allocate bad size");
-               return NULL;
-       }
-       cells = (unsigned)(size - 1) / sizeof(Cell) + 1;
+       cells = (unsigned)(size + sizeof(Cell) - 1) / sizeof(Cell);
 
-       /* find Cell large enough */
-       for (bp = ap->freelist; ; bp = bp->next) {
-               for (fpp = NULL, fp = bp->freelist;
-                    fp != bp->last; fpp = fp, fp = fpp->next)
-                       if ((fp-1)->size >= cells)
-                               goto Found;
+       /* allocate at least this many cells */
+       acells = cells + NOBJECT_FIELDS;
 
-               /* wrapped around Block list, create new Block */
-               if (bp->next == ap->freelist) {
-                       bp = (Block*) malloc(offsetof(Block, cell[ICELLS])
-                                            + sizeof(bp->cell[0]) * cells);
-                       if (bp == NULL) {
-                               aerror(ap, "cannot allocate");
-                               return NULL;
+       /*
+        * Only attempt to track small objects - let malloc deal
+        * with larger objects. (this way we don't have to deal with
+        * coalescing memory, or with releasing it to the system)
+        */
+       if (cells <= ICELLS) {
+               /* find free Cell large enough */
+               for (bp = ap->freelist; ; bp = bp->next) {
+                       for (fpp = NULL, fp = bp->freelist;
+                            fp != bp->last; fpp = fp, fp = fp->next)
+                       {
+                               if ((fp-1)->size >= cells)
+                                       goto Found;
+                       }
+                       /* wrapped around Block list, create new Block */
+                       if (bp->next == ap->freelist) {
+                               bp = 0;
+                               break;
                        }
-                       if (ap->freelist == &aempty)
-                               bp->next = bp;
-                       else {
-                               bp->next = ap->freelist->next;
-                               ap->freelist->next = bp;
-                       }
-                       bp->last = bp->cell + ICELLS + cells;
-                       fp = bp->freelist = bp->cell + 1; /* initial free list */
-                       (fp-1)->size = ICELLS + cells - 1;
-                       fp->next = bp->last;
-                       fpp = NULL;
-                       break;
+               }
+               /* Not much free space left?  Allocate a big object this time */
+               acells += ICELLS;
+       }
+       if (bp == 0) {
+               bp = (Block*) malloc(offsetof(Block, cell[acells]));
+               if (bp == NULL)
+                       aerror(ap, "cannot allocate");
+               if (ap->freelist == &aempty) {
+                       ap->freelist = bp->next = bp->prev = bp;
+               } else {
+                       bp->next = ap->freelist->next;
+                       ap->freelist->next->prev = bp;
+                       ap->freelist->next = bp;
+                       bp->prev = ap->freelist;
                }
+               bp->last = bp->cell + acells;
+               /* initial free list */
+               fp = bp->freelist = bp->cell + NOBJECT_FIELDS;
+               (fp-1)->size = acells - NOBJECT_FIELDS;
+               (fp-2)->block = bp;
+               fp->next = bp->last;
+               fpp = NULL;
        }
+
   Found:
-       ap->freelist = bp;
-       dp = fp;                /* allocated object */
-       split = (dp-1)->size - cells;
+       return asplit(ap, bp, fp, fpp, cells);
+}
+



Home | Main Index | Thread Index | Old Index