Fair enough. It looks like the codecvt_utf16<wchar_t, *> cases need similar fixes too, but I don't have a Windows machine to test that on.
I'm actually interested though in looking into whether the wchar_t specializations can be made to automatically forward to the char16_t/char32_t specialization as appropriate (eg, by inheriting from them and wrapping appropriately). Should shrink the shared library a bit if fewer full specializations are needed. On Mon, Jul 8, 2013 at 12:41 PM, Howard Hinnant <[email protected]> wrote: > Not really. This code was donated anonymously to me for Windows support. I > checked it over to make sure it did not impact any other platforms, did a few > quick tests, and moved on. I should have posted the patch here for review > first. I'll do that next time. Any suggestions for bettering the Windows > port (or anything else for that matter) are more than welcome. > > Howard > > On Jul 8, 2013, at 3:34 PM, Matthew Dempsky <[email protected]> wrote: > >> Out of curiosity, is there any rationale for using preprocessor checks >> like this rather than (eg) templates that have separate >> specializations for sizeof(wchar_t) == sizeof(uint16_t) and >> sizeof(wchar_t) == sizeof(uint32_t)? >> >> Something like: >> >> template <size_t = sizeof(wchar_t)> struct wcharcvt_traits; >> >> template <> >> struct wcharcvt_traits<sizeof(uint16_t)> { >> typedef uint16_t uinttype; >> static constexpr auto to_utf8 = ucs2_to_utf8; >> static constexpr auto from_utf8 = utf8_to_ucs2; >> }; >> >> On Mon, Jul 8, 2013 at 12:03 PM, Howard Hinnant <[email protected]> wrote: >>> Author: hhinnant >>> Date: Mon Jul 8 14:03:07 2013 >>> New Revision: 185849 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=185849&view=rev >>> Log: >>> Windows port for __codecvt_utf8<wchar_t>. >>> >>> Modified: >>> libcxx/trunk/src/locale.cpp >>> >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp >>> >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp >>> >>> Modified: libcxx/trunk/src/locale.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=185849&r1=185848&r2=185849&view=diff >>> ============================================================================== >>> --- libcxx/trunk/src/locale.cpp (original) >>> +++ libcxx/trunk/src/locale.cpp Mon Jul 8 14:03:07 2013 >>> @@ -3201,14 +3201,25 @@ __codecvt_utf8<wchar_t>::do_out(state_ty >>> const intern_type* frm, const intern_type* frm_end, const intern_type*& >>> frm_nxt, >>> extern_type* to, extern_type* to_end, extern_type*& to_nxt) const >>> { >>> +#if _WIN32 >>> + const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm); >>> + const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end); >>> + const uint16_t* _frm_nxt = _frm; >>> +#else >>> const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm); >>> const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end); >>> const uint32_t* _frm_nxt = _frm; >>> +#endif >>> uint8_t* _to = reinterpret_cast<uint8_t*>(to); >>> uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end); >>> uint8_t* _to_nxt = _to; >>> +#if _WIN32 >>> + result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, >>> _to_nxt, >>> + _Maxcode_, _Mode_); >>> +#else >>> result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, >>> _Maxcode_, _Mode_); >>> +#endif >>> frm_nxt = frm + (_frm_nxt - _frm); >>> to_nxt = to + (_to_nxt - _to); >>> return r; >>> @@ -3222,11 +3233,19 @@ __codecvt_utf8<wchar_t>::do_in(state_typ >>> const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm); >>> const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end); >>> const uint8_t* _frm_nxt = _frm; >>> +#if _WIN32 >>> + uint16_t* _to = reinterpret_cast<uint16_t*>(to); >>> + uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end); >>> + uint16_t* _to_nxt = _to; >>> + result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, >>> _to_nxt, >>> + _Maxcode_, _Mode_); >>> +#else >>> uint32_t* _to = reinterpret_cast<uint32_t*>(to); >>> uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end); >>> uint32_t* _to_nxt = _to; >>> result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, >>> _Maxcode_, _Mode_); >>> +#endif >>> frm_nxt = frm + (_frm_nxt - _frm); >>> to_nxt = to + (_to_nxt - _to); >>> return r; >>> >>> Modified: >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp?rev=185849&r1=185848&r2=185849&view=diff >>> ============================================================================== >>> --- >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp >>> (original) >>> +++ >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp >>> Mon Jul 8 14:03:07 2013 >>> @@ -45,14 +45,14 @@ int main() >>> test_buf f(bs.rdbuf()); >>> assert(f.sbumpc() == L'1'); >>> assert(f.sgetc() == L'2'); >>> - assert(f.pbackfail(L'a') == -1); >>> + assert(f.pbackfail(L'a') == test_buf::traits_type::eof()); >>> } >>> { >>> std::fstream bs("underflow.dat"); >>> test_buf f(bs.rdbuf()); >>> assert(f.sbumpc() == L'1'); >>> assert(f.sgetc() == L'2'); >>> - assert(f.pbackfail(L'a') == -1); >>> + assert(f.pbackfail(L'a') == test_buf::traits_type::eof()); >>> assert(f.sbumpc() == L'2'); >>> assert(f.sgetc() == L'3'); >>> } >>> >>> Modified: >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp?rev=185849&r1=185848&r2=185849&view=diff >>> ============================================================================== >>> --- >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp >>> (original) >>> +++ >>> libcxx/trunk/test/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp >>> Mon Jul 8 14:03:07 2013 >>> @@ -79,6 +79,6 @@ int main() >>> assert(f.sbumpc() == 0x4E51); >>> assert(f.sbumpc() == 0x4E52); >>> assert(f.sbumpc() == 0x4E53); >>> - assert(f.sbumpc() == -1); >>> + assert(f.sbumpc() == test_buf::traits_type::eof()); >>> } >>> } >>> >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> [email protected] >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
