This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix libstdc++ usage of __ctype_b/__ctype_to*
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: bkoz at nabi dot net, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 5 Sep 2002 10:31:48 -0500
- Subject: Re: [PATCH] Fix libstdc++ usage of __ctype_b/__ctype_to*
- Organization: Red Hat / Chicago
- References: <20020901034451.G7886@dhcp187.sf.frob.com><20020901065254.B7920@devserv.devel.redhat.com><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>
> > > -#if _GLIBCPP_USE_SHADOW_HEADERS
> > > +#if _GLIBCPP_C_LOCALE_GNU
> > > + const ctype_base::mask*
> > > + ctype<char>::classic_table() throw()
> > > + {
> > > + if (!_S_c_locale)
> > > + _S_create_c_locale(_S_c_locale, "C");
> > > + return _S_c_locale->__ctype_b;
> > > + }
> > > +#else
> >
> > _S_c_locale should be created before this. I suppose this is safer.
>
> Most probably yes, but as it is a static method I wanted to be sure.
> Should I leave it in?
Sure.
> > > +# if _GLIBCPP_USE_SHADOW_HEADERS
> > > using _C_legacy::__ctype_toupper;
> > > using _C_legacy::__ctype_tolower;
> > > using _C_legacy::__ctype_b;
> > > -#endif
> >
> > Just remove all this _GLIBCPP_USE_SHADOW_HEADERS cruft.
>
> You mean the using lines too?
Yep.
> > > const ctype_base::mask*
> > > ctype<char>::classic_table() throw()
> > > - { return __ctype_b; }
> >
> > Why not just _S_c_locale->__ctype_b?
>
> Well, I use _S_c_locale->__ctype_b #ifdef _GLIBCPP_C_LOCALE_GNU,
> otherwise _S_c_locale is NULL (config/locale/generic/c_locale.cc has:
> void
> locale::facet::_S_create_c_locale(__c_locale& __cloc, const char*,
> __c_locale)
> { __cloc = NULL; }
> ) and it is a bad idea to dereference it...
Whoops. Right. This is ok then.
>
> >
> > > -
> > > + {
> > > + const ctype_base::mask* __ret;
> > > + char* __old = strdup(setlocale(LC_CTYPE, NULL));
> > > + setlocale(LC_CTYPE, "C");
> > > + __ret = __ctype_b;
>
> 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.
-benjamin