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

[patches] First hack at OPTION_POSIX_WIDE_CHAR_DEVICE_IO



I wanted to get at least something going here, so here's a rough cut
at one of the wide character support option groups.  To be done:

- I still need to work out which tests must be disabled when this
  option group is gone.

- GLIBC has a few functions for reporting errors which check whether
  stderr is wide-oriented or byte-oriented, and then apply the
  appropriate functions.  At the moment, the present patch simply
  makes GLIBC abort if the option group is disabled and stderr is
  caught being wide-oriented.  Since the functions to read or write
  wide characters to stderr are gone, those shouldn't be making it
  wide-oriented.  However, there is still the fwide function to be
  dealt with.

ChangeLog.eglibc:
2007-10-07  Jim Blandy  <jimb@xxxxxxxxxxxxxxxx>

	First cut at a POSIX_WIDE_CHAR_DEVICE_IO option group.
	* option-groups.def (OPTION_POSIX_WIDE_CHAR_DEVICE_IO): New entry.
	* option-groups.defaults (OPTION_POSIX_WIDE_CHAR_DEVICE_IO):
	Initialize.
	* libio/Makefile: Include ../option-groups.mak.
	(routines): Put in the group: fputwc, fputwc_u, getwc, getwc_u,
	getwchar, getwchar_u, iofgetws, iofgetws_u, iofputws, iofputws_u,
	iogetwline, ioungetwc, putwc, putwc_u, putwchar, putwchar_u,
	fwprintf, swprintf, vwprintf, wprintf, wscanf, fwscanf, vwscanf,
	vswprintf, iovswscanf, and swscanf.
	(tests): Put in the group: tst_swprintf, tst_wprintf, tst_swscanf,
	tst_wscanf, tst_getwc, tst_putwc, tst_wprintf2, and tst-widetext.
	* stdio-common/Makefile: (routines): Put vfwprintf and vfwscanf in
	the group.
	(CFLAGS-fxprintf.c): Define OPTION_POSIX_WIDE_CHAR_DEVICE_IO as
	appropriate.
	* stdio-common/fxprintf.c (__fxprintf): Support the wide character
	case only if OPTION_POSIX_WIDE_CHAR_DEVICE_IO is #defined.
	* misc/Makefile (CFLAGS-error.c, CFLAGS-err.c): Define
	OPTION_POSIX_WIDE_CHAR_DEVICE_IO as appropriate.
	* misc/err.c (convert_and_print): Define only if
	OPTION_POSIX_WIDE_CHAR_DEVICE_IO is #defined.
	(vwarnx, vwarn): Support the wide character case only if
	OPTION_POSIX_WIDE_CHAR_DEVICE_IO is #defined.
	* misc/error.c (error_tail): Same.
	* argp/Makefile (CFLAGS-argp-help.c, CFLAGS-argp-fmtstream.c):
	Define OPTION_POSIX_WIDE_CHAR_DEVICE_IO as appropriate.
	(__argp_failure): Support the wide character case only if
	OPTION_POSIX_WIDE_CHAR_DEVICE_IO is #defined.
	* wcsmbs/Makefile (routines): Put isoc99_wscanf, isoc99_vwscanf,
	isoc99_fwscanf, isoc99_vfwscanf, isoc99_swscanf, and
	isoc99_vswscanf in the group.
	* debug/Makefile (routines): Put swprintf_chk, vswprintf_chk,
	wprintf_chk, fwprintf_chk, vwprintf_chk, vfwprintf_chk,
	fgetws_chk, and fgetws_u_chk in the group.

Index: debug/Makefile
===================================================================
--- debug/Makefile	(revision 3736)
+++ debug/Makefile	(working copy)
@@ -38,8 +38,6 @@
 	    wctomb_chk wcscpy_chk wmemcpy_chk wmemmove_chk wmempcpy_chk \
 	    wcpcpy_chk wcsncpy_chk wcscat_chk wcsncat_chk wmemset_chk \
 	    wcpncpy_chk \
-	    swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \
-	    vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \
 	    confstr_chk getgroups_chk ttyname_r_chk \
 	    gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \
 	    wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk mbstowcs_chk \
@@ -48,6 +46,10 @@
 	    $(static-only-routines)
 routines-$(OPTION_EGLIBC_GETLOGIN) += getlogin_r_chk
 routines-$(OPTION_EGLIBC_BACKTRACE) += backtrace backtracesyms backtracesymsfd 
