From: Phil Edwards Date: Sat, 11 Nov 2000 00:37:45 +0000 (+0000) Subject: codecvt.h (__iconv_adaptor): New adaptor function... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=585ddf9c47fb750de8713634a5e93ed4fe55814a;p=gcc.git codecvt.h (__iconv_adaptor): New adaptor function... 2000-11-10 Phil Edwards * include/bits/codecvt.h (__iconv_adaptor): New adaptor function, courtesy of Alexandre Oliva, to handle const/non-const signatures. (codecvt::do_out): Use. (codecvt::do_in): And here. From-SVN: r37379 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7f754db5dd0..be17c8e6ab0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2000-11-10 Phil Edwards + + * include/bits/codecvt.h (__iconv_adaptor): New adaptor function, + courtesy of Alexandre Oliva, to handle const/non-const signatures. + (codecvt::do_out): Use. + (codecvt::do_in): And here. + 2000-11-10 Gabriel Dos Reis * include/bits/cpp_type_traits.h: Fix typos. Adjust formatting. diff --git a/libstdc++-v3/include/bits/codecvt.h b/libstdc++-v3/include/bits/codecvt.h index 1c0d4137436..97fc015509c 100644 --- a/libstdc++-v3/include/bits/codecvt.h +++ b/libstdc++-v3/include/bits/codecvt.h @@ -372,6 +372,19 @@ namespace std locale::id codecvt<_InternT, _ExternT, __enc_traits>::id; + // This adaptor works around the signature problems of the second + // argument to iconv(): SUSv2 and others use 'const char**', but glibc 2.2 + // uses 'char**', which is what the standard is (apparently) due to use + // in the future. Using this adaptor, g++ will do the work for us. + template + inline size_t + __iconv_adaptor(size_t(*iconv_func)(iconv_t, _T, size_t *, char**, size_t*), + iconv_t cd, char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) + { + return iconv_func (cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft); + } + template codecvt_base::result codecvt<_InternT, _ExternT, __enc_traits>:: @@ -393,7 +406,7 @@ namespace std // Argument list for iconv specifies a byte sequence. Thus, // all to/from arrays must be brutally casted to char*. char* __cto = reinterpret_cast(__to); - const char* __cfrom; + char* __cfrom; size_t __conv; // Some encodings need a byte order marker as the first item @@ -408,14 +421,16 @@ namespace std intern_type __cfixed[__size + 1]; __cfixed[0] = static_cast(__int_bom); char_traits::copy(__cfixed + 1, __from, __size); - __cfrom = reinterpret_cast(__cfixed); - __conv = iconv(*__desc, &__cfrom, &__flen, &__cto, &__tlen); + __cfrom = reinterpret_cast(__cfixed); + __conv = __iconv_adaptor(iconv, *__desc, &__cfrom, + &__flen, &__cto, &__tlen); } else { intern_type* __cfixed = const_cast(__from); - __cfrom = reinterpret_cast(__cfixed); - __conv = iconv(*__desc, &__cfrom, &__flen, &__cto, &__tlen); + __cfrom = reinterpret_cast(__cfixed); + __conv = __iconv_adaptor(iconv, *__desc, &__cfrom, + &__flen, &__cto, &__tlen); } if (__conv != size_t(-1)) @@ -456,7 +471,8 @@ namespace std // Argument list for iconv specifies a byte sequence. Thus, // all to/from arrays must be brutally casted to char*. char* __cto = reinterpret_cast(__to); - size_t __conv = iconv(*__desc, NULL, NULL, &__cto, &__tlen); + size_t __conv = __iconv_adaptor(iconv,*__desc, NULL, NULL, + &__cto, &__tlen); if (__conv != size_t(-1)) { @@ -495,7 +511,7 @@ namespace std // Argument list for iconv specifies a byte sequence. Thus, // all to/from arrays must be brutally casted to char*. char* __cto = reinterpret_cast(__to); - const char* __cfrom; + char* __cfrom; size_t __conv; // Some encodings need a byte order marker as the first item @@ -510,14 +526,16 @@ namespace std extern_type __cfixed[__size + 1]; __cfixed[0] = static_cast(__ext_bom); char_traits::copy(__cfixed + 1, __from, __size); - __cfrom = reinterpret_cast(__cfixed); - __conv = iconv(*__desc, &__cfrom, &__flen, &__cto, &__tlen); + __cfrom = reinterpret_cast(__cfixed); + __conv = __iconv_adaptor(iconv, *__desc, &__cfrom, + &__flen, &__cto, &__tlen); } else { extern_type* __cfixed = const_cast(__from); - __cfrom = reinterpret_cast(__cfixed); - __conv = iconv(*__desc, &__cfrom, &__flen, &__cto, &__tlen); + __cfrom = reinterpret_cast(__cfixed); + __conv = __iconv_adaptor(iconv, *__desc, &__cfrom, + &__flen, &__cto, &__tlen); }