This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

V3 PATCH: Allow for systems without wide-character support



IRIX fails the test that enables _GLIBCPP_USE_WCHAR_T because it
doesn't define wmemmove and friends.

Here's the patch to allow that.  It's pretty simple, really -- just
conditionally compile out the bits that aren't needed.  A lot of this
was already being done, but a few places got missed.

The only change here that's not of this nature is that _IO_fwide hit a
`#error' for the cas wheren _GLIBCPP_USE_WCHAR_T isn't defined.  I
made _IO_fwide simply not change the mode on the stream when the user
tries to set the stream to wide-character mode.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-10-29  Mark Mitchell  <mark@codesourcery.com>

	* config/c_io_libio.cc (basic_file<char>::__basic_file): 
	Don't pass a NULL _IO_wide_data to _IO_no_init when
	_GLIBCPP_USE_WCHAR_T is not defined.
	* config/c_io_libio.h (_IO_codecvt): Don't declare when 
	_GLIBCPP_USE_WCHAR_T is not defined.
	* config/c_io_libio_codecvt.c: Don't compile it 
	when _GLIBCPP_USE_WCHAR_T is not defined.
	* include/bits/codecvt.h (codecvt<_InternT, _ExternT, __enc_traits):
	Don't define this specialization when _GLIBCPP_USE_WCHAR_T 
	is not defined.
	* include/bits/locale_facets.h (<bits/std_cwctype.h>): Don't
	include it when _GLIBCPP_USE_WCHAR_T is not defined. 
	* src/codecvt.cc (__enc_traits::_S_max_size): Don't define
	when _GLIBCPP_USE_WCHAR_T is not defined.
	* src/localename.cc (locale::_Impl::_M_construct_collate):
	Don't call wide-character functions when _GLIBCPP_USE_WCHAR_T is 
	not defined.
	(locale::_Impl::_M_construct_ctype): Likewise.
	(locale::_Impl::_M_construct_monetary): Likewise.
	(locale::_Impl::_M_construct_numeric): Likewise.
	(locale::_Impl::_M_construct_time): Likewise.
	(locale::_Impl::_M_construct_messages): Likewise.

2000-10-29  Mark Mitchell  <mark@codesourcery.com>

	* iofopen.c (_IO_new_fopen): Don't define `_IO_wide_data wd'
	if _GLIBCPP_USE_WCHAR_T is not defined.
	* iofwide.c: Don't define codecvt functions when 
	_GLIBCPP_USE_WCHAR_T is not defined.
	(_IO_fwide): Don't try to put the stream in wide mode when
	_GLIBCPP_USE_WCHAR_T is not defined.
	* libio.h (_IO_wide_data): Define it as an incomplete struct
	when _GLIBCPP_USE_WCHAR_T is not defined.
	* wfiledoalloc.c: Don't define anything when 
	_GLIBCPP_USE_WCHAR_T is not defined.
	* wfileops.c: Likewise.
	* wgenops.c: Likewise.

Index: config/c_io_libio.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/c_io_libio.cc,v
retrieving revision 1.11
diff -c -p -r1.11 c_io_libio.cc
*** c_io_libio.cc	2000/10/04 05:06:31	1.11
--- c_io_libio.cc	2000/10/29 21:51:05
*************** namespace std {
*** 204,210 ****
--- 204,214 ----
      _lock = __lock;
  #endif
      // Don't set the orientation of the stream when initializing.
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _IO_no_init(this, 0, 0, &_M_wfile, 0);
+ #else /* !defined(_GLIBCPP_USE_WCHAR_T) */
+     _IO_no_init(this, 0, 0, NULL, 0);
+ #endif /* !defined(_GLIBCPP_USE_WCHAR_T) */
      _IO_JUMPS((_IO_FILE_plus *) this) = &_IO_file_jumps;
      _IO_file_init((_IO_FILE_plus*)this);
    }
