Source-Changes-HG archive

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

[src/trunk]: src/lib/libcurses PR/17352: David Laight: Curses core-dumps on w...



details:   https://anonhg.NetBSD.org/src/rev/de289aa9fa91
branches:  trunk
changeset: 533291:de289aa9fa91
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jun 26 18:13:59 2002 +0000

description:
PR/17352: David Laight: Curses core-dumps on windows > 1024 wide.

diffstat:

 lib/libcurses/color.c          |   8 +++---
 lib/libcurses/cr_put.c         |  14 +++++-----
 lib/libcurses/ctrace.c         |  17 +++++++++----
 lib/libcurses/cur_hash.c       |  13 ++++-----
 lib/libcurses/curses_private.h |   7 +++--
 lib/libcurses/refresh.c        |  52 ++++++++++++++++++++++++++++++-----------
 lib/libcurses/scanw.c          |   6 ++--
 lib/libcurses/setterm.c        |  27 ++++++++++++--------
 lib/libcurses/tscroll.c        |   7 +++--
 9 files changed, 94 insertions(+), 57 deletions(-)

diffs (truncated from 420 to 300 lines):

diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/color.c
--- a/lib/libcurses/color.c     Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/color.c     Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: color.c,v 1.17 2002/01/02 10:38:27 blymn Exp $ */
+/*     $NetBSD: color.c,v 1.18 2002/06/26 18:13:59 christos Exp $      */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: color.c,v 1.17 2002/01/02 10:38:27 blymn Exp $");
+__RCSID("$NetBSD: color.c,v 1.18 2002/06/26 18:13:59 christos Exp $");
 #endif                         /* not lint */
 
 #include "curses.h"
