Skip to content

Commit 4ddaec3

Browse files
authored
Temporary fix for VS2013. (#1033)
* Workaround some VS2013 bugs. * Fix threadpool.cpp under VS2013.
1 parent 5a885dd commit 4ddaec3

File tree

9 files changed

+84
-49
lines changed

9 files changed

+84
-49
lines changed

Release/samples/BlackJack/BlackJack_Server/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if(MSVC)
1616
set_property(SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/blackjack-server-stdafx.pch")
1717
set_property(SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/blackjack-server-stdafx.pch")
1818
endif()
19-
set_source_files_properties(stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpblackjack-server-stdafx.pch")
19+
set_source_files_properties(stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpblackjack-server-stdafx.pch /Zm120")
2020
target_sources(blackjackserver PRIVATE stdafx.cpp)
21-
target_compile_options(blackjackserver PRIVATE /Yustdafx.h /Fpblackjack-server-stdafx.pch)
21+
target_compile_options(blackjackserver PRIVATE /Yustdafx.h /Fpblackjack-server-stdafx.pch /Zm120)
2222
endif()

Release/src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ if(MSVC)
179179
set_property(SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/stdafx.pch")
180180
endif()
181181

182-
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
182+
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Zm120")
183183
target_sources(cpprest PRIVATE pch/stdafx.cpp)
184-
target_compile_options(cpprest PRIVATE /Yustdafx.h)
184+
target_compile_options(cpprest PRIVATE /Yustdafx.h /Zm120)
185185
endif()
186186

187187
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")

Release/src/http/listener/http_server_httpsys.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ pplx::task<void> http_windows_server::register_listener(
225225
return pplx::task_from_exception<void>(
226226
http_exception(errorCode,
227227
_XPLATSTR("Access denied: attempting to add Address '") + pListener->uri().to_string() +
228-
_XPLATSTR("'. ") _XPLATSTR("Run as administrator to listen on an hostname other "
229-
"than localhost, or to listen on port 80.")));
228+
_XPLATSTR("'. Run as administrator to listen on an hostname other ")
229+
_XPLATSTR("than localhost, or to listen on port 80.")));
230230
}
231231
else
232232
{

Release/src/pplx/pplxwin.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _PPLXIMP size_t __cdecl CaptureCallstack(void** stackData, size_t skipFrames, si
4141
#if !defined(__cplusplus_winrt)
4242
capturedFrames = RtlCaptureStackBackTrace(
4343
static_cast<DWORD>(skipFrames + 1), static_cast<DWORD>(captureFrames), stackData, nullptr);
44-
#endif
44+
#endif // !__cplusplus_winrt
4545
return capturedFrames;
4646
}
4747

@@ -64,9 +64,9 @@ void InitializeCriticalSection(LPCRITICAL_SECTION _cs)
6464
{
6565
throw ::std::bad_alloc();
6666
}
67-
#else
67+
#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv
6868
InitializeCriticalSectionEx(_cs, 0, 0);
69-
#endif // !__cplusplus_winrt
69+
#endif // __cplusplus_winrt
7070
}
7171

7272
} // namespace platform
@@ -169,7 +169,7 @@ _PPLXIMP void windows_scheduler::schedule(TaskProc_t proc, _In_ void* param)
169169

170170
Windows::System::Threading::ThreadPool::RunAsync(workItemHandler);
171171
}
172-
#else
172+
#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv
173173

174174
#if _WIN32_WINNT < _WIN32_WINNT_VISTA
175175
struct _Scheduler_Param
@@ -202,7 +202,7 @@ _PPLXIMP void windows_scheduler::schedule(TaskProc_t proc, _In_ void* param)
202202
throw utility::details::create_system_error(GetLastError());
203203
}
204204
}
205-
#else
205+
#else // ^^^ _WIN32_WINNT < _WIN32_WINNT_VISTA ^^^ // vvv _WIN32_WINNT >= _WIN32_WINNT_VISTA vvv
206206
struct _Scheduler_Param
207207
{
208208
TaskProc_t m_proc;
@@ -236,12 +236,12 @@ _PPLXIMP void windows_scheduler::schedule(TaskProc_t proc, _In_ void* param)
236236
}
237237
#endif // _WIN32_WINNT < _WIN32_WINNT_VISTA
238238

