Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit From Ingo Schwarze:



details:   https://anonhg.NetBSD.org/src/rev/3f1773b96c93
branches:  trunk
changeset: 813696:3f1773b96c93
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 14 14:49:34 2016 +0000

description:
>From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t.  Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not.  Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn.  Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved.  It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t".  Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous.  Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c.  If WIDECHAR was defined, it printed an
Int = wint_t value with %c.  Fortunately, that bug only affects
debugging, not production.  The fix is contained in the patch.

With WIDECHAR, this doesn't change anything.  For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.

diffstat:

 lib/libedit/chared.c   |   20 ++++----
 lib/libedit/chared.h   |   18 ++++----
 lib/libedit/chartype.h |    6 +--
 lib/libedit/common.c   |   74 ++++++++++++++++----------------
 lib/libedit/emacs.c    |   44 +++++++++---------
 lib/libedit/keymacro.c |    8 +-
 lib/libedit/makelist   |    7 +-
 lib/libedit/map.c      |   12 ++--
 lib/libedit/parse.c    |    6 +-
 lib/libedit/refresh.c  |   16 +++---
 lib/libedit/refresh.h  |    4 +-
 lib/libedit/search.c   |   14 +++---
 lib/libedit/search.h   |    6 +-
 lib/libedit/terminal.c |   10 ++--
 lib/libedit/terminal.h |    6 +-
 lib/libedit/tty.c      |   14 +++---
 lib/libedit/vi.c       |  108 ++++++++++++++++++++++++------------------------
 17 files changed, 185 insertions(+), 188 deletions(-)

diffs (truncated from 1580 to 300 lines):

diff -r 54c83602ae01 -r 3f1773b96c93 lib/libedit/chared.c
--- a/lib/libedit/chared.c      Sun Feb 14 14:47:48 2016 +0000
+++ b/lib/libedit/chared.c      Sun Feb 14 14:49:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $     */
+/*     $NetBSD: chared.c,v 1.41 2016/02/14 14:49:34 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)chared.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.41 2016/02/14 14:49:34 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -199,7 +199,7 @@
  *     Return if p is part of a word according to emacs
  */
 protected int
-ce__isword(Int p)
+ce__isword(wint_t p)
 {
        return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
 }
@@ -209,7 +209,7 @@
  *     Return if p is part of a word according to vi
  */
 protected int