Index: config/c_io_libio.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/c_io_libio.h,v
retrieving revision 1.5
diff -c -p -r1.5 c_io_libio.h
*** c_io_libio.h	2000/10/25 12:50:05	1.5
--- c_io_libio.h	2000/10/29 21:51:05
*************** namespace std {
*** 62,68 ****
--- 62,70 ----
    typedef _IO_FILE 	__c_file_type;
    typedef _IO_wide_data __c_wfile_type;
  
+ #ifdef _GLIBCPP_USE_WCHAR_T
    extern "C" _IO_codecvt __c_libio_codecvt;
+ #endif /* defined (_GLIBCPP_USE_WCHAR_T) */
  
  // from ios_base.h
    struct __ios_flags
Index: config/c_io_libio_codecvt.c
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/c_io_libio_codecvt.c,v
retrieving revision 1.2
diff -c -p -r1.2 c_io_libio_codecvt.c
*** c_io_libio_codecvt.c	2000/10/25 16:54:47	1.2
--- c_io_libio_codecvt.c	2000/10/29 21:51:05
***************
*** 27,32 ****
--- 27,33 ----
  
  #include <libio.h>
  
+ #ifdef _GLIBCPP_USE_WCHAR_T
  
  /* Prototypes of libio's codecvt functions.  */
  static enum __codecvt_result 
*************** do_length(struct _IO_codecvt *codecvt, _
*** 148,150 ****
--- 149,153 ----
  static int
  do_max_length(struct _IO_codecvt *codecvt)
  { return 1; }
+ 
+ #endif /* _GLIBCPP_USE_WCHAR_T */
Index: include/bits/codecvt.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/codecvt.h,v
retrieving revision 1.2
diff -c -p -r1.2 codecvt.h
*** codecvt.h	2000/10/20 06:51:59	1.2
--- codecvt.h	2000/10/29 21:51:06
*************** namespace std
*** 303,308 ****
--- 303,309 ----
    template<typename _InternT, typename _ExternT, typename _StateT>
      locale::id codecvt<_InternT, _ExternT, _StateT>::id;
  
+ #ifdef _GLIBCPP_USE_WCHAR_T
    // partial specialization
    // This specialization takes advantage of iconv to provide code
    // conversions between a large number of character encodings.
*************** namespace std
*** 567,572 ****
--- 568,574 ----
      do_max_length() const throw()
      { return 1; }
  #endif
+ #endif /* _GLIBCPP_USE_WCHAR_T */
  
    // codecvt<char, char, mbstate_t> required specialization
    template<>
Index: include/bits/locale_facets.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/locale_facets.h,v
retrieving revision 1.4
diff -c -p -r1.4 locale_facets.h
*** locale_facets.h	2000/10/18 23:26:22	1.4
--- locale_facets.h	2000/10/29 21:51:06
***************
*** 39,45 ****
--- 39,47 ----
  #include <bits/std_ctime.h>	// For struct tm
  #include <typeinfo> 		// For bad_cast, which shouldn't be here.
  #include <bits/std_ios.h>	// For ios_base
+ #ifdef _GLIBCPP_USE_WCHAR_T
  #include <bits/std_cwctype.h>	// For wctype_t
+ #endif /* _GLIBCPP_USE_WCHAR_T */
  
  namespace std
  {
Index: libio/iofopen.c
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/iofopen.c,v
retrieving revision 1.2
diff -c -p -r1.2 iofopen.c
*** iofopen.c	2000/08/15 07:32:59	1.2
--- iofopen.c	2000/10/29 21:51:09
*************** _IO_new_fopen (filename, mode)
*** 44,50 ****
--- 44,52 ----
  #ifdef _IO_MTSAFE_IO
      _IO_lock_t lock;
  #endif
+ #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
      struct _IO_wide_data wd;
+ #endif /* !(defined _LIBC || defined _GLIBCPP_USE_WCHAR_T) */
    } *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
  
    if (new_f == NULL)
Index: libio/iofwide.c
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/iofwide.c,v
retrieving revision 1.7
diff -c -p -r1.7 iofwide.c
*** iofwide.c	2000/10/25 16:54:47	1.7
--- iofwide.c	2000/10/29 21:51:09
***************
*** 38,44 ****
  # include <langinfo.h>
  #endif
  
! 
  /* Prototypes of libio's codecvt functions.  */
  static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
  				     __c_mbstate_t *statep,
--- 38,44 ----
  # include <langinfo.h>
  #endif
  
! #ifdef _GLIBCPP_USE_WCHAR_T
  /* Prototypes of libio's codecvt functions.  */
  static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
  				     __c_mbstate_t *statep,
*************** static struct __gconv_trans_data libio_t
*** 83,89 ****
    .__trans_fct = __gconv_transliterate
  };
  #endif
! 
  
  /* Return orientation of stream.  If mode is nonzero try to change
     the orientation first.  */
--- 83,89 ----
    .__trans_fct = __gconv_transliterate
  };
  #endif