+routines-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO)			\
+	 += swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk	\
+	    vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk
+
 static-only-routines := warning-nop stack_chk_fail_local
 
 CFLAGS-backtrace.c = -fno-omit-frame-pointer
Index: wcsmbs/Makefile
===================================================================
--- wcsmbs/Makefile	(revision 3736)
+++ wcsmbs/Makefile	(working copy)
@@ -40,8 +40,9 @@
 	    wcwidth wcswidth \
 	    wcscoll_l wcsxfrm_l \
 	    wcscasecmp wcsncase wcscasecmp_l wcsncase_l \
-	    wcsmbsload mbsrtowcs_l \
-	    isoc99_wscanf isoc99_vwscanf isoc99_fwscanf isoc99_vfwscanf \
+	    wcsmbsload mbsrtowcs_l
+routines-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO)				\
+	 += isoc99_wscanf isoc99_vwscanf isoc99_fwscanf isoc99_vfwscanf	\
 	    isoc99_swscanf isoc99_vswscanf
 
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen \
Index: libio/Makefile
===================================================================
--- libio/Makefile	(revision 3736)
+++ libio/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Specific makefile for libio.
 #
+include ../option-groups.mak
+
 subdir	:= libio
 
 headers	:= stdio.h libio.h _G_config.h bits/stdio.h bits/stdio-lock.h \
@@ -31,10 +33,9 @@
 	ioseekoff ioseekpos iosetbuffer iosetvbuf ioungetc		      \
 	iovsprintf iovsscanf						      \
 	iofgetpos64 iofopen64 iofsetpos64				      \
-	fputwc fputwc_u getwc getwc_u getwchar getwchar_u iofgetws iofgetws_u \
-	iofputws iofputws_u iogetwline iowpadn ioungetwc putwc putwc_u	      \
-	putwchar putwchar_u putchar putchar_u fwprintf swprintf vwprintf      \
-	wprintf wscanf fwscanf vwscanf vswprintf iovswscanf swscanf wgenops   \
+	iowpadn								      \
+	putchar putchar_u						      \
+	wgenops								      \
 	wstrops wfileops iofwide fwide wmemstream			      \
 									      \
 	clearerr feof ferror fileno fputc freopen fseek getc getchar	      \
@@ -46,9 +47,13 @@
 	__fpurge __fpending __fsetlocking				      \
 									      \
 	libc_fatal fmemopen
+routines-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO) +=                               \
+	fputwc fputwc_u getwc getwc_u getwchar getwchar_u iofgetws iofgetws_u \
+	iofputws iofputws_u iogetwline ioungetwc putwc putwc_u                \
+	putwchar putwchar_u fwprintf swprintf vwprintf                        \
+	wprintf wscanf fwscanf vwscanf vswprintf iovswscanf swscanf 
 
-tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc   \
-	tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc	      \
+tests = test-fmemopen tst-ext tst-fopenloc	      \
 	tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-sscanf	      \
 	tst-mmap-setvbuf bug-ungetwc1 bug-ungetwc2 tst-atime tst-eof          \
 	tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \
@@ -61,6 +66,9 @@
 	tst-setvbuf1
 tests-$(OPTION_EGLIBC_LOCALE_CODE) \
      += tst-swscanf
+tests-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO) \
+     += tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc   \
+	tst_wprintf2 tst-widetext 
 test-srcs = test-freopen
 
 all: # Make this the default target; it will be defined in Rules.
Index: misc/err.c
===================================================================
--- misc/err.c	(revision 3736)
+++ misc/err.c	(working copy)
@@ -41,6 +41,7 @@
 }
 
 #ifdef USE_IN_LIBIO
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
 static void
 convert_and_print (const char *format, __gnuc_va_list ap)
 {
@@ -86,6 +87,7 @@
   __vfwprintf (stderr, wformat, ap);
 }
 #endif
+#endif
 
 void
 vwarnx (const char *format, __gnuc_va_list ap)
@@ -94,9 +96,13 @@
 #ifdef USE_IN_LIBIO
   if (_IO_fwide (stderr, 0) > 0)
     {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
       __fwprintf (stderr, L"%s: ", __progname);
       convert_and_print (format, ap);
       putwc_unlocked (L'\n', stderr);
+#else
+      abort ();
+#endif
     }
   else
 #endif
@@ -119,6 +125,7 @@
 #ifdef USE_IN_LIBIO
   if (_IO_fwide (stderr, 0) > 0)
     {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
       __fwprintf (stderr, L"%s: ", __progname);
       if (format)
 	{
@@ -127,6 +134,9 @@
 	}
       __set_errno (error);
       __fwprintf (stderr, L"%m\n");
+#else
+      abort ();
+#endif
     }
   else
 #endif
