Skip to content

Commit

Permalink
Remove dependencies on unstable MSVC/STL extensions, comply w/ standa…
Browse files Browse the repository at this point in the history
…rds (#18334)

Fix some potential issues that may be exposed after upgrading the
compiler and dependencies. For detailed explanations, see the comments.
  • Loading branch information
YexuanXiao authored Jan 6, 2025
1 parent 7cd46c0 commit b25fe55
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/host/VtIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,11 @@ void VtIo::Writer::WriteUTF16(std::wstring_view str) const

// C++23's resize_and_overwrite is too valuable to not use.
// It reduce the CPU overhead by roughly half.
#if !defined(_HAS_CXX23) || !_HAS_CXX23
#if !defined(__cpp_lib_string_resize_and_overwrite) && _MSVC_STL_UPDATE >= 202111L
#define resize_and_overwrite _Resize_and_overwrite
#elif !defined(__cpp_lib_string_resize_and_overwrite)
#error "rely on resize_and_overwrite"
#endif

// NOTE: Throwing inside resize_and_overwrite invokes undefined behavior.
_io->_back.resize_and_overwrite(totalUTF8Cap, [&](char* buf, const size_t) noexcept {
const auto len = WideCharToMultiByte(CP_UTF8, 0, str.data(), gsl::narrow_cast<int>(incomingUTF16Len), buf + existingUTF8Len, gsl::narrow_cast<int>(incomingUTF8Cap), nullptr, nullptr);
Expand Down
1 change: 0 additions & 1 deletion src/inc/LibraryIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
// GSL
// Block GSL Multi Span include because it both has C++17 deprecated iterators
// and uses the C-namespaced "max" which conflicts with Windows definitions.
#include <gsl/gsl>
#include <gsl/gsl_util>
#include <gsl/pointers>

Expand Down
1 change: 1 addition & 0 deletions src/renderer/atlas/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <span>
#include <string_view>
#include <vector>
#include <cassert>

#include <d2d1_3.h>
#include <d3d11_2.h>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/gdi/gdirenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace Microsoft::Console::Render
// It's important the pool is first so it can be given to the others on construction.
std::pmr::unsynchronized_pool_resource _pool;
std::pmr::vector<std::pmr::wstring> _polyStrings;
std::pmr::vector<std::pmr::basic_string<int>> _polyWidths;
std::pmr::vector<std::pmr::vector<int>> _polyWidths;

std::vector<DWORD> _imageMask;

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/gdi/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ bool GdiEngine::FontHasWesternScript(HDC hdc)
polyString.back() &= softFontCharMask;
polyWidth.push_back(gsl::narrow<int>(cluster.GetColumns()) * coordFontSize.width);
cchCharWidths += polyWidth.back();
polyWidth.append(text.size() - 1, 0);
polyWidth.resize(polyWidth.size() + text.size() - 1);
}

// Detect and convert for raster font...
Expand Down
4 changes: 2 additions & 2 deletions src/server/WaitBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class ConsoleWaitBlock
_In_ IWaitRoutine* const pWaiter);

ConsoleWaitQueue* const _pProcessQueue;
std::_List_const_iterator<std::_List_val<std::_List_simple_types<ConsoleWaitBlock*>>> _itProcessQueue;
typename std::list<ConsoleWaitBlock*>::const_iterator _itProcessQueue;

ConsoleWaitQueue* const _pObjectQueue;
std::_List_const_iterator<std::_List_val<std::_List_simple_types<ConsoleWaitBlock*>>> _itObjectQueue;
typename std::list<ConsoleWaitBlock*>::const_iterator _itObjectQueue;

CONSOLE_API_MSG _WaitReplyMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/terminal/adapter/SixelParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace Microsoft::Console::VirtualTerminal
size_t _colorsUsed = 0;
size_t _colorsAvailable = 0;
bool _colorTableChanged = false;
IndexedPixel _foregroundPixel = 0;
IndexedPixel _foregroundPixel = {};

void _initImageBuffer();
void _resizeImageBuffer(const til::CoordType requiredHeight);
Expand Down
7 changes: 6 additions & 1 deletion src/types/colorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ void Utils::InitializeVT340ColorTable(const std::span<COLORREF> table) noexcept
}
}

#pragma warning(push)
#pragma warning(disable : 26497) // This is a false positive in audit mode.

// Function Description:
// - Fill color table entries from 16 to 255 with the default colors used by
// modern terminals. This includes a range of colors from a 6x6x6 color cube
Expand All @@ -255,7 +258,7 @@ void Utils::InitializeVT340ColorTable(const std::span<COLORREF> table) noexcept
// - table: a color table to be filled
// Return Value:
// - <none>
constexpr void Utils::InitializeExtendedColorTable(const std::span<COLORREF> table, const bool monochrome) noexcept
void Utils::InitializeExtendedColorTable(const std::span<COLORREF> table, const bool monochrome) noexcept
{
if (table.size() >= 256)
{
Expand All @@ -279,6 +282,8 @@ constexpr void Utils::InitializeExtendedColorTable(const std::span<COLORREF> tab
}
}

#pragma warning(pop)

#pragma warning(push)
#pragma warning(disable : 26447) // This is a false positive.

Expand Down
2 changes: 1 addition & 1 deletion src/types/inc/colorTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft::Console::Utils
void InitializeColorTable(const std::span<COLORREF> table) noexcept;
void InitializeANSIColorTable(const std::span<COLORREF> table) noexcept;
void InitializeVT340ColorTable(const std::span<COLORREF> table) noexcept;
constexpr void InitializeExtendedColorTable(const std::span<COLORREF> table, const bool monochrome = false) noexcept;
void InitializeExtendedColorTable(const std::span<COLORREF> table, const bool monochrome = false) noexcept;
std::span<const til::color> CampbellColorTable() noexcept;

std::optional<til::color> ColorFromXOrgAppColorName(const std::wstring_view wstr) noexcept;
Expand Down

0 comments on commit b25fe55

Please sign in to comment.