! #endif /* defined(GLIBCPP_USE_WCHAR_T) */
  
  /* Return orientation of stream.  If mode is nonzero try to change
     the orientation first.  */
*************** _IO_fwide (fp, mode)
*** 104,109 ****
--- 104,110 ----
    /* Set the orientation appropriately.  */
    if (mode > 0)
      {
+ #ifdef _GLIBCPP_USE_WCHAR_T
        struct _IO_codecvt *cc = fp->_codecvt;
  
        fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
*************** _IO_fwide (fp, mode)
*** 174,179 ****
--- 175,183 ----
  
        /* From now on use the wide character callback functions.  */
        ((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable;
+ #else /* !defined(_GLIBCPP_USE_WCHAR_T) */
+       mode = fp->_mode;
+ #endif /* !defined(_GLIBCPP_USE_WCHAR_T) */
      }
  
    /* Set the mode now.  */
*************** _IO_fwide (fp, mode)
*** 186,191 ****
--- 190,196 ----
  weak_alias (_IO_fwide, fwide)
  #endif
  
+ #ifdef _GLIBCPP_USE_WCHAR_T
  
  static enum __codecvt_result
  do_out (struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
*************** do_max_length (struct _IO_codecvt *codec
*** 467,469 ****
--- 472,476 ----
    return MB_CUR_MAX;
  #endif
  }
+ 
+ #endif /* defined(_GLIBCPP_USE_WCHAR_T) */
Index: libio/libio.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/libio.h,v
retrieving revision 1.10
diff -c -p -r1.10 libio.h
*** libio.h	2000/10/27 12:29:42	1.10
--- libio.h	2000/10/29 21:51:10
*************** struct _IO_wide_data
*** 254,260 ****
    struct _IO_jump_t *_wide_vtable;
  #endif
  };
! #endif
  
  struct _IO_FILE {
    int _flags;		/* High-order word is _IO_MAGIC; rest is flags. */
--- 254,266 ----
    struct _IO_jump_t *_wide_vtable;
  #endif
  };
! #else /* !(defined _LIBC || defined _GLIBCPP_USE_WCHAR_T) */
! /* Because _IO_no_init unconditionally takes a `_IO_wide_data*' as its
!    last parameter we must still define this type.  We intentionally
!    leave it incomplete to prevent any use of this type when we are not
!    supporting wide characters.  */
! struct _IO_wide_data;
! #endif /* !(defined _LIBC || defined _GLIBCPP_USE_WCHAR_T) */
  
  struct _IO_FILE {
    int _flags;		/* High-order word is _IO_MAGIC; rest is flags. */
Index: libio/wfiledoalloc.c
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/wfiledoalloc.c,v
retrieving revision 1.2
diff -c -p -r1.2 wfiledoalloc.c
*** wfiledoalloc.c	2000/08/01 07:44:11	1.2
--- wfiledoalloc.c	2000/10/29 21:51:10
***************
*** 46,51 ****
--- 46,52 ----
  # define _POSIX_SOURCE
  #endif
  #include "libioP.h"
+ #ifdef _GLIBCPP_USE_WCHAR_T
  #include <sys/types.h>
  #include <sys/stat.h>
  #ifdef __STDC__
*************** _IO_wfile_doallocate (fp)
*** 103,105 ****
--- 104,108 ----
      fp->_flags |= _IO_LINE_BUF;
    return 1;
  }
+ 
+ #endif /* _GLIBCPP_USE_WCHAR_T */
Index: libio/wfileops.c
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/wfileops.c,v
retrieving revision 1.4
diff -c -p -r1.4 wfileops.c
*** wfileops.c	2000/10/25 16:54:47	1.4
--- wfileops.c	2000/10/29 21:51:10
***************
*** 27,32 ****
--- 27,33 ----
  
  #include <assert.h>
  #include <libioP.h>
+ #ifdef _GLIBCPP_USE_WCHAR_T
  #include <wchar.h>
  #ifdef HAVE_GCONV_H
  #  include <gconv.h>
*************** struct _IO_jump_t _IO_wfile_jumps =
*** 749,751 ****
--- 750,754 ----
    JUMP_INIT(showmanyc, _IO_default_showmanyc),
    JUMP_INIT(imbue, _IO_default_imbue)
  };
+ 
+ #endif /* _GLIBCPP_USE_WCHAR_T */
Index: libio/wgenops.c
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/wgenops.c,v
retrieving revision 1.3
diff -c -p -r1.3 wgenops.c
*** wgenops.c	2000/08/15 07:33:00	1.3
--- wgenops.c	2000/10/29 21:51:10
***************
*** 28,33 ****
--- 28,34 ----
  /* Generic or default I/O operations. */
  
  #include "libioP.h"
+ #ifdef _GLIBCPP_USE_WCHAR_T
  #ifdef __STDC__
  #include <stdlib.h>
  #endif
*************** _IO_unsave_wmarkers (fp)
*** 751,753 ****
--- 752,756 ----
    if (_IO_have_backup (fp))
      _IO_free_wbackup_area (fp);
  }