Index: misc/error.c
===================================================================
--- misc/error.c	(revision 3736)
+++ misc/error.c	(working copy)
@@ -131,6 +131,7 @@
 #if _LIBC
   if (_IO_fwide (stderr, 0) > 0)
     {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
 # define ALLOCA_LIMIT 2000
       size_t len = strlen (message) + 1;
       wchar_t *wmessage = NULL;
@@ -192,6 +193,9 @@
 
       if (use_malloc)
 	free (wmessage);
+#else
+      abort ();
+#endif
     }
   else
 #endif
Index: misc/Makefile
===================================================================
--- misc/Makefile	(revision 3736)
+++ misc/Makefile	(working copy)
@@ -91,6 +91,9 @@
 tests: $(objpfx)tst-error1-mem
 # eglibc: endif
 
+OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO) \
+	= -DOPTION_POSIX_WIDE_CHAR_DEVICE_IO
+
 CFLAGS-tsearch.c = $(uses-callbacks)
 CFLAGS-lsearch.c = $(uses-callbacks)
 CFLAGS-pselect.c = -fexceptions
@@ -98,13 +101,13 @@
 CFLAGS-writev.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-usleep.c = -fexceptions
 CFLAGS-syslog.c = -fexceptions
-CFLAGS-error.c = -fexceptions
+CFLAGS-error.c = -fexceptions $(OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-y)
 CFLAGS-getpass.c = -fexceptions
 CFLAGS-mkstemp.c = -fexceptions
 CFLAGS-mkstemp64.c = -fexceptions
 CFLAGS-getsysstats.c = -fexceptions
 CFLAGS-getusershell.c = -fexceptions
-CFLAGS-err.c = -fexceptions
+CFLAGS-err.c = -fexceptions $(OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-y)
 CFLAGS-tst-tsearch.c = $(stack-align-test-flags)
 CFLAGS-mntent_r.c = -D_IO_MTSAFE_IO
 
Index: argp/argp-help.c
===================================================================
--- argp/argp-help.c	(revision 3736)
+++ argp/argp-help.c	(working copy)
@@ -1876,7 +1876,13 @@
 
 #ifdef USE_IN_LIBIO
 	  if (_IO_fwide (stream, 0) > 0)
-	    putwc_unlocked (L'\n', stream);
+            {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
+              putwc_unlocked (L'\n', stream);
+#else
+              abort ();
+#endif
+            }
 	  else
 #endif
 	    putc_unlocked ('\n', stream);
Index: argp/argp-fmtstream.c
===================================================================
--- argp/argp-fmtstream.c	(revision 3736)
+++ argp/argp-fmtstream.c	(working copy)
@@ -152,7 +152,13 @@
 		{
 #ifdef USE_IN_LIBIO
 		  if (_IO_fwide (fs->stream, 0) > 0)
-		    putwc_unlocked (L' ', fs->stream);
+                    {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
+                      putwc_unlocked (L' ', fs->stream);
+#else
+                      abort ();
+#endif
+                    }
 		  else
 #endif
 		    putc_unlocked (' ', fs->stream);
@@ -317,7 +323,13 @@
 	    for (i = 0; i < fs->wmargin; ++i)
 #ifdef USE_IN_LIBIO
 	      if (_IO_fwide (fs->stream, 0) > 0)
-		putwc_unlocked (L' ', fs->stream);
+                {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
+                  putwc_unlocked (L' ', fs->stream);
+#else
+                  abort ();
+#endif
+                }
 	      else
 #endif
 		putc_unlocked (' ', fs->stream);
Index: argp/Makefile
===================================================================
--- argp/Makefile	(revision 3736)
+++ argp/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Makefile for argp.
 #
+include ../option-groups.mak
+
 subdir	:= argp
 
 headers		= argp.h
@@ -28,9 +30,13 @@
 
 tests		= argp-test tst-argp1 bug-argp1 tst-argp2
 
-CFLAGS-argp-help.c = $(uses-callbacks) -fexceptions
+OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO) \
+	= -DOPTION_POSIX_WIDE_CHAR_DEVICE_IO
+
+CFLAGS-argp-help.c = $(uses-callbacks) -fexceptions \
+	             $(OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-y)
 CFLAGS-argp-parse.c = $(uses-callbacks)
-CFLAGS-argp-fmtstream.c = -fexceptions
+CFLAGS-argp-fmtstream.c = -fexceptions $(OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-y)
 
 bug-argp1-ARGS = -- --help
 
