From gcc-patches-return-67562-listarch-gcc-patches=gcc dot gnu dot org at gcc dot gnu dot org Fri Sep 06 14:44:59 2002 Return-Path: Delivered-To: listarch-gcc-patches at gcc dot gnu dot org Received: (qmail 31503 invoked by alias); 6 Sep 2002 14:44:56 -0000 Mailing-List: contact gcc-patches-help at gcc dot gnu dot org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner at gcc dot gnu dot org Delivered-To: mailing list gcc-patches at gcc dot gnu dot org Received: (qmail 31479 invoked from network); 6 Sep 2002 14:44:52 -0000 Received: from unknown (HELO devserv.devel.redhat.com) (66.187.233.200) by sources dot redhat dot com with SMTP; 6 Sep 2002 14:44:52 -0000 Received: (from jakub@localhost) by devserv dot devel dot redhat dot com (8 dot 11 dot 6/8 dot 11 dot 0) id g86EioP06755; Fri, 6 Sep 2002 10:44:50 -0400 Date: Fri, 6 Sep 2002 10:44:50 -0400 From: Jakub Jelinek To: Benjamin Kosnik Cc: bkoz at nabi dot net, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org Subject: [PATCH] Fix libstdc++ usage of __ctype_b/__ctype_to* (take 2) Message-ID: <20020906104449.C7920@devserv.devel.redhat.com> Reply-To: Jakub Jelinek References: <20020901040933.I7886@dhcp187.sf.frob.com> <20020901095711.C7920@devserv.devel.redhat.com> <20020901102055.A5791@devserv.devel.redhat.com> <3D724B9A.6050908@redhat.com> <20020901145657.E7920@devserv.devel.redhat.com> <3D726A72.2080106@redhat.com> <20020901165440.F7920@devserv.devel.redhat.com> <20020904160557.7dbc29f6.bkoz@nabi.net> <20020905041710.P7920@devserv.devel.redhat.com> <20020905103148.7c1381a2.bkoz@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20020905103148 dot 7c1381a2 dot bkoz at redhat dot com>; from bkoz at redhat dot com on Thu, Sep 05, 2002 at 10:31:48AM -0500 On Thu, Sep 05, 2002 at 10:31:48AM -0500, Benjamin Kosnik wrote: > > Most probably yes, but as it is a static method I wanted to be sure. > > Should I leave it in? > > Sure. > > > Just remove all this _GLIBCPP_USE_SHADOW_HEADERS cruft. > > > > You mean the using lines too? > > Yep. > > BTW: This will have the effect that --enable-clocale=generic will no longer > > work with glibc 2.3+. Although for everything but checking the generic > > clocale gnu it makes no sense to use anything but --enable-clocale=gnu > > with glibc 2.3+, we might as well consider using: > > > > #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) > > __ret = *__ctype_b_loc(); > > #else > > __ret = __ctype_b; > > #endif > > here (and similarly with __ctype_tolower and __ctype_toupper). > > Sounds good. Ok, here is an updated version of the patch. Ok to commit (head, branch)? 2002-09-06 Jakub Jelinek * config/os/gnu-linux/bits/ctype_noninline.h [_GLIBCPP_USE_SHADOW_HEADERS]: Remove using _C_legacy::__ctype_*. (ctype::classic_table): If _GLIBCPP_C_LOCALE_GNU, return _S_c_locale->__ctype_b, otherwise temporarily switch to "C" locale and return __ctype_b. (ctype::ctype(__c_locale, const mask*, bool, size_t)): If not _GLIBCPP_C_LOCALE_GNU, temporarily switch to "C" locale and initialize using __ctype_{b,tolower,toupper}. (ctype::ctype(const mask*, bool, size_t)): If _GLIBCPP_C_LOCALE_GNU, initialize using _S_c_locale->__ctype_{b,tolower,toupper}, otherwise temporarily switch to "C" locale and initialize using __ctype_{b,tolower,toupper}. --- libstdc++-v3/config/os/gnu-linux/bits/ctype_noninline.h.jj 2002-09-03 11:54:25.000000000 +0200 +++ libstdc++-v3/config/os/gnu-linux/bits/ctype_noninline.h 2002-09-06 10:34:59.000000000 +0200 @@ -34,16 +34,32 @@ // Information as gleaned from /usr/include/ctype.h -#if _GLIBCPP_USE_SHADOW_HEADERS - using _C_legacy::__ctype_toupper; - using _C_legacy::__ctype_tolower; - using _C_legacy::__ctype_b; -#endif - +#if _GLIBCPP_C_LOCALE_GNU const ctype_base::mask* ctype::classic_table() throw() - { return __ctype_b; } - + { + if (!_S_c_locale) + _S_create_c_locale(_S_c_locale, "C"); + return _S_c_locale->__ctype_b; + } +#else + const ctype_base::mask* + ctype::classic_table() throw() + { + const ctype_base::mask* __ret; + char* __old = strdup(setlocale(LC_CTYPE, NULL)); + setlocale(LC_CTYPE, "C"); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + __ret = *__ctype_b_loc(); +#else + __ret = __ctype_b; +#endif + setlocale(LC_CTYPE, __old); + free(__old); + return __ret; + } +#endif + #if _GLIBCPP_C_LOCALE_GNU ctype::ctype(__c_locale __cloc, const mask* __table, bool __del, size_t __refs) @@ -57,17 +73,55 @@ #else ctype::ctype(__c_locale, const mask* __table, bool __del, size_t __refs) - : __ctype_abstract_base(__refs), _M_del(__table != 0 && __del), - _M_toupper(__ctype_toupper), _M_tolower(__ctype_tolower), - _M_table(__table ? __table : classic_table()) - { _M_c_locale_ctype = _S_c_locale; } + : __ctype_abstract_base(__refs), _M_del(__table != 0 && __del) + { + char* __old=strdup(setlocale(LC_CTYPE, NULL)); + setlocale(LC_CTYPE, "C"); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + _M_toupper = *__ctype_toupper_loc(); + _M_tolower = *__ctype_tolower_loc(); + _M_table = __table ? __table : *__ctype_b_loc(); +#else + _M_toupper = __ctype_toupper; + _M_tolower = __ctype_tolower; + _M_table = __table ? __table : __ctype_b; +#endif + setlocale(LC_CTYPE, __old); + free(__old); + _M_c_locale_ctype = _S_c_locale; + } #endif +#if _GLIBCPP_C_LOCALE_GNU ctype::ctype(const mask* __table, bool __del, size_t __refs) : - __ctype_abstract_base(__refs), _M_del(__table != 0 && __del), - _M_toupper(__ctype_toupper), _M_tolower(__ctype_tolower), - _M_table(__table ? __table : classic_table()) - { _M_c_locale_ctype = _S_c_locale; } + __ctype_abstract_base(__refs), _M_del(__table != 0 && __del) + { + _M_c_locale_ctype = _S_c_locale; + _M_toupper = _M_c_locale_ctype->__ctype_toupper; + _M_tolower = _M_c_locale_ctype->__ctype_tolower; + _M_table = __table ? __table : _M_c_locale_ctype->__ctype_b; + } +#else + ctype::ctype(__c_locale, const mask* __table, bool __del, + size_t __refs) + : __ctype_abstract_base(__refs), _M_del(__table != 0 && __del) + { + char* __old=strdup(setlocale(LC_CTYPE, NULL)); + setlocale(LC_CTYPE, "C"); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + _M_toupper = *__ctype_toupper_loc(); + _M_tolower = *__ctype_tolower_loc(); + _M_table = __table ? __table : *__ctype_b_loc(); +#else + _M_toupper = __ctype_toupper; + _M_tolower = __ctype_tolower; + _M_table = __table ? __table : __ctype_b; +#endif + setlocale(LC_CTYPE, __old); + free(__old); + _M_c_locale_ctype = _S_c_locale; + } +#endif char ctype::do_toupper(char __c) const Jakub