@@ -318,8 +318,8 @@
        pair = PAIR_NUMBER((u_int32_t)attr);
 #ifdef DEBUG
        __CTRACE("__set_color: %d, %d, %d\n", pair,
-                _cursesi_screen->pairs[pair].fore,
-                _cursesi_screen->pairs[pair].back);
+                _cursesi_screen->colour_pairs[pair].fore,
+                _cursesi_screen->colour_pairs[pair].back);
 #endif
        switch (_cursesi_screen->color_type) {
        /* Set ANSI forground and background colours */
diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/cr_put.c
--- a/lib/libcurses/cr_put.c    Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/cr_put.c    Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cr_put.c,v 1.20 2000/12/19 21:34:24 jdc Exp $  */
+/*     $NetBSD: cr_put.c,v 1.21 2002/06/26 18:14:00 christos Exp $     */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cr_put.c   8.3 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: cr_put.c,v 1.20 2000/12/19 21:34:24 jdc Exp $");
+__RCSID("$NetBSD: cr_put.c,v 1.21 2002/06/26 18:14:00 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -97,7 +97,7 @@
        int     in_refresh;
 {
        int     c, l;
-       char   cgp[1024];
+       char   cgp[128];
 
        if (destcol >= COLS) {
                destline += destcol / COLS;
@@ -166,14 +166,14 @@
        }
        if (destline < outline && !(__CA || __tc_up))
                destline = outline;
-       if (__CA) {
-               t_goto(NULL, __tc_cm, destcol, destline, cgp, 1023);
-
+       if (__CA && t_goto(NULL, __tc_cm, destcol, destline, cgp,
+           sizeof(cgp) - 1) != -1) {
                /*
                 * Need this condition due to inconsistent behavior
                 * of backspace on the last column.
                 */
-               if (outcol != COLS - 1 && plod((int) strlen(cgp), in_refresh) > 0)
+               if (outcol != COLS - 1 &&
+                   plod((int) strlen(cgp), in_refresh) > 0)
                        plod(0, in_refresh);
                else
                        tputs(cgp, 0, __cputchar);
diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/ctrace.c
--- a/lib/libcurses/ctrace.c    Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/ctrace.c    Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ctrace.c,v 1.12 2002/05/26 17:01:38 wiz Exp $  */
+/*     $NetBSD: ctrace.c,v 1.13 2002/06/26 18:14:02 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)ctrace.c   8.2 (Berkeley) 10/5/93";
 #else
-__RCSID("$NetBSD: ctrace.c,v 1.12 2002/05/26 17:01:38 wiz Exp $");
+__RCSID("$NetBSD: ctrace.c,v 1.13 2002/06/26 18:14:02 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -48,6 +48,7 @@
 
 #include <sys/time.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include "curses.h"
 #include "curses_private.h"
@@ -65,10 +66,16 @@
         static int seencr = 1;
        va_list ap;
 
-       if (tracefp == NULL)
-               tracefp = fopen(TFILE, "w");
-       if (tracefp == NULL)
+       if (tracefp == (void *)~0)
                return;
+       if (tracefp == NULL) {
+               char *tf = getenv("CURSES_TRACE_FILE");
+               tracefp = fopen(tf ? tf : TFILE, "w");
+       }
+       if (tracefp == NULL) {
+               tracefp = (void *)~0;
+               return;
+       }
        gettimeofday(&tv, NULL);
         if (seencr) {
                 gettimeofday(&tv, NULL);
diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/cur_hash.c
--- a/lib/libcurses/cur_hash.c  Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/cur_hash.c  Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cur_hash.c,v 1.9 2000/04/15 13:17:03 blymn Exp $       */
+/*     $NetBSD: cur_hash.c,v 1.10 2002/06/26 18:14:03 christos Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cur_hash.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: cur_hash.c,v 1.9 2000/04/15 13:17:03 blymn Exp $");
+__RCSID("$NetBSD: cur_hash.c,v 1.10 2002/06/26 18:14:03 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -48,15 +48,14 @@
 #include "curses_private.h"
 
 /*
- * __hash() is "hashpjw" from the Dragon Book, Aho, Sethi & Ullman, p.436.
+ * __hash_more() is "hashpjw" from the Dragon Book, Aho, Sethi & Ullman, p.436.
  */
 u_int
-__hash(char *s, int len)
+__hash_more(char *s, size_t len, u_int h)
 {
-       u_int   h, g, i;
+       u_int g;
+       size_t i = 0;
 
-       h = 0;
-       i = 0;
        while (i < len) {
                h = (h << 4) + s[i];
                if ((g = h & 0xf0000000) != 0) {
diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h    Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/curses_private.h    Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_private.h,v 1.20 2002/01/02 10:38:27 blymn Exp $        */
+/*     $NetBSD: curses_private.h,v 1.21 2002/06/26 18:14:03 christos Exp $     */
 
 /*-
  * Copyright (c) 1998-2000 Brett Lymn
@@ -231,7 +231,7 @@
        unsigned int len;
        int meta_state;
        char pad_char;
-       char ttytype[1024];
+       char ttytype[128];
        int endwin;
 };
 
@@ -255,7 +255,8 @@
 int      _cursesi_setterm(char *type, SCREEN *screen);
 int      _cursesi_wnoutrefresh(SCREEN *screen, WINDOW *win);
 int     __delay(void);
-unsigned int __hash(char *s, int len);
+unsigned int __hash_more(char *s, size_t len, u_int h);
+#define        __hash(s, len)  __hash_more(s, len, 0u)
 void    __id_subwins(WINDOW *orig);
 void    __init_getch(SCREEN *screen);
 void    __init_acs(SCREEN *screen);
diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/refresh.c
--- a/lib/libcurses/refresh.c   Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/refresh.c   Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: refresh.c,v 1.45 2002/01/02 10:38:28 blymn Exp $       */
+/*     $NetBSD: refresh.c,v 1.46 2002/06/26 18:14:04 christos Exp $    */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)refresh.c  8.7 (Berkeley) 8/13/94";
 #else
-__RCSID("$NetBSD: refresh.c,v 1.45 2002/01/02 10:38:28 blymn Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.46 2002/06/26 18:14:04 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -713,6 +713,11 @@
  * repainting the screen line by line.
  */
 
+static __LDATA buf[128];
+static  u_int last_hash;
+static  size_t last_hash_len;
+#define BLANKSIZE (sizeof(buf) / sizeof(buf[0]))
+
 static void
 quickch(void)
 {
@@ -721,7 +726,6 @@
        __LINE *clp, *tmp1, *tmp2;
        int     bsize, curs, curw, starts, startw, i, j;
        int     n, target, cur_period, bot, top, sc_region;
-       __LDATA buf[1024];
        u_int   blank_hash;
        attr_t  bcolor;
 
@@ -865,15 +869,28 @@
        }
 #endif
 
-       /* So we don't have to call __hash() each time */
-       for (i = 0; i < __virtscr->maxx; i++) {
-               buf[i].ch = ' ';
-               buf[i].bch = ' ';
-               buf[i].attr = 0;
-               buf[i].battr = 0;
+       if (buf[0].ch != ' ') {
+               for (i = 0; i < BLANKSIZE; i++) {
+                       buf[i].ch = ' ';
+                       buf[i].bch = ' ';
+                       buf[i].attr = 0;
+                       buf[i].battr = 0;
+               }
        }
-       blank_hash = __hash((char *)(void *)buf,
-           (int) (__virtscr->maxx * __LDATASIZE));
+
+       if (__virtscr->maxx != last_hash_len) {
+               blank_hash = 0;
+               for (i = __virtscr->maxx; i > BLANKSIZE; i -= BLANKSIZE) {
+                       blank_hash = __hash_more((char *)(void *)buf, sizeof(buf),
+                           blank_hash);
+               }
+               blank_hash = __hash_more((char *)(void *)buf,
+                   i * sizeof(buf[0]), blank_hash);
+               /* cache result in static data - screen width doesn't change often */
+               last_hash_len = __virtscr->maxx;
+               last_hash = blank_hash;
+       } else
+               blank_hash = last_hash;
 
        /*
         * Perform the rotation to maintain the consistency of curscr.
@@ -931,9 +948,16 @@
                        if ((n > 0 && target >= top && target < top + n) ||
                            (n < 0 && target <= bot && target > bot + n)) {
                                if (clp->hash != blank_hash || memcmp(clp->line,
-                                   buf, (size_t) __virtscr->maxx * __LDATASIZE) !=0) {
-                                       (void)memcpy(clp->line,  buf,
-                                           (size_t) __virtscr->maxx * __LDATASIZE);
+                                   clp->line + 1, (__virtscr->maxx - 1) *
+                                   __LDATASIZE) || memcmp(clp->line, buf,
+                                   __LDATASIZE)) {
+                                       for (i = __virtscr->maxx; i > BLANKSIZE;
+                                           i -= BLANKSIZE) {
+                                               (void)memcpy(clp->line + i -
+                                                   BLANKSIZE, buf, sizeof(buf));
+                                       }
+                                       (void)memcpy(clp->line , buf, i * 
+                                           sizeof(buf[0]));
 #ifdef DEBUG
                                        __CTRACE("-- blanked out: dirty\n");
 #endif
diff -r 7aa7b75e1257 -r de289aa9fa91 lib/libcurses/scanw.c
--- a/lib/libcurses/scanw.c     Wed Jun 26 18:08:49 2002 +0000
+++ b/lib/libcurses/scanw.c     Wed Jun 26 18:13:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scanw.c,v 1.16 2002/05/26 17:01:38 wiz Exp $   */
+/*     $NetBSD: scanw.c,v 1.17 2002/06/26 18:14:06 christos Exp $      */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)scanw.c    8.3 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: scanw.c,v 1.16 2002/05/26 17:01:38 wiz Exp $");
+__RCSID("$NetBSD: scanw.c,v 1.17 2002/06/26 18:14:06 christos Exp $");
 #endif
 #endif                         /* not lint */
 



Home | Main Index | Thread Index | Old Index