Index: option-groups.defaults
===================================================================
--- option-groups.defaults	(revision 3736)
+++ option-groups.defaults	(working copy)
@@ -30,4 +30,6 @@
 OPTION_EGLIBC_UTMP = y
 OPTION_EGLIBC_UTMPX = y
 OPTION_EGLIBC_WORDEXP = y
+OPTION_POSIX_C_LANG_WIDE_CHAR = y
 OPTION_POSIX_REGEXP = y
+OPTION_POSIX_WIDE_CHAR_DEVICE_IO = y
Index: option-groups.def
===================================================================
--- option-groups.def	(revision 3736)
+++ option-groups.def	(working copy)
@@ -652,6 +652,29 @@
         <regexp.h> header file, 'compile', 'step', and 'advance', is
         omitted.
 
+config OPTION_POSIX_WIDE_CHAR_DEVICE_IO
+    bool "Input and output functions for wide characters"
+    help
+        This option group includes functions for reading and writing
+        wide characters to and from <stdio.h> streams.
+
+        This option group includes the following functions:
+
+          fgetwc        fwprintf      putwchar      vwscanf
+          fgetws        fwscanf       ungetwc       wprintf
+          fputwc        getwc         vfwprintf     wscanf
+          fputws        getwchar      vfwscanf
+          fwide         putwc         vwprintf
+
+        This option group further includes the following unlocked
+        variants of the above functions:
+
+          fgetwc_unlocked           getwc_unlocked
+          fgetws_unlocked           getwchar_unlocked
+          fputwc_unlocked           putwc_unlocked
+          fputws_unlocked           putwchar_unlocked
+                    
+
 
 # This helps Emacs users browse this file using the page motion commands
 # and commands like 'pages-directory'.
Index: stdio-common/Makefile
===================================================================
--- stdio-common/Makefile	(revision 3736)
+++ stdio-common/Makefile	(working copy)
@@ -30,7 +30,7 @@
 	_itoa _itowa itoa-digits itoa-udigits itowa-digits		      \
 	vfprintf vprintf printf_fp reg-printf printf-prs printf_fphex	      \
 	printf_size fprintf printf snprintf sprintf asprintf dprintf	      \
-	vfwprintf vfscanf vfwscanf					      \
+	vfscanf								      \
 	fscanf scanf sscanf						      \
 	perror psignal							      \
 	tmpfile tmpfile64 tmpnam tmpnam_r tempnam tempname		      \
@@ -39,6 +39,8 @@
 	flockfile ftrylockfile funlockfile				      \
 	isoc99_scanf isoc99_vscanf isoc99_fscanf isoc99_vfscanf isoc99_sscanf \
 	isoc99_vsscanf
+routines-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO) +=	\
+	vfwprintf vfwscanf
 
 include ../Makeconfig
 
@@ -85,6 +87,8 @@
 
 OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
 	= -DOPTION_EGLIBC_LOCALE_CODE
+OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-$(OPTION_POSIX_WIDE_CHAR_DEVICE_IO) \
+	= -DOPTION_POSIX_WIDE_CHAR_DEVICE_IO
 
 CFLAGS-vfprintf.c = -Wno-uninitialized
 CFLAGS-vfwprintf.c = -Wno-uninitialized
@@ -95,6 +99,7 @@
 CFLAGS-tst-printfsz.c = -Wno-format
 CFLAGS-printf_fp.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
 CFLAGS-printf_fphex.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+CFLAGS-fxprintf.c = $(OPTION_POSIX_WIDE_CHAR_DEVICE_IO-CFLAGS-y)
 
 CFLAGS-tmpfile.c = -fexceptions
 CFLAGS-tmpfile64.c = -fexceptions
Index: stdio-common/fxprintf.c
===================================================================
--- stdio-common/fxprintf.c	(revision 3736)
+++ stdio-common/fxprintf.c	(working copy)
@@ -38,6 +38,7 @@
   int res;
   if (_IO_fwide (fp, 0) > 0)
     {
+#ifdef OPTION_POSIX_WIDE_CHAR_DEVICE_IO
       size_t len = strlen (fmt) + 1;
       wchar_t wfmt[len];
       for (size_t i = 0; i < len; ++i)
@@ -46,6 +47,9 @@
 	  wfmt[i] = fmt[i];
 	}
       res = __vfwprintf (fp, wfmt, ap);
+#else
+      abort();
+#endif
     }
   else
     res = INTUSE(_IO_vfprintf) (fp, fmt, ap);