Module Name:    src
Committed By:   christos
Date:           Wed Feb 24 17:20:01 UTC 2016

Modified Files:
        src/lib/libedit: chartype.c chartype.h read.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libedit/chartype.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libedit/chartype.h
cvs rdiff -u -r1.84 -r1.85 src/lib/libedit/read.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/chartype.c
diff -u src/lib/libedit/chartype.c:1.21 src/lib/libedit/chartype.c:1.22
--- src/lib/libedit/chartype.c:1.21	Wed Feb 24 12:13:22 2016
+++ src/lib/libedit/chartype.c	Wed Feb 24 12:20:01 2016
@@ -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 @@ ct_encode_char(char *dst, size_t len, Ch
 	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)

Index: src/lib/libedit/chartype.h
diff -u src/lib/libedit/chartype.h:1.22 src/lib/libedit/chartype.h:1.23
--- src/lib/libedit/chartype.h:1.22	Wed Feb 24 12:13:22 2016
+++ src/lib/libedit/chartype.h	Wed Feb 24 12:20:01 2016
@@ -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 @@ Width(wchar_t c)
 
 #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 const Char *ct_visual_string(c
 protected int ct_chr_class(Char c);
 #endif
 
+size_t	ct_mbrtowc(wchar_t *, const char *, size_t);
+
 
 #endif /* _chartype_f */

Index: src/lib/libedit/read.c
diff -u src/lib/libedit/read.c:1.84 src/lib/libedit/read.c:1.85
--- src/lib/libedit/read.c:1.84	Wed Feb 24 12:13:22 2016
+++ src/lib/libedit/read.c	Wed Feb 24 12:20:01 2016
@@ -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 @@ read_char(EditLine *el, wchar_t *cp)
 	}
 
 	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) {
 				/*

Reply via email to