Source-Changes-HG archive

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

[src/netbsd-8]: src/lib/libcurses Pull up following revision(s) (requested by...



details:   https://anonhg.NetBSD.org/src/rev/6f2b2502a16b
branches:  netbsd-8
changeset: 449662:6f2b2502a16b
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Mar 15 14:30:19 2019 +0000

description:
Pull up following revision(s) (requested by rin in ticket #1214):

        lib/libcurses/get_wch.c: revision 1.21
        lib/libcurses/getch.c: revision 1.71

Rename global variable "state" to "_cursesi_state".

Until now, if application happens to have a global variable of the same
name, it was overridden by curses routines. This is the scenario in
which aspell crashes when linked to our curses, reported in pkg/44005.

We need to wipe out global/static variables like "_cursesi_state" or
"wstate" for thread safety. But it would be a future task...

XXX pullup to netbsd-8 and netbsd-7

diffstat:

 lib/libcurses/get_wch.c |  24 ++++++++++++------------
 lib/libcurses/getch.c   |  34 ++++++++++++++++++----------------
 2 files changed, 30 insertions(+), 28 deletions(-)

diffs (218 lines):

diff -r 56dc7a7b92a5 -r 6f2b2502a16b lib/libcurses/get_wch.c
--- a/lib/libcurses/get_wch.c   Wed Mar 13 10:53:16 2019 +0000
+++ b/lib/libcurses/get_wch.c   Fri Mar 15 14:30:19 2019 +0000
@@ -1,4 +1,4 @@
-/*   $NetBSD: get_wch.c,v 1.14.4.3 2018/10/03 17:49:06 martin Exp $ */
+/*   $NetBSD: get_wch.c,v 1.14.4.4 2019/03/15 14:30:19 martin Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: get_wch.c,v 1.14.4.3 2018/10/03 17:49:06 martin Exp $");
+__RCSID("$NetBSD: get_wch.c,v 1.14.4.4 2019/03/15 14:30:19 martin Exp $");
 #endif                                           /* not lint */
 
 #include <errno.h>
@@ -49,9 +49,9 @@
 #include "keymap.h"
 
 #ifdef HAVE_WCHAR
-static short   wstate;           /* state of the wcinkey function */
+static short   wstate;         /* state of the wcinkey function */
 #endif /* HAVE_WCHAR */
-extern short state;            /* storage declared in getch.c */
+extern short _cursesi_state;   /* storage declared in getch.c */
 
 /* prototypes for private functions */
 #ifdef HAVE_WCHAR
@@ -223,7 +223,7 @@
                                *wc = inbuf[*start];
                                *working = *start = (*start +1) % MAX_CBUF_SIZE;
                                if (*start == *end) {
-                                       state = wstate = INKEY_NORM;
+                                       _cursesi_state = wstate = INKEY_NORM;
 #ifdef DEBUG
                                        __CTRACE(__CTRACE_INPUT,
                                            "inkey: WCASSEMBLING=>NORM, "
@@ -231,7 +231,7 @@
                                            *start, *working, *end);
 #endif /* DEBUG */
                                } else {
-                                       state = wstate = INKEY_BACKOUT;
+                                       _cursesi_state = wstate = INKEY_BACKOUT;
 #ifdef DEBUG
                                        __CTRACE(__CTRACE_INPUT,
                                            "inkey: WCASSEMBLING=>BACKOUT, "
@@ -290,7 +290,7 @@
 
                                if (*start == *end) {
                                        /* only one char processed */
-                                       state = wstate = INKEY_NORM;
+                                       _cursesi_state = wstate = INKEY_NORM;
 #ifdef DEBUG
                                        __CTRACE(__CTRACE_INPUT,
                                            "inkey: WCASSEMBLING=>NORM, "
@@ -300,7 +300,7 @@
                                } else {
                                        /* otherwise we must have more than
                                         * one char to backout */
-                                       state = wstate = INKEY_BACKOUT;
+                                       _cursesi_state = wstate = INKEY_BACKOUT;
 #ifdef DEBUG
                                        __CTRACE(__CTRACE_INPUT,
                                            "inkey: WCASSEMBLING=>BACKOUT, "
@@ -388,7 +388,7 @@
                        }
 
                        if (*start == *end) {   /* only one char processed */
-                               state = wstate = INKEY_NORM;
+                               _cursesi_state = wstate = INKEY_NORM;
 #ifdef DEBUG
                                __CTRACE(__CTRACE_INPUT,
                                    "inkey: Empty cbuf=>NORM, "
@@ -398,7 +398,7 @@
                        } else {
                                /* otherwise we must have more than one
                                 * char to backout */
-                               state = wstate = INKEY_BACKOUT;
+                               _cursesi_state = wstate = INKEY_BACKOUT;
 #ifdef DEBUG
                                __CTRACE(__CTRACE_INPUT,
                                    "inkey: Non-empty cbuf=>BACKOUT, "
@@ -423,7 +423,7 @@
 #endif /* DEBUG */
                                if (*start == *end) {
                                        /* if it is go back to normal */
-                                       state = wstate = INKEY_NORM;
+                                       _cursesi_state = wstate = INKEY_NORM;
 #ifdef DEBUG
                                        __CTRACE(__CTRACE_INPUT,
                                            "[inkey]=>NORM, start(%d), "
@@ -432,7 +432,7 @@
 #endif /* DEBUG */
                                } else {
                                        /* otherwise go to backout state */
-                                       state = wstate = INKEY_BACKOUT;
+                                       _cursesi_state = wstate = INKEY_BACKOUT;
 #ifdef DEBUG
                                        __CTRACE(__CTRACE_INPUT,
                                            "[inkey]=>BACKOUT, start(%d), "
diff -r 56dc7a7b92a5 -r 6f2b2502a16b lib/libcurses/getch.c
--- a/lib/libcurses/getch.c     Wed Mar 13 10:53:16 2019 +0000
+++ b/lib/libcurses/getch.c     Fri Mar 15 14:30:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getch.c,v 1.65.4.3 2018/10/03 17:49:06 martin Exp $    */
+/*     $NetBSD: getch.c,v 1.65.4.4 2019/03/15 14:30:19 martin Exp $    */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getch.c    8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: getch.c,v 1.65.4.3 2018/10/03 17:49:06 martin Exp $");
+__RCSID("$NetBSD: getch.c,v 1.65.4.4 2019/03/15 14:30:19 martin Exp $");
 #endif
 #endif                                 /* not lint */
 
@@ -47,7 +47,7 @@
 #include "curses_private.h"
 #include "keymap.h"
 
-short  state;          /* state of the inkey function */
+short _cursesi_state;          /* state of the inkey function */
 
 static const struct tcdata tc[] = {
        {TICODE_kSAV, KEY_SSAVE},
@@ -447,7 +447,7 @@
 #endif
 
        /* init the inkey state variable */
-       state = INKEY_NORM;
+       _cursesi_state = INKEY_NORM;
 
        /* init the base keymap */
        screen->base_keymap = new_keymap();
@@ -557,7 +557,7 @@
 #endif
        for (;;) {              /* loop until we get a complete key sequence */
 reread:
-               if (state == INKEY_NORM) {
+               if (_cursesi_state == INKEY_NORM) {
                        if (delay && __timeout(delay) == ERR)
                                return ERR;
                        c = __fgetc_resize(infd);
@@ -579,9 +579,11 @@
                        inbuf[working] = k;
                        INC_POINTER(working);
                        end = working;
-                       state = INKEY_ASSEMBLING;       /* go to the assembling
-                                                        * state now */
-               } else if (state == INKEY_BACKOUT) {
+
+                       /* go to the assembling state now */
+                       _cursesi_state = INKEY_ASSEMBLING;
+
+               } else if (_cursesi_state == INKEY_BACKOUT) {
                        k = inbuf[working];
                        INC_POINTER(working);
                        if (working == end) {   /* see if we have run
@@ -589,9 +591,9 @@
                                                 * backlog */
 
                                /* if we have then switch to assembling */
-                               state = INKEY_ASSEMBLING;
+                               _cursesi_state = INKEY_ASSEMBLING;
                        }
-               } else if (state == INKEY_ASSEMBLING) {
+               } else if (_cursesi_state == INKEY_ASSEMBLING) {
                        /* assembling a key sequence */
                        if (delay) {
                                if (__timeout(to ? (ESCDELAY / 100) : delay)
@@ -623,7 +625,7 @@
                                        goto reread;
 
                                k = inbuf[start];
-                               state = INKEY_TIMEOUT;
+                               _cursesi_state = INKEY_TIMEOUT;
                        } else {
                                k = (wchar_t) c;
                                inbuf[working] = k;
@@ -640,7 +642,7 @@
                   * timed out and the key has not been disabled
                   */
                mapping = current->mapping[k];
-               if (((state == INKEY_TIMEOUT) || (mapping < 0))
+               if (((_cursesi_state == INKEY_TIMEOUT) || (mapping < 0))
                        || ((current->key[mapping]->type == KEYMAP_LEAF)
                            && (current->key[mapping]->enable == FALSE))) {
                        /* return the first key we know about */
@@ -650,10 +652,10 @@
                        working = start;
 
                        if (start == end) {     /* only one char processed */
-                               state = INKEY_NORM;
+                               _cursesi_state = INKEY_NORM;
                        } else {/* otherwise we must have more than one char
                                 * to backout */
-                               state = INKEY_BACKOUT;
+                               _cursesi_state = INKEY_BACKOUT;
                        }
                        return k;
                } else {        /* must be part of a multikey sequence */
@@ -665,10 +667,10 @@
                                /* check if inbuf empty now */
                                if (start == end) {
                                        /* if it is go back to normal */
-                                       state = INKEY_NORM;
+                                       _cursesi_state = INKEY_NORM;
                                } else {
                                        /* otherwise go to backout state */
-                                       state = INKEY_BACKOUT;
+                                       _cursesi_state = INKEY_BACKOUT;
                                }
 
                                /* return the symbol */



Home | Main Index | Thread Index | Old Index