239-
#endif
239+
#endif // __cplusplus_winrt
240240
} // namespace details
241241

242242
} // namespace pplx
243243

244-
#else
244+
#else // ^^^ !defined(_WIN32) || CPPREST_FORCE_PPLX ^^^ // vvv defined(_WIN32) && !CPPREST_FORCE_PPLX vvv
245245
namespace Concurrency
246246
{
247247
void __cdecl set_cpprestsdk_ambient_scheduler(const std::shared_ptr<scheduler_interface>& _Scheduler)
@@ -251,7 +251,9 @@ void __cdecl set_cpprestsdk_ambient_scheduler(const std::shared_ptr<scheduler_in
251251

252252
const std::shared_ptr<scheduler_interface>& __cdecl get_cpprestsdk_ambient_scheduler()
253253
{
254-
return pplx::get_ambient_scheduler();
254+
const auto& tmp = pplx::get_ambient_scheduler(); // putting this in a temporary reference variable to workaround
255+
// VS2013 compiler bugs
256+
return tmp;
255257
}
256258

257259
} // namespace Concurrency

Release/src/pplx/threadpool.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ struct threadpool_impl final : crossplat::threadpool
5858
add_thread();
5959
}
6060

61+
threadpool_impl(const threadpool_impl&) = delete;
62+
threadpool_impl& operator=(const threadpool_impl&) = delete;
63+
6164
~threadpool_impl()
6265
{
6366
m_service.stop();
@@ -102,13 +105,21 @@ struct threadpool_impl final : crossplat::threadpool
102105
#if defined(_WIN32)
103106
struct shared_threadpool
104107
{
108+
#if defined(_MSC_VER) && _MSC_VER < 1900
109+
std::aligned_storage<sizeof(threadpool_impl)>::type shared_storage;
110+
111+
threadpool_impl& get_shared() { return reinterpret_cast<threadpool_impl&>(shared_storage); }
112+
113+
shared_threadpool(size_t n) { ::new (static_cast<void*>(&shared_storage)) threadpool_impl(n); }
114+
#else // ^^^ VS2013 ^^^ // vvv everything else vvv
105115
union {
106116
threadpool_impl shared_storage;
107117
};
108118

109119
threadpool_impl& get_shared() { return shared_storage; }
110120

111121
shared_threadpool(size_t n) : shared_storage(n) {}
122+
#endif // defined(_MSC_VER) && _MSC_VER < 1900
112123

113124
~shared_threadpool()
114125
{
@@ -132,22 +143,34 @@ namespace
132143
template<class T>
133144
struct uninitialized
134145
{
146+
#if defined(_MSC_VER) && _MSC_VER < 1900
147+
typename std::aligned_storage<sizeof(T)>::type storage;
148+
149+
~uninitialized()
150+
{
151+
if (initialized)
152+
{
153+
reinterpret_cast<T&>(storage).~T();
154+
}
155+
}
156+
#else // ^^^ VS2013 ^^^ // vvv everything else vvv
135157
union {
136158
T storage;
137159
};
138160

139-
bool initialized;
140-
141-
uninitialized() CPPREST_NOEXCEPT : initialized(false) {}
142-
uninitialized(const uninitialized&) = delete;
143-
uninitialized& operator=(const uninitialized&) = delete;
144161
~uninitialized()
145162
{
146163
if (initialized)
147164
{
148165
storage.~T();
149166
}
150167
}
168+
#endif // defined(_MSC_VER) && _MSC_VER < 1900
169+
170+
bool initialized;
171+
uninitialized() CPPREST_NOEXCEPT : initialized(false) {}
172+
uninitialized(const uninitialized&) = delete;
173+
uninitialized& operator=(const uninitialized&) = delete;
151174

152175
template<class... Args>
153176
void construct(Args&&... vals)
@@ -173,7 +196,15 @@ std::pair<bool, platform_shared_threadpool*> initialize_shared_threadpool(size_t
173196
initialized_this_time = true;
174197
});
175198

176-
return {initialized_this_time, &uninit_threadpool.storage};
199+
return
200+
{
201+
initialized_this_time,
202+
#if defined(_MSC_VER) && _MSC_VER < 1900
203+
reinterpret_cast<platform_shared_threadpool*>(&uninit_threadpool.storage)
204+
#else // ^^^ VS2013 ^^^ // vvv everything else vvv
205+
&uninit_threadpool.storage
206+
#endif // defined(_MSC_VER) && _MSC_VER < 1900
207+
};
177208
}
178209
} // namespace
179210

Release/tests/functional/http/client/oauth1_tests.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ SUITE(oauth1_tests)
123123

124124
#undef TEST_ACCESSOR
125125

126+
// clang-format off
126127
TEST_FIXTURE(oauth1_token_setup, oauth1_signature_base_string)
127128
{
128129
// Basic base string generation.
@@ -137,9 +138,9 @@ SUITE(oauth1_tests)
137138

138139
utility::string_t base_string = m_oauth1_config._build_signature_base_string(r, state);
139140
utility::string_t correct_base_string(
140-
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%"
141-
"3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_"
142-
"token%26oauth_version%3D1.0"));
141+
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%")
142+
U("3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_")
143+
U("token%26oauth_version%3D1.0"));
143144
VERIFY_ARE_EQUAL(correct_base_string, base_string);
144145
}
145146