-cv__isword(Int p)
+cv__isword(wint_t p)
 {
        if (Isalnum(p) || p == '_')
                return 1;
@@ -223,7 +223,7 @@
  *     Return if p is part of a big word according to vi
  */
 protected int
-cv__isWord(Int p)
+cv__isWord(wint_t p)
 {
        return !Isspace(p);
 }
@@ -233,7 +233,7 @@
  *     Find the previous word
  */
 protected Char *
-c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
+c__prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t))
 {
        p--;
 
@@ -257,7 +257,7 @@
  *     Find the next word
  */
 protected Char *
-c__next_word(Char *p, Char *high, int n, int (*wtest)(Int))
+c__next_word(Char *p, Char *high, int n, int (*wtest)(wint_t))
 {
        while (n--) {
                while ((p < high) && !(*wtest)(*p))
@@ -275,7 +275,7 @@
  *     Find the next word vi style
  */
 protected Char *
-cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int))
+cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(wint_t))
 {
        int test;
 
@@ -304,7 +304,7 @@
  *     Find the previous word vi style
  */
 protected Char *
-cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
+cv_prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t))
 {
        int test;
 
@@ -368,7 +368,7 @@
  *     Go to the end of this word according to vi
  */
 protected Char *
-cv__endword(Char *p, Char *high, int n, int (*wtest)(Int))
+cv__endword(Char *p, Char *high, int n, int (*wtest)(wint_t))
 {
        int test;
 
diff -r 54c83602ae01 -r 3f1773b96c93 lib/libedit/chared.h
--- a/lib/libedit/chared.h      Sun Feb 14 14:47:48 2016 +0000
+++ b/lib/libedit/chared.h      Sun Feb 14 14:49:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $     */
+/*     $NetBSD: chared.h,v 1.23 2016/02/14 14:49:34 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -146,17 +146,17 @@
 #include "fcns.h"
 
 
-protected int   cv__isword(Int);
-protected int   cv__isWord(Int);
+protected int   cv__isword(wint_t);
+protected int   cv__isWord(wint_t);
 protected void  cv_delfini(EditLine *);
-protected Char *cv__endword(Char *, Char *, int, int (*)(Int));
-protected int   ce__isword(Int);
+protected Char *cv__endword(Char *, Char *, int, int (*)(wint_t));
+protected int   ce__isword(wint_t);
 protected void  cv_undo(EditLine *);
 protected void  cv_yank(EditLine *, const Char *, int);
-protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int));
-protected Char *cv_prev_word(Char *, Char *, int, int (*)(Int));
-protected Char *c__next_word(Char *, Char *, int, int (*)(Int));
-protected Char *c__prev_word(Char *, Char *, int, int (*)(Int));
+protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(wint_t));
+protected Char *cv_prev_word(Char *, Char *, int, int (*)(wint_t));
+protected Char *c__next_word(Char *, Char *, int, int (*)(wint_t));
+protected Char *c__prev_word(Char *, Char *, int, int (*)(wint_t));
 protected void  c_insert(EditLine *, int);
 protected void  c_delbefore(EditLine *, int);
 protected void  c_delbefore1(EditLine *);
diff -r 54c83602ae01 -r 3f1773b96c93 lib/libedit/chartype.h
--- a/lib/libedit/chartype.h    Sun Feb 14 14:47:48 2016 +0000
+++ b/lib/libedit/chartype.h    Sun Feb 14 14:49:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.h,v 1.18 2016/02/14 14:47:48 christos Exp $   */
+/*     $NetBSD: chartype.h,v 1.19 2016/02/14 14:49:34 christos Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -67,11 +67,9 @@
 #define ct_mbstowcs          mbstowcs
 
 #define Char                   wchar_t
-#define Int                    wint_t
 #define FUN(prefix,rest)       prefix ## _w ## rest
 #define FUNW(type)             type ## _w
 #define TYPE(type)             type ## W
-#define FCHAR                  "%lc"
 #define FSTR                   "%ls"
 #define STR(x)                         L ## x
 #define UC(c)                  c
@@ -121,11 +119,9 @@
 #define ct_mbstowcs(a, b, c)    (strncpy(a, b, c), strlen(a))
 
 #define Char                   char
-#define Int                    int
 #define FUN(prefix,rest)       prefix ## _ ## rest
 #define FUNW(type)             type
 #define TYPE(type)             type
-#define FCHAR                  "%c"
 #define FSTR                   "%s"
 #define STR(x)                         x
 #define UC(c)                  (unsigned char)(c)
diff -r 54c83602ae01 -r 3f1773b96c93 lib/libedit/common.c
--- a/lib/libedit/common.c      Sun Feb 14 14:47:48 2016 +0000
+++ b/lib/libedit/common.c      Sun Feb 14 14:49:34 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.30 2016/02/11 19:21:04 christos Exp $     */
+/*     $NetBSD: common.c,v 1.31 2016/02/14 14:49:34 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)common.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: common.c,v 1.30 2016/02/11 19:21:04 christos Exp $");
+__RCSID("$NetBSD: common.c,v 1.31 2016/02/14 14:49:34 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -52,7 +52,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_end_of_file(EditLine *el, Int c __attribute__((__unused__)))
+ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__)))
 {
 
        re_goto_bottom(el);
@@ -66,7 +66,7 @@
  *     Insert a character [bound to all insert keys]
  */
 protected el_action_t
-ed_insert(EditLine *el, Int c)
+ed_insert(EditLine *el, wint_t c)
 {
        int count = el->el_state.argument;
 
@@ -109,7 +109,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__)))
+ed_delete_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
 {
        Char *cp, *p, *kp;
 
@@ -137,7 +137,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__)))
+ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
 {
 #ifdef DEBUG_EDIT
 #define        EL      el->el_line
@@ -184,7 +184,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_kill_line(EditLine *el, Int c __attribute__((__unused__)))
+ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__)))
 {
        Char *kp, *cp;
 
@@ -205,7 +205,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_move_to_end(EditLine *el, Int c __attribute__((__unused__)))
+ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__)))
 {
 
        el->el_line.cursor = el->el_line.lastchar;
@@ -228,7 +228,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__)))
+ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__)))
 {
 
        el->el_line.cursor = el->el_line.buffer;
@@ -251,7 +251,7 @@
  *     [^T] [^T]
  */
 protected el_action_t
-ed_transpose_chars(EditLine *el, Int c)
+ed_transpose_chars(EditLine *el, wint_t c)
 {
 
        if (el->el_line.cursor < el->el_line.lastchar) {
@@ -277,7 +277,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_next_char(EditLine *el, Int c __attribute__((__unused__)))
+ed_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
 {
        Char *lim = el->el_line.lastchar;
 
@@ -306,7 +306,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_prev_word(EditLine *el, Int c __attribute__((__unused__)))
+ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
 {
 
        if (el->el_line.cursor == el->el_line.buffer)
@@ -332,7 +332,7 @@
  */
 protected el_action_t
 /*ARGSUSED*/
-ed_prev_char(EditLine *el, Int c __attribute__((__unused__)))
+ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
 {
 
        if (el->el_line.cursor > el->el_line.buffer) {
@@ -356,7 +356,7 @@
  *     [^V] [^V]
  */
 protected el_action_t
-ed_quoted_insert(EditLine *el, Int c)
+ed_quoted_insert(EditLine *el, wint_t c)
 {
        int num;
        Char tc;
@@ -376,7 +376,7 @@
  *     Adds to argument or enters a digit
  */
 protected el_action_t
-ed_digit(EditLine *el, Int c)
+ed_digit(EditLine *el, wint_t c)
 {
 
        if (!Isdigit(c))
@@ -404,7 +404,7 @@
  *     For ESC-n
  */
 protected el_action_t
-ed_argument_digit(EditLine *el, Int c)
+ed_argument_digit(EditLine *el, wint_t c)
 {



Home | Main Index | Thread Index | Old Index