56-iostream.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. diff --git a/include/ostream b/include/ostream
  2. index 42819ce..51778a2 100644
  3. --- a/include/ostream
  4. +++ b/include/ostream
  5. @@ -964,7 +964,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) {
  6. std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
  7. }
  8. -#if _LIBCPP_STD_VER >= 20
  9. +#if 0
  10. # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  11. template <class _Traits>
  12. diff --git a/src/iostream.cpp b/src/iostream.cpp
  13. index c5ad77a..029de4a 100644
  14. --- a/src/iostream.cpp
  15. +++ b/src/iostream.cpp
  16. @@ -21,80 +21,120 @@
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  19. +alignas(istream) char _cin[sizeof(istream)];
  20. +_LIBCPP_EXPORTED_FROM_ABI istream& cin = *reinterpret_cast<istream*>(_cin);
  21. +#else
  22. alignas(istream) _LIBCPP_EXPORTED_FROM_ABI char cin[sizeof(istream)]
  23. #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  24. __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
  25. "@std@@@12@A")
  26. #endif
  27. ;
  28. +#endif
  29. alignas(__stdinbuf<char>) static char __cin[sizeof(__stdinbuf<char>)];
  30. static mbstate_t mb_cin;
  31. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  32. +# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  33. +alignas(wistream) char _wcin[sizeof(wistream)];
  34. +_LIBCPP_EXPORTED_FROM_ABI wistream& wcin = *reinterpret_cast<wistream*>(_wcin);
  35. +# else
  36. alignas(wistream) _LIBCPP_EXPORTED_FROM_ABI char wcin[sizeof(wistream)]
  37. # if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  38. __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
  39. "@std@@@12@A")
  40. # endif
  41. ;
  42. +#endif
  43. alignas(__stdinbuf<wchar_t>) static char __wcin[sizeof(__stdinbuf<wchar_t>)];
  44. static mbstate_t mb_wcin;
  45. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  46. +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  47. +alignas(ostream) char _cout[sizeof(ostream)];
  48. +_LIBCPP_EXPORTED_FROM_ABI ostream& cout = *reinterpret_cast<ostream*>(_cout);
  49. +#else
  50. alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cout[sizeof(ostream)]
  51. #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  52. __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
  53. "@std@@@12@A")
  54. #endif
  55. ;
  56. +#endif
  57. alignas(__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
  58. static mbstate_t mb_cout;
  59. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  60. +# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  61. +alignas(wostream) char _wcout[sizeof(wostream)];
  62. +_LIBCPP_EXPORTED_FROM_ABI wostream& wcout = *reinterpret_cast<wostream*>(_wcout);
  63. +# else
  64. alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcout[sizeof(wostream)]
  65. # if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  66. __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
  67. "@std@@@12@A")
  68. # endif
  69. ;
  70. +#endif
  71. alignas(__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
  72. static mbstate_t mb_wcout;
  73. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  74. +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  75. +alignas(ostream) char _cerr[sizeof(ostream)];
  76. +_LIBCPP_EXPORTED_FROM_ABI ostream& cerr = *reinterpret_cast<ostream*>(_cerr);
  77. +#else
  78. alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cerr[sizeof(ostream)]
  79. #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  80. __asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
  81. "@std@@@12@A")
  82. #endif
  83. ;
  84. +#endif
  85. alignas(__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
  86. static mbstate_t mb_cerr;
  87. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  88. +# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  89. +alignas(wostream) char _wcerr[sizeof(wostream)];
  90. +_LIBCPP_EXPORTED_FROM_ABI wostream& wcerr = *reinterpret_cast<wostream*>(_wcerr);
  91. +# else
  92. alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcerr[sizeof(wostream)]
  93. # if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  94. __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
  95. "@std@@@12@A")
  96. # endif
  97. ;
  98. +# endif
  99. alignas(__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
  100. static mbstate_t mb_wcerr;
  101. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  102. +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  103. +alignas(ostream) char _clog[sizeof(ostream)];
  104. +_LIBCPP_EXPORTED_FROM_ABI ostream& clog = *reinterpret_cast<ostream*>(_clog);
  105. +#else
  106. alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char clog[sizeof(ostream)]
  107. #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  108. __asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
  109. "@std@@@12@A")
  110. #endif
  111. ;
  112. +#endif
  113. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  114. +# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(__clang__)
  115. +alignas(wostream) char _wclog[sizeof(wostream)];
  116. +_LIBCPP_EXPORTED_FROM_ABI wostream& wclog = *reinterpret_cast<wostream*>(_wclog);
  117. +# else
  118. alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wclog[sizeof(wostream)]
  119. # if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
  120. __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
  121. "@std@@@12@A")
  122. # endif
  123. ;
  124. +#endif
  125. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  126. // Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
  127. @@ -128,19 +168,19 @@ public:
  128. DoIOSInit::DoIOSInit() {
  129. force_locale_initialization();
  130. - istream* cin_ptr = ::new (cin) istream(::new (__cin) __stdinbuf<char>(stdin, &mb_cin));
  131. - ostream* cout_ptr = ::new (cout) ostream(::new (__cout) __stdoutbuf<char>(stdout, &mb_cout));
  132. - ostream* cerr_ptr = ::new (cerr) ostream(::new (__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
  133. - ::new (clog) ostream(cerr_ptr->rdbuf());
  134. + istream* cin_ptr = ::new (&cin) istream(::new (__cin) __stdinbuf<char>(stdin, &mb_cin));
  135. + ostream* cout_ptr = ::new (&cout) ostream(::new (__cout) __stdoutbuf<char>(stdout, &mb_cout));
  136. + ostream* cerr_ptr = ::new (&cerr) ostream(::new (__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
  137. + ::new (&clog) ostream(cerr_ptr->rdbuf());
  138. cin_ptr->tie(cout_ptr);
  139. std::unitbuf(*cerr_ptr);
  140. cerr_ptr->tie(cout_ptr);
  141. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  142. - wistream* wcin_ptr = ::new (wcin) wistream(::new (__wcin) __stdinbuf<wchar_t>(stdin, &mb_wcin));
  143. - wostream* wcout_ptr = ::new (wcout) wostream(::new (__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
  144. - wostream* wcerr_ptr = ::new (wcerr) wostream(::new (__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
  145. - ::new (wclog) wostream(wcerr_ptr->rdbuf());
  146. + wistream* wcin_ptr = ::new (&wcin) wistream(::new (__wcin) __stdinbuf<wchar_t>(stdin, &mb_wcin));
  147. + wostream* wcout_ptr = ::new (&wcout) wostream(::new (__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
  148. + wostream* wcerr_ptr = ::new (&wcerr) wostream(::new (__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
  149. + ::new (&wclog) wostream(wcerr_ptr->rdbuf());
  150. wcin_ptr->tie(wcout_ptr);
  151. std::unitbuf(*wcerr_ptr);
  152. @@ -149,15 +189,15 @@ DoIOSInit::DoIOSInit() {
  153. }
  154. DoIOSInit::~DoIOSInit() {
  155. - ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
  156. + ostream* cout_ptr = reinterpret_cast<ostream*>(&cout);
  157. cout_ptr->flush();
  158. - ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
  159. + ostream* clog_ptr = reinterpret_cast<ostream*>(&clog);
  160. clog_ptr->flush();
  161. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  162. - wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
  163. + wostream* wcout_ptr = reinterpret_cast<wostream*>(&wcout);
  164. wcout_ptr->flush();
  165. - wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
  166. + wostream* wclog_ptr = reinterpret_cast<wostream*>(&wclog);
  167. wclog_ptr->flush();
  168. #endif
  169. }