Skip to content

Commit bed8fa5

Browse files
authored
Replace CPPREST_TARGET_XP with version checks, remove ""s, and other cleanup (microsoft#1187)
* Audit for "" and use std::string default ctor instead. * Fix Linux ambiguity. * Exclude common build directories. * Replace CPPREST_TARGET_XP with checks against _WIN32_WINNT to allow more fine grained controls going forward (e.g. assume Win10). Also fix a few typos. * Delete CASABLANCA_UNREFERENCED_PARAMETER and attempt Linux compile fix. * Defend NOMINMAX. * Another _WIN32 guard. * With && this time. * Fix more spelling errors. * Optimize trim_nulls slightly. * And actually make the optimization correct this time. * Fix unit test failure. * clang-format
1 parent a718c5b commit bed8fa5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+326
-281
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ Build_android/build/
7373
Generated Files/
7474
# Ignore iOS temp build directories
7575
Build_iOS/Apple-Boost-BuildScript
76+
77+
/out/

.vscode/settings.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
"**/.git/objects/**": true,
44
"**/.git/subtree-cache/**": true,
55
"**/node_modules/*/**": true,
6-
"**/vcpkg/**": true
7-
}
6+
"**/vcpkg/**": true,
7+
"build.x86.debug": true,
8+
"build.x86.release": true,
9+
"build.x64.debug": true,
10+
"build.x64.release": true,
11+
"out": true,
12+
},
13+
"cSpell.words": [
14+
"XPLATSTR",
15+
"blittable",
16+
"pplx",
17+
"rdpos",
18+
"rgpsz"
19+
]
820
}

Release/include/cpprest/details/cpprest_compat.h

-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#define CPPREST_CONSTEXPR const
2525
#endif // _MSC_VER >= 1900
2626

27-
#define CASABLANCA_UNREFERENCED_PARAMETER(x) (x)
28-
2927
#include <sal.h>
3028

3129
#else // ^^^ _WIN32 ^^^ // vvv !_WIN32 vvv
@@ -38,7 +36,6 @@
3836
{ \
3937
if (!(x)) __builtin_unreachable(); \
4038
} while (false)
41-
#define CASABLANCA_UNREFERENCED_PARAMETER(x) (void)x
4239
#define CPPREST_NOEXCEPT noexcept
4340
#define CPPREST_CONSTEXPR constexpr
4441

Release/include/cpprest/details/web_utilities.h

+18-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
****/
1111
#pragma once
1212

13+
#ifdef _WIN32
14+
#include <Windows.h>
15+
#endif // _WIN32
16+
1317
#include "cpprest/asyncrt_utils.h"
1418
#include "cpprest/uri.h"
1519

@@ -24,23 +28,24 @@ class zero_memory_deleter
2428
};
2529
typedef std::unique_ptr<::utility::string_t, zero_memory_deleter> plaintext_string;
2630

27-
#if defined(_WIN32) && !defined(CPPREST_TARGET_XP)
28-
#if defined(__cplusplus_winrt)
31+
#ifdef _WIN32
32+
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
33+
#ifdef __cplusplus_winrt
2934
class winrt_encryption
3035
{
3136
public:
32-
winrt_encryption() {}
37+
winrt_encryption() = default;
3338
_ASYNCRTIMP winrt_encryption(const std::wstring& data);
3439
_ASYNCRTIMP plaintext_string decrypt() const;
3540

3641
private:
3742
::pplx::task<Windows::Storage::Streams::IBuffer ^> m_buffer;
3843
};
39-
#else
44+
#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv
4045
class win32_encryption
4146
{
4247
public:
43-
win32_encryption() {}
48+
win32_encryption() = default;
4449
_ASYNCRTIMP win32_encryption(const std::wstring& data);
4550
_ASYNCRTIMP ~win32_encryption();
4651
_ASYNCRTIMP plaintext_string decrypt() const;
@@ -49,8 +54,9 @@ class win32_encryption
4954
std::vector<char> m_buffer;
5055
size_t m_numCharacters;
5156
};
52-
#endif
53-
#endif
57+
#endif // __cplusplus_winrt
58+
#endif // _WIN32_WINNT >= _WIN32_WINNT_VISTA
59+
#endif // _WIN32
5460
} // namespace details
5561