@@ -155,9 +156,9 @@ SUITE(oauth1_tests)
155156

156157
utility::string_t base_string = m_oauth1_config._build_signature_base_string(r, state);
157158
utility::string_t correct_base_string(
158-
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%"
159-
"3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_test%3Dxyzzy%26oauth_timestamp%3D12345678%"
160-
"26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
159+
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%")
160+
U("3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_test%3Dxyzzy%26oauth_timestamp%3D12345678%")
161+
U("26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
161162
VERIFY_ARE_EQUAL(correct_base_string, base_string);
162163
}
163164

@@ -173,9 +174,9 @@ SUITE(oauth1_tests)
173174

174175
utility::string_t base_string = m_oauth1_config._build_signature_base_string(r, state);
175176
utility::string_t correct_base_string(
176-
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26MyVariableOne%3DValueOne%26%26MyVariableTwo%"
177-
"3DValueTwo%26oauth_consumer_key%3Dtest_key%26oauth_nonce%3DABCDEFGH%26oauth_signature_method%3DHMAC-"
178-
"SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
177+
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26MyVariableOne%3DValueOne%26%26MyVariableTwo%")
178+
U("3DValueTwo%26oauth_consumer_key%3Dtest_key%26oauth_nonce%3DABCDEFGH%26oauth_signature_method%3DHMAC-")
179+
U("SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
179180
}
180181
}
181182

@@ -214,8 +215,8 @@ SUITE(oauth1_tests)
214215
m_server.server()->next_request().then([](test_request* request) {
215216
const utility::string_t header_authorization(request->m_headers[header_names::authorization]);
216217
const utility::string_t prefix(
217-
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", "
218-
"oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
218+
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", ")
219+
U("oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
219220
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
220221
request->reply(status_codes::OK);
221222
});
@@ -237,8 +238,8 @@ SUITE(oauth1_tests)
237238
m_server.server()->next_request().then([](test_request* request) {
238239
const utility::string_t header_authorization(request->m_headers[header_names::authorization]);
239240
const utility::string_t prefix(
240-
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", "
241-
"oauth_signature_method=\"PLAINTEXT\", oauth_timestamp=\""));
241+
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", ")
242+
U("oauth_signature_method=\"PLAINTEXT\", oauth_timestamp=\""));
242243
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
243244
request->reply(status_codes::OK);
244245
});
@@ -254,8 +255,8 @@ SUITE(oauth1_tests)
254255
const utility::string_t header_authorization(request->m_headers[header_names::authorization]);
255256

256257
// Verify prefix, and without 'oauth_token'.
257-
const utility::string_t prefix(U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", "
258-
"oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
258+
const utility::string_t prefix(U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", ")
259+
U("oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
259260
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
260261

261262
// Verify suffix with proper 'oauth_callback'.
@@ -285,8 +286,8 @@ SUITE(oauth1_tests)
285286

286287
// Verify temporary token prefix.
287288
const utility::string_t prefix(
288-
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"xyzzy\", "
289-
"oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
289+
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"xyzzy\", ")
290+
U("oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
290291
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
291292

292293
// Verify suffix with 'oauth_verifier'.
@@ -313,6 +314,8 @@ SUITE(oauth1_tests)
313314
VERIFY_ARE_EQUAL(m_oauth1_config.token().secret(), U("bar"));
314315
}
315316

317+
// clang-format on
318+
316319
} // SUITE(oauth1_tests)
317320

318321
} // namespace client