+ 
+ #endif /* _GLIBCPP_USE_WCHAR_T */
Index: src/codecvt.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/codecvt.cc,v
retrieving revision 1.3
diff -c -p -r1.3 codecvt.cc
*** codecvt.cc	2000/09/01 08:56:58	1.3
--- codecvt.cc	2000/10/29 21:51:11
***************
*** 31,38 ****
--- 31,40 ----
  
  namespace std {
  
+ #ifdef _GLIBCPP_USE_WCHAR_T
    // Definitions for static const data members of __enc_traits.
    const int __enc_traits::_S_max_size;
+ #endif /* _GLIBCPP_USE_WCHAR_T */
  
    // codecvt<char, char, mbstate_t> required specialization
    locale::id codecvt<char, char, mbstate_t>::id;
Index: src/localename.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/localename.cc,v
retrieving revision 1.8
diff -c -p -r1.8 localename.cc
*** localename.cc	2000/10/20 06:52:00	1.8
--- localename.cc	2000/10/29 21:51:11
*************** namespace std {
*** 223,280 ****
--- 223,306 ----
    locale::_Impl::_M_construct_collate(const char* __name)
    {
      _M_facet_init(new collate_byname<char>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new collate_byname<wchar_t>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
    }
  
    void 
    locale::_Impl::_M_construct_ctype(const char* __name)
    {
      _M_facet_init(new ctype_byname<char>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new ctype_byname<wchar_t>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
      _M_facet_init(new codecvt_byname<char, char, mbstate_t>(__name));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new codecvt_byname<wchar_t, char, mbstate_t>(__name));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
    }
      
    void 
    locale::_Impl::_M_construct_monetary(const char* __name)
    {
      _M_facet_init(new moneypunct_byname<char, false>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new moneypunct_byname<wchar_t, false>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
      _M_facet_init(new moneypunct_byname<char, true >(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new moneypunct_byname<wchar_t, true >(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
  
      _M_replace_facet(locale::_S_classic, &money_get<char>::id);
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_replace_facet(locale::_S_classic, &money_get<wchar_t>::id);
+ #endif /* _GLIBCPP_USE_WCHAR_T */
      _M_replace_facet(locale::_S_classic, &money_put<char>::id);
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_replace_facet(locale::_S_classic, &money_put<wchar_t>::id);
+ #endif /* _GLIBCPP_USE_WCHAR_T */
    }
      
    void 
    locale::_Impl::_M_construct_numeric(const char* __name)
    {
      _M_facet_init(new numpunct_byname<char>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new numpunct_byname<wchar_t>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
  
      _M_replace_facet(locale::_S_classic, &num_get<char>::id);
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_replace_facet(locale::_S_classic, &num_get<wchar_t>::id);
+ #endif /* _GLIBCPP_USE_WCHAR_T */
      _M_replace_facet(locale::_S_classic, &num_put<char>::id);
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_replace_facet(locale::_S_classic, &num_put<wchar_t>::id);
+ #endif /* _GLIBCPP_USE_WCHAR_T */
    }
      
    void 
    locale::_Impl::_M_construct_time(const char* __name)
    {
      _M_facet_init(new time_get_byname<char>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new time_get_byname<wchar_t>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
      _M_facet_init(new time_put_byname<char>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new time_put_byname<wchar_t>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
    }
      
    void 
    locale::_Impl::_M_construct_messages(const char* __name)
    {
      _M_facet_init(new messages_byname<char>(__name, 0));
+ #ifdef _GLIBCPP_USE_WCHAR_T
      _M_facet_init(new messages_byname<wchar_t>(__name, 0));
+ #endif /* _GLIBCPP_USE_WCHAR_T */
    }
  }
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]