5662
/// <summary>
@@ -89,7 +95,7 @@ class credentials
8995
"This API is deprecated for security reasons to avoid unnecessary password copies stored in plaintext.")
9096
utility::string_t password() const
9197
{
92-
#if defined(_WIN32) && !defined(CPPREST_TARGET_XP)
98+
#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
9399
return utility::string_t(*m_password.decrypt());
94100
#else
95101
return m_password;
@@ -105,7 +111,7 @@ class credentials
105111
details::plaintext_string _internal_decrypt() const
106112
{
107113
// Encryption APIs not supported on XP
108-
#if defined(_WIN32) && !defined(CPPREST_TARGET_XP)
114+
#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
109115
return m_password.decrypt();
110116
#else
111117
return details::plaintext_string(new ::utility::string_t(m_password));
@@ -115,7 +121,7 @@ class credentials
115121
private:
116122
::utility::string_t m_username;
117123

118-
#if defined(_WIN32) && !defined(CPPREST_TARGET_XP)
124+
#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
119125
#if defined(__cplusplus_winrt)
120126
details::winrt_encryption m_password;
121127
#else
@@ -151,13 +157,13 @@ class web_proxy
151157
/// <summary>
152158
/// Constructs a proxy with the default settings.
153159
/// </summary>
154-
web_proxy() : m_address(_XPLATSTR("")), m_mode(use_default_) {}
160+
web_proxy() : m_address(), m_mode(use_default_) {}
155161

156162
/// <summary>
157163
/// Creates a proxy with specified mode.
158164
/// </summary>
159165
/// <param name="mode">Mode to use.</param>
160-
web_proxy(web_proxy_mode mode) : m_address(_XPLATSTR("")), m_mode(static_cast<web_proxy_mode_internal>(mode)) {}
166+
web_proxy(web_proxy_mode mode) : m_address(), m_mode(static_cast<web_proxy_mode_internal>(mode)) {}
161167

162168
/// <summary>
163169
/// Creates a proxy explicitly with provided address.

Release/include/cpprest/http_client.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef void* native_handle;
5454
#include <limits>
5555
#include <memory>
5656

57-
#if !defined(CPPREST_TARGET_XP)
57+
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
5858
#include "cpprest/oauth1.h"
5959
#endif
6060

@@ -110,7 +110,7 @@ class http_client_config
110110
{
111111
}
112112

113-
#if !defined(CPPREST_TARGET_XP)
113+
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
114114
/// <summary>
115115
/// Get OAuth 1.0 configuration.
116116
/// </summary>
@@ -363,7 +363,7 @@ class http_client_config
363363
#endif
364364

365365
private:
366-
#if !defined(CPPREST_TARGET_XP)
366+
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
367367
std::shared_ptr<oauth1::experimental::oauth1_config> m_oauth1;
368368
#endif
369369

Release/include/cpprest/streams.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ _UINT_TRAIT(unsigned long long, ULLONG_MIN, ULLONG_MAX)
470470
{ \
471471
typedef std::true_type _is_integral; \
472472
typedef std::false_type _is_unsigned; \
473-
static const int64_t _min = std::numeric_limits<_t>::min(); \
473+
static const int64_t _min = (std::numeric_limits<_t>::min)(); \
474474
static const int64_t _max = (std::numeric_limits<_t>::max)(); \
475475
};
476476
#define _UINT_TRAIT(_t) \
@@ -1139,8 +1139,8 @@ pplx::task<ReturnType> _type_parser_base<CharType>::_parse_input(concurrency::st
11391139
auto update = [=](pplx::task<int_type> op) -> pplx::task<bool> {
11401140
int_type ch = op.get();
11411141
if (ch == traits::eof()) return pplx::task_from_result(false);
1142-
bool accptd = accept_character(state, ch);
1143-
if (!accptd) return pplx::task_from_result(false);
1142+
bool accepted = accept_character(state, ch);
1143+
if (!accepted) return pplx::task_from_result(false);
11441144
// We peeked earlier, so now we must advance the position.
11451145
concurrency::streams::streambuf<CharType> buf = buffer;
11461146
return buf.bumpc().then([](int_type) { return true; });
@@ -1308,9 +1308,18 @@ struct _double_state
13081308
template<typename FloatingPoint, typename int_type>
13091309
static std::string create_exception_message(int_type ch, bool exponent)
13101310
{
1311-
std::ostringstream os;
1312-
os << "Invalid character '" << char(ch) << "'" << (exponent ? " in exponent" : "");
1313-
return os.str();
1311+
std::string result;
1312+
if (exponent)
1313+
{
1314+
result.assign("Invalid character 'X' in exponent");
1315+
}
1316+
else
1317+
{
1318+
result.assign("Invalid character 'X'");
1319+
}
1320+
1321+
result[19] = static_cast<char>(ch);
1322+
return result;
13141323
}
13151324

13161325
template<typename FloatingPoint, typename int_type>

Release/include/cpprest/ws_client.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ class websocket_client_callback_impl
330330

331331
virtual pplx::task<void> close() = 0;
332332

333-
virtual pplx::task<void> close(websocket_close_status close_status,
334-
const utility::string_t& close_reason = _XPLATSTR("")) = 0;
333+
virtual pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = {}) = 0;
335334

336335
virtual void set_close_handler(
337336
const std::function<void(websocket_close_status, const utility::string_t&, const std::error_code&)>&
@@ -478,7 +477,7 @@ class websocket_client
478477
/// frame.</param> <param name="close_reason">While closing an established connection, an endpoint may indicate the
479478
/// reason for closure.</param> <returns>An asynchronous operation that is completed the connection has been
480479
/// successfully closed.</returns>
481-
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = _XPLATSTR(""))
480+
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = {})
482481
{
483482
return m_client->callback_client()->close(close_status, close_reason);
484483
}
@@ -566,7 +565,7 @@ class websocket_callback_client
566565
/// frame.</param> <param name="close_reason">While closing an established connection, an endpoint may indicate the
567566
/// reason for closure.</param> <returns>An asynchronous operation that is completed the connection has been
568567
/// successfully closed.</returns>
569-
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = _XPLATSTR(""))
568+
pplx::task<void> close(websocket_close_status close_status, const utility::string_t& close_reason = {})
570569
{
571570
return m_client->close(close_status, close_reason);
572571
}

Release/include/cpprest/ws_msg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class websocket_outgoing_message
7474
/// </summary>
7575
/// <param name="data">UTF-8 String containing the optional pong message.</param>
7676
void set_pong_message(const std::string& data = {})
77-
{
77+
{
7878
this->set_message_pong(concurrency::streams::container_buffer<std::string>(data));
7979
}
8080
#endif

Release/include/pplx/pplxtasks.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3799,7 +3799,7 @@ class task
37993799
auto _LogWorkItemAndInvokeUserLambda(_Func&& _func) const -> decltype(_func())
38003800
{
38013801
details::_TaskWorkItemRAIILogger _LogWorkItem(this->_M_pTask->_M_taskEventLogger);
3802-
CASABLANCA_UNREFERENCED_PARAMETER(_LogWorkItem);
3802+
(void)_LogWorkItem;
38033803
return _func();
38043804
}
38053805

@@ -3931,7 +3931,7 @@ class task
39313931
-> decltype(_func(std::forward<_Arg>(_value)))
39323932
{
39333933
details::_TaskWorkItemRAIILogger _LogWorkItem(this->_M_pTask->_M_taskEventLogger);
3934-
CASABLANCA_UNREFERENCED_PARAMETER(_LogWorkItem);
3934+
(void)_LogWorkItem;
39353935
return _func(std::forward<_Arg>(_value));
39363936
}
39373937

Release/samples/BlackJack/BlackJack_Client/BlackJackClient.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef WIN32_LEAN_AND_MEAN
1818
#define WIN32_LEAN_AND_MEAN
1919
#endif
20-
#define NOMINMAX
2120
#include <objbase.h>
2221
#include <winsock2.h>
2322

Release/samples/BlackJack/BlackJack_Server/messagetypes.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ struct BJHand
179179
{
180180
if (iter->value == CV_Ace) hasAces = true;
181181

182-
res.low += std::min((int)iter->value, 10);
182+
res.low += (std::min)((int)iter->value, 10);
183183
}
184184
res.high = hasAces ? res.low + 10 : res.low;
185185
return res;
@@ -271,7 +271,7 @@ struct Player
271271

272272
static Player FromJSON(const web::json::object& object)
273273
{
274-
Player result(U(""));
274+
Player result(utility::string_t{});
275275

276276
auto iName = object.find(NAME);
277277
if (iName == object.end())

Release/samples/BlackJack/BlackJack_Server/stdafx.h

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
#include <vector>
2727

2828
#ifdef _WIN32
29-
#ifndef NOMINMAX
30-
#define NOMINMAX
31-
#endif
3229
#include <Windows.h>
3330
#else
3431
#include <sys/time.h>

Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ void PlayerSpace::Update(Player player)
5454
playerName->Text = ref new Platform::String(web::uri::decode(player.Name).c_str());
5555
playerBalance->Text = "$" + player.Balance.ToString();
5656
playerBet->Text = "Bet: $" + player.Hand.bet.ToString();
57-
playerInsurance->Text = (player.Hand.insurance > 0) ? "Ins: $" + player.Hand.insurance.ToString() : "";
57+
if (player.Hand.insurance > 0) {
58+
auto& text = playerInsurance->Text;
59+
text.assign("Ins: $");
60+
text.append(std::to_string(player.Hand.insurance));
61+
} else {
62+
text.clear();
63+
}
5864
}
5965

6066
void PlayerSpace::AddCard(Card card)
@@ -87,19 +93,19 @@ void PlayerSpace::ShowResult(BJHandResult result)
8793
{
8894
case BJHandResult::HR_ComputerWin:
8995
playerInsurance->Text = L"Dealer Wins";
90-
playerBet->Text = L"";
96+
playerBet->Text.clear();
9197
break;
9298
case BJHandResult::HR_PlayerWin:
9399
playerInsurance->Text = L"Player Wins";
94-
playerBet->Text = L"";
100+
playerBet->Text.clear();
95101
break;
96102
case BJHandResult::HR_Push:
97103
playerInsurance->Text = L"Push";
98-
playerBet->Text = L"";
104+
playerBet->Text.clear();
99105
break;
100106
case BJHandResult::HR_PlayerBlackJack:
101107
playerInsurance->Text = L"Blackjack!";
102-
playerBet->Text = L"";
108+
playerBet->Text.clear();
103109
break;
104110
default: break;
105111
}

Release/samples/BlackJack/BlackJack_UIClient/Player.xaml.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ ref class PlayerSpace sealed
2525

2626
void Clear()
2727
{
28-
playerBalance->Text = L"";
29-
playerBet->Text = L"";
30-
playerName->Text = L"";
31-
playerInsurance->Text = L"";
28+
playerBalance->Text.clear();
29+
playerBet->Text.clear();
30+
playerName->Text.clear();
31+
playerInsurance->Text.clear();
3232
m_cards.clear();
3333
playerCardGrid->Children->Clear();
3434
}

0 commit comments

Comments
 (0)