wcwidth on mingw
Similarly for wcwidth, I'm seeing this error: ../gllib/wchar.h:678: error: `wcwidth' was not declared in this scope Here too the problem is that gnulib defines a function rpl_wcwidth, although wcwidth does not exist on mingw. gnulib could just define wcwidth instead. This fixes it: 2010-04-03 Bruno Haible br...@clisp.org wcwidth: Fix C++ test error on mingw. * lib/wcwidth.c (wcwidth): Renamed from rpl_wcwidth. * m4/wcwidth.m4 (gl_FUNC_WCWIDTH): If the wcwidth function does not exist, don't set REPLACE_WCWIDTH. Instead, rely on HAVE_DECL_WCWIDTH. --- ChangeLog.orig Sun Apr 4 02:41:12 2010 +++ ChangeLog Sun Apr 4 02:40:53 2010 @@ -1,5 +1,12 @@ 2010-04-03 Bruno Haible br...@clisp.org + wcwidth: Fix C++ test error on mingw. + * lib/wcwidth.c (wcwidth): Renamed from rpl_wcwidth. + * m4/wcwidth.m4 (gl_FUNC_WCWIDTH): If the wcwidth function does not + exist, don't set REPLACE_WCWIDTH. Instead, rely on HAVE_DECL_WCWIDTH. + +2010-04-03 Bruno Haible br...@clisp.org + nanosleep: Fix C++ test error on mingw. * lib/nanosleep.c (nanosleep): Renamed from rpl_nanosleep. * lib/time.in.h (nanosleep): Use modern idiom. --- lib/wcwidth.c.orig Sun Apr 4 02:41:12 2010 +++ lib/wcwidth.c Sun Apr 4 02:24:44 2010 @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a character. - Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2006-2007, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,10 +26,9 @@ #include streq.h #include uniwidth.h -#undef wcwidth - int -rpl_wcwidth (wchar_t wc) +wcwidth (wchar_t wc) +#undef wcwidth { /* In UTF-8 locales, use a Unicode aware width function. */ const char *encoding = locale_charset (); --- m4/wcwidth.m4.orig Sun Apr 4 02:41:12 2010 +++ m4/wcwidth.m4 Sun Apr 4 02:41:06 2010 @@ -1,4 +1,4 @@ -# wcwidth.m4 serial 15 +# wcwidth.m4 serial 16 dnl Copyright (C) 2006-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,9 +34,7 @@ HAVE_DECL_WCWIDTH=0 fi - if test $ac_cv_func_wcwidth = no; then -REPLACE_WCWIDTH=1 - else + if test $ac_cv_func_wcwidth = yes; then dnl On MacOS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1. dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1. dnl This leads to bugs in 'ls' (coreutils). @@ -84,11 +82,13 @@ *no) REPLACE_WCWIDTH=1 ;; esac fi - if test $REPLACE_WCWIDTH = 1; then + if test $ac_cv_func_wcwidth != yes || test $REPLACE_WCWIDTH = 1; then AC_LIBOBJ([wcwidth]) fi - - if test $REPLACE_WCWIDTH = 1 || test $HAVE_DECL_WCWIDTH = 0; then + if test $ac_cv_func_wcwidth != yes || test $REPLACE_WCWIDTH = 1 \ + || test $HAVE_DECL_WCWIDTH = 0; then gl_REPLACE_WCHAR_H fi + dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not + dnl have the wcwidth function, then it does not declare it. ])
Re: [bug-gnulib] wcwidth on mingw
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Bruno Haible on 6/27/2006 12:15 PM: I note that mbswidth.c takes precautions to ensure wcwidth exists; should we break that out into a wcwidth module and make both mbchar and mbswidth depend on it? This would make sense, yes. I'm normally not fond of major changes that avoid an implicit declaration of function warning of a function that returns 'int' anyway. But here we have gone through the trouble of doing it right already in mbswidth.c - why not reuse this technique. OK, applied as follows based on your feedback, after testing in both cygwin (which has wcwidth) and mingw (which has iswprint, but not wcwidth). If there is any fallout, we can add further patches later. By the way, is it safe to assume wchar_t exists, or should wcwidth pull in m4/wchar_t.m4? Also, on mingw, where sizeof(wchar_t)==2 but sizeof(int)==4, a prototype of int wcwidth() is incompatible with a declaration of int wcwidth(wchar_t wc) because of promotion rules. 2006-06-28 Eric Blake [EMAIL PROTECTED] * modules/wcwidth: New file. * modules/mbchar (Depends-on): Add wcwidth. * modules/mbswidth (Depends-on): Add wcwidth. * MODULES.html.sh: Add wcwidth. 2006-06-28 Eric Blake [EMAIL PROTECTED] * mbchar.h (wcwidth): Include wcwidth.h. * mbswidth.c (wcwidth): Move from here... * wcwidth.h: ...to this new file. 2006-06-28 Eric Blake [EMAIL PROTECTED] * mbswidth.m4 (gl_MBSDWIDTH): Move wcwidth from here... * wcwidth.m4 (gl_FUNC_WCWIDTH): ...to this new file. - -- Life is short - so eat dessert first! Eric Blake [EMAIL PROTECTED] -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEon7w84KuGfSFAYARAsT1AJ4qlkfCp+/rIwjVwq8FUs9V57er4ACfSSw4 17OsMd39JW8XI0oqc4xJk1E= =MRhe -END PGP SIGNATURE- Index: lib/wcwidth.h === RCS file: lib/wcwidth.h diff -N lib/wcwidth.h --- /dev/null 1 Jan 1970 00:00:00 - +++ lib/wcwidth.h 28 Jun 2006 12:59:33 - @@ -0,0 +1,52 @@ +/* Determine the number of screen columns needed for a character. + Copyright (C) 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _gl_WCWIDTH_H +#define _gl_WCWIDTH_H + +/* Get wcwidth if available, along with wchar_t. */ +#if HAVE_WCHAR_H +/* Tru64 with Desktop Toolkit C has a bug: stdio.h must be included before + wchar.h. + BSD/OS 4.1 has a bug: stdio.h and time.h must be included before + wchar.h. */ +# include stdio.h +# include time.h +# include wchar.h +#endif + +/* Get iswprint. */ +#if HAVE_WCTYPE_H +# include wctype.h +#endif +#if !defined iswprint !HAVE_ISWPRINT +# define iswprint(wc) 1 +#endif + +#if !defined wcwidth !HAVE_WCWIDTH + +/* wcwidth doesn't exist, so assume all printable characters have + width 1. */ +static inline int +wcwidth (wchar_t wc) +{ + return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; +} + +#endif + +#endif /* _gl_WCWIDTH_H */ Index: lib/mbchar.h === RCS file: /sources/gnulib/gnulib/lib/mbchar.h,v retrieving revision 1.2 diff -u -p -r1.2 mbchar.h --- lib/mbchar.h16 Aug 2005 16:07:59 - 1.2 +++ lib/mbchar.h28 Jun 2006 12:59:33 - @@ -1,5 +1,5 @@ /* Multibyte character data type. - Copyright (C) 2001, 2005 Free Software Foundation, Inc. + Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -158,6 +158,8 @@ #include wctype.h +#include wcwidth.h + #define MBCHAR_BUF_SIZE 24 struct mbchar Index: lib/mbswidth.c === RCS file: /sources/gnulib/gnulib/lib/mbswidth.c,v retrieving revision 1.14 diff -u -p -r1.14 mbswidth.c --- lib/mbswidth.c 14 May 2005 06:03:58 - 1.14 +++ lib/mbswidth.c 28 Jun 2006 12:59:33 - @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a string. - Copyright (C) 2000-2005
Re: [bug-gnulib] wcwidth on mingw
Eric Blake wrote: By the way, is it safe to assume wchar_t exists No it isn't. Good point. Either the module description should have #if HAVE_WCHAR_T # include wcwidth.h #endif or wcwidth.h should protect against this case itself. The latter is obviously better. Also, on mingw, where sizeof(wchar_t)==2 but sizeof(int)==4, a prototype of int wcwidth() is incompatible with a declaration of int wcwidth(wchar_t wc) because of promotion rules. Yes, but that's not a reason for removing the declaration and not testing HAVE_DECL_WCWIDTH any more. If wchar_t is really only 16 bit, and if we write extern int wcwidth(wchar_t wc); some compilers on some platforms might not zero/sign-extend the argument when passing a 16-bit value. (I.e. they might pass garbage in the upper 16 bits of the argument word.) Whereas when we write extern int wcwidth(int wc); we tell the compiler to do a zero/sign-extend. This is safer. Further issues: - In mbswidth.c you removed the includes of wchar.h and wctype.h. But they are needed for iswcntrl(). Things are more maintainable if you write down the includes, even if they are *currently* redundant, because when someone will change wcwidth.h in the future, he will certainly not look at recompiling mbswidth.c. - When 'inline' is used, we must arrange to invoke AC_C_INLINE. I fixed these, patch appended. Bruno diff -c -3 -r1.1 wcwidth.h *** lib/wcwidth.h 28 Jun 2006 13:11:03 - 1.1 --- lib/wcwidth.h 28 Jun 2006 16:52:51 - *** *** 18,43 #ifndef _gl_WCWIDTH_H #define _gl_WCWIDTH_H /* Get wcwidth if available, along with wchar_t. */ ! #if HAVE_WCHAR_H /* Tru64 with Desktop Toolkit C has a bug: stdio.h must be included before wchar.h. BSD/OS 4.1 has a bug: stdio.h and time.h must be included before wchar.h. */ ! # include stdio.h ! # include time.h ! # include wchar.h ! #endif /* Get iswprint. */ ! #if HAVE_WCTYPE_H ! # include wctype.h ! #endif ! #if !defined iswprint !HAVE_ISWPRINT ! # define iswprint(wc) 1 ! #endif ! #if !defined wcwidth !HAVE_WCWIDTH /* wcwidth doesn't exist, so assume all printable characters have width 1. */ --- 18,49 #ifndef _gl_WCWIDTH_H #define _gl_WCWIDTH_H + #if HAVE_WCHAR_T + /* Get wcwidth if available, along with wchar_t. */ ! # if HAVE_WCHAR_H /* Tru64 with Desktop Toolkit C has a bug: stdio.h must be included before wchar.h. BSD/OS 4.1 has a bug: stdio.h and time.h must be included before wchar.h. */ ! # include stdio.h ! # include time.h ! # include wchar.h ! # endif /* Get iswprint. */ ! # if HAVE_WCTYPE_H ! # include wctype.h ! # endif ! # if !defined iswprint !HAVE_ISWPRINT ! # define iswprint(wc) 1 ! # endif ! # ifndef HAVE_DECL_WCWIDTH ! this configure-time declaration test was not run ! # endif ! # ifndef wcwidth ! # if !HAVE_WCWIDTH /* wcwidth doesn't exist, so assume all printable characters have width 1. */ *** *** 47,52 return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; } ! #endif #endif /* _gl_WCWIDTH_H */ --- 53,70 return wc == 0 ? 0 : iswprint (wc) ? 1 : -1; } ! # elif !HAVE_DECL_WCWIDTH ! ! /* wcwidth exists but is not declared. */ ! extern ! # ifdef __cplusplus ! C ! # endif ! int wcwidth (int /* actually wchar_t */); ! ! # endif ! # endif ! ! #endif /* HAVE_WCHAR_H */ #endif /* _gl_WCWIDTH_H */ diff -c -3 -r1.15 mbswidth.c *** lib/mbswidth.c 28 Jun 2006 13:11:03 - 1.15 --- lib/mbswidth.c 28 Jun 2006 16:52:51 - *** *** 32,41 /* Get isprint(). */ #include ctype.h ! /* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */ #include wcwidth.h /* Get iswcntrl(). */ #if !defined iswcntrl !HAVE_ISWCNTRL # define iswcntrl(wc) 0 #endif --- 32,55 /* Get isprint(). */ #include ctype.h ! /* Get mbstate_t, mbrtowc(), mbsinit(). */ ! #if HAVE_WCHAR_H ! /* Tru64 with Desktop Toolkit C has a bug: stdio.h must be included before !wchar.h. !BSD/OS 4.1 has a bug: stdio.h and time.h must be included before !wchar.h. */ ! # include stdio.h ! # include time.h ! # include wchar.h ! #endif ! ! /* Get wcwidth(). */ #include wcwidth.h /* Get iswcntrl(). */ + #if HAVE_WCTYPE_H + # include wctype.h + #endif #if !defined iswcntrl !HAVE_ISWCNTRL # define iswcntrl(wc) 0 #endif diff -c -3 -r1.1 wcwidth.m4 *** m4/wcwidth.m4 28 Jun 2006 13:10:13 - 1.1 --- m4/wcwidth.m4 28 Jun 2006 16:52:52 - *** *** 1,17 ! # wcwidth.m4 serial 1 dnl Copyright (C) 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. - dnl autoconf tests required for use of mbswidth.c - AC_DEFUN([gl_FUNC_WCWIDTH], ! [