Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit Tuck in mbstate_t to the wide char version only ...



details:   https://anonhg.NetBSD.org/src/rev/b9e1912dad3f
branches:  trunk
changeset: 813890:b9e1912dad3f
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 24 17:20:01 2016 +0000

description:
Tuck in mbstate_t to the wide char version only to avoid exposing the zeroing
hack and doing it in the narrow case.

diffstat:

 lib/libedit/chartype.c |  17 ++++++++++++-----
 lib/libedit/chartype.h |   7 +++----
 lib/libedit/read.c     |   9 +++------
 3 files changed, 18 insertions(+), 15 deletions(-)

diffs (114 lines):

diff -r b2ed97dbb70b -r b9e1912dad3f lib/libedit/chartype.c
--- a/lib/libedit/chartype.c    Wed Feb 24 17:13:48 2016 +0000
+++ b/lib/libedit/chartype.c    Wed Feb 24 17:20:01 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.c,v 1.21 2016/02/24 17:13:22 christos Exp $   */
+/*     $NetBSD: chartype.c,v 1.22 2016/02/24 17:20:01 christos Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.21 2016/02/24 17:13:22 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.22 2016/02/24 17:20:01 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <ctype.h>
@@ -215,12 +215,19 @@
        return l;
 }
 
+size_t
+ct_mbrtowc(wchar_t *wc, const char *s, size_t n)
+{
+       mbstate_t mbs;
+       /* This only works because UTF-8 is stateless */
+       memset(&mbs, 0, sizeof(mbs));
+       return mbrtowc(wc, s, n, &mbs);
+}
+
 #else
 
 size_t
-/*ARGSUSED*/
-ct_mbrtowc(wchar_t *wc, const char *s, size_t n,
-    void *mbs __attribute__((__unused__))) {
+ct_mbrtowc(wchar_t *wc, const char *s, size_t n)
        if (s == NULL)
                return 0;
        if (n == 0)
diff -r b2ed97dbb70b -r b9e1912dad3f lib/libedit/chartype.h
--- a/lib/libedit/chartype.h    Wed Feb 24 17:13:48 2016 +0000
+++ b/lib/libedit/chartype.h    Wed Feb 24 17:20:01 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.h,v 1.22 2016/02/24 17:13:22 christos Exp $   */
+/*     $NetBSD: chartype.h,v 1.23 2016/02/24 17:20:01 christos Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,6 @@
 #define _h_chartype_f
 
 
-
 #ifdef WIDECHAR
 
 /* Ideally we should also test the value of the define to see if it
@@ -60,7 +59,6 @@
 #warning Build environment does not support non-BMP characters
 #endif
 
-#define ct_mbrtowc           mbrtowc
 #define ct_wctob             wctob
 #define ct_wctomb            wctomb
 #define ct_wctomb_reset      wctomb(0,0)
@@ -113,7 +111,6 @@
 
 #else /* NARROW */
 
-size_t ct_mbrtowc(wchar_t *, const char *, size_t, void *);
 #define ct_wctob(w)          ((int)(w))
 #define ct_wctomb            error
 #define ct_wctomb_reset
@@ -246,5 +243,7 @@
 protected int ct_chr_class(Char c);
 #endif
 
+size_t ct_mbrtowc(wchar_t *, const char *, size_t);
+
 
 #endif /* _chartype_f */
diff -r b2ed97dbb70b -r b9e1912dad3f lib/libedit/read.c
--- a/lib/libedit/read.c        Wed Feb 24 17:13:48 2016 +0000
+++ b/lib/libedit/read.c        Wed Feb 24 17:20:01 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: read.c,v 1.84 2016/02/24 17:13:22 christos Exp $       */
+/*     $NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $       */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)read.c     8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: read.c,v 1.84 2016/02/24 17:13:22 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -343,12 +343,9 @@
        }
 
        for (;;) {
-               mbstate_t mbs;
 
                ++cbp;
-               /* This only works because UTF8 is stateless */
-               memset(&mbs, 0, sizeof(mbs));
-               switch (ct_mbrtowc(cp, cbuf, cbp, &mbs)) {
+               switch (ct_mbrtowc(cp, cbuf, cbp)) {
                case (size_t)-1:
                        if (cbp > 1) {
                                /*



Home | Main Index | Thread Index | Old Index