56-iostream.patch 7.9 KB

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