Release/tests/functional/http/client/oauth2_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ SUITE(oauth2_tests)
130130
config.set_client_key(U("4567abcd"));
131131
config.set_auth_endpoint(U("https://test1"));
132132
config.set_redirect_uri(U("http://localhost:8080"));
133-
VERIFY_ARE_EQUAL(U("https://test1/?response_type=code&client_id=4567abcd&redirect_uri=http://"
134-
"localhost:8080&state=xyzzy&scope=testing_123"),
133+
VERIFY_ARE_EQUAL(U("https://test1/?response_type=code&client_id=4567abcd&redirect_uri=http://")
134+
U("localhost:8080&state=xyzzy&scope=testing_123"),
135135
config.build_authorization_uri(false));
136136
}
137137

138138
// Verify again with implicit grant.
139139
{
140140
config.set_implicit_grant(true);
141-
VERIFY_ARE_EQUAL(U("https://test1/?response_type=token&client_id=4567abcd&redirect_uri=http://"
142-
"localhost:8080&state=xyzzy&scope=testing_123"),
141+
VERIFY_ARE_EQUAL(U("https://test1/?response_type=token&client_id=4567abcd&redirect_uri=http://")
142+
U("localhost:8080&state=xyzzy&scope=testing_123"),
143143
config.build_authorization_uri(false));
144144
}
145145

@@ -190,8 +190,8 @@ SUITE(oauth2_tests)
190190

191191
VERIFY_ARE_EQUAL(U(""), request->m_headers[header_names::authorization]);
192192

193-
VERIFY_ARE_EQUAL(to_body_data(U("grant_type=authorization_code&code=789GHI&redirect_uri=https%3A%2F%"
194-
"2Fbar&client_id=123ABC&client_secret=456DEF")),
193+
VERIFY_ARE_EQUAL(to_body_data(U("grant_type=authorization_code&code=789GHI&redirect_uri=https%3A%2F%")
194+
U("2Fbar&client_id=123ABC&client_secret=456DEF")),
195195
request->m_body);
196196

197197
VERIFY_ARE_EQUAL(U("test_user_agent"), get_request_user_agent(request));

Release/tests/functional/http/client/outside_tests.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ SUITE(outside_tests)
116116
});
117117
}
118118

119-
#if (defined(_MSC_VER) && (_MSC_VER >= 1800)) && !CPPREST_FORCE_PPLX
119+
#if (defined(_MSC_VER) && (_MSC_VER >= 1900)) && !CPPREST_FORCE_PPLX
120120
TEST_FIXTURE(uri_address, multiple_https_requests_sync_scheduler)
121121
{
122122
struct sync_scheduler : public scheduler_interface
@@ -175,9 +175,8 @@ SUITE(outside_tests)
175175
TEST_FIXTURE(uri_address, no_transfer_encoding_content_length)
176176
{
177177
handle_timeout([] {
178-
http_client client(
179-
U("http://ws.audioscrobbler.com/2.0/"
180-
"?method=artist.gettoptracks&artist=cher&api_key=6fcd59047568e89b1615975081258990&format=json"));
178+
http_client client(U("http://ws.audioscrobbler.com/2.0/") U(
179+
"?method=artist.gettoptracks&artist=cher&api_key=6fcd59047568e89b1615975081258990&format=json"));
181180

182181
client.request(methods::GET)
183182
.then([](http_response response) {

Release/tests/functional/http/listener/to_string_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ SUITE(to_string_tests)
3636
// to string
3737
http_response resp(status_codes::PartialContent);
3838
resp.set_body(U("data"));
39-
VERIFY_ARE_EQUAL(U("HTTP/1.1 206 Partial Content\r\nContent-Length: 4\r\nContent-Type: text/plain; "
40-
"charset=utf-8\r\n\r\ndata"),
39+
VERIFY_ARE_EQUAL(U("HTTP/1.1 206 Partial Content\r\nContent-Length: 4\r\nContent-Type: text/plain; ")
40+
U("charset=utf-8\r\n\r\ndata"),
4141
resp.to_string());
4242
}
4343

0 commit comments

Comments
 (0)