Temporary fix for VS2013. (#1033)
* Workaround some VS2013 bugs. * Fix threadpool.cpp under VS2013.
This commit is contained in:
Родитель
5a885dd7c7
Коммит
4ddaec3898
|
@ -16,7 +16,7 @@ if(MSVC)
|
|||
set_property(SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/blackjack-server-stdafx.pch")
|
||||
set_property(SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/blackjack-server-stdafx.pch")
|
||||
endif()
|
||||
set_source_files_properties(stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpblackjack-server-stdafx.pch")
|
||||
set_source_files_properties(stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpblackjack-server-stdafx.pch /Zm120")
|
||||
target_sources(blackjackserver PRIVATE stdafx.cpp)
|
||||
target_compile_options(blackjackserver PRIVATE /Yustdafx.h /Fpblackjack-server-stdafx.pch)
|
||||
target_compile_options(blackjackserver PRIVATE /Yustdafx.h /Fpblackjack-server-stdafx.pch /Zm120)
|
||||
endif()
|
||||
|
|
|
@ -179,9 +179,9 @@ if(MSVC)
|
|||
set_property(SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/stdafx.pch")
|
||||
endif()
|
||||
|
||||
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
|
||||
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Zm120")
|
||||
target_sources(cpprest PRIVATE pch/stdafx.cpp)
|
||||
target_compile_options(cpprest PRIVATE /Yustdafx.h)
|
||||
target_compile_options(cpprest PRIVATE /Yustdafx.h /Zm120)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
|
|
|
@ -225,8 +225,8 @@ pplx::task<void> http_windows_server::register_listener(
|
|||
return pplx::task_from_exception<void>(
|
||||
http_exception(errorCode,
|
||||
_XPLATSTR("Access denied: attempting to add Address '") + pListener->uri().to_string() +
|
||||
_XPLATSTR("'. ") _XPLATSTR("Run as administrator to listen on an hostname other "
|
||||
"than localhost, or to listen on port 80.")));
|
||||
_XPLATSTR("'. Run as administrator to listen on an hostname other ")
|
||||
_XPLATSTR("than localhost, or to listen on port 80.")));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -41,7 +41,7 @@ _PPLXIMP size_t __cdecl CaptureCallstack(void** stackData, size_t skipFrames, si
|
|||
#if !defined(__cplusplus_winrt)
|
||||
capturedFrames = RtlCaptureStackBackTrace(
|
||||
static_cast<DWORD>(skipFrames + 1), static_cast<DWORD>(captureFrames), stackData, nullptr);
|
||||
#endif
|
||||
#endif // !__cplusplus_winrt
|
||||
return capturedFrames;
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,9 @@ void InitializeCriticalSection(LPCRITICAL_SECTION _cs)
|
|||
{
|
||||
throw ::std::bad_alloc();
|
||||
}
|
||||
#else
|
||||
#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv
|
||||
InitializeCriticalSectionEx(_cs, 0, 0);
|
||||
#endif // !__cplusplus_winrt
|
||||
#endif // __cplusplus_winrt
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
|
@ -169,7 +169,7 @@ _PPLXIMP void windows_scheduler::schedule(TaskProc_t proc, _In_ void* param)
|
|||
|
||||
Windows::System::Threading::ThreadPool::RunAsync(workItemHandler);
|
||||
}
|
||||
#else
|
||||
#else // ^^^ __cplusplus_winrt ^^^ // vvv !__cplusplus_winrt vvv
|
||||
|
||||
#if _WIN32_WINNT < _WIN32_WINNT_VISTA
|
||||
struct _Scheduler_Param
|
||||
|
@ -202,7 +202,7 @@ _PPLXIMP void windows_scheduler::schedule(TaskProc_t proc, _In_ void* param)
|
|||
throw utility::details::create_system_error(GetLastError());
|
||||
}
|
||||
}
|
||||
#else
|
||||
#else // ^^^ _WIN32_WINNT < _WIN32_WINNT_VISTA ^^^ // vvv _WIN32_WINNT >= _WIN32_WINNT_VISTA vvv
|
||||
struct _Scheduler_Param
|
||||
{
|
||||
TaskProc_t m_proc;
|
||||
|
@ -236,12 +236,12 @@ _PPLXIMP void windows_scheduler::schedule(TaskProc_t proc, _In_ void* param)
|
|||
}
|
||||
#endif // _WIN32_WINNT < _WIN32_WINNT_VISTA
|
||||
|
||||
#endif
|
||||
#endif // __cplusplus_winrt
|
||||
} // namespace details
|
||||
|
||||
} // namespace pplx
|
||||
|
||||
#else
|
||||
#else // ^^^ !defined(_WIN32) || CPPREST_FORCE_PPLX ^^^ // vvv defined(_WIN32) && !CPPREST_FORCE_PPLX vvv
|
||||
namespace Concurrency
|
||||
{
|
||||
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
|
|||
|
||||
const std::shared_ptr<scheduler_interface>& __cdecl get_cpprestsdk_ambient_scheduler()
|
||||
{
|
||||
return pplx::get_ambient_scheduler();
|
||||
const auto& tmp = pplx::get_ambient_scheduler(); // putting this in a temporary reference variable to workaround
|
||||
// VS2013 compiler bugs
|
||||
return tmp;
|
||||
}
|
||||
|
||||
} // namespace Concurrency
|
||||
|
|
|
@ -58,6 +58,9 @@ struct threadpool_impl final : crossplat::threadpool
|
|||
add_thread();
|
||||
}
|
||||
|
||||
threadpool_impl(const threadpool_impl&) = delete;
|
||||
threadpool_impl& operator=(const threadpool_impl&) = delete;
|
||||
|
||||
~threadpool_impl()
|
||||
{
|
||||
m_service.stop();
|
||||
|
@ -102,6 +105,13 @@ private:
|
|||
#if defined(_WIN32)
|
||||
struct shared_threadpool
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
std::aligned_storage<sizeof(threadpool_impl)>::type shared_storage;
|
||||
|
||||
threadpool_impl& get_shared() { return reinterpret_cast<threadpool_impl&>(shared_storage); }
|
||||
|
||||
shared_threadpool(size_t n) { ::new (static_cast<void*>(&shared_storage)) threadpool_impl(n); }
|
||||
#else // ^^^ VS2013 ^^^ // vvv everything else vvv
|
||||
union {
|
||||
threadpool_impl shared_storage;
|
||||
};
|
||||
|
@ -109,6 +119,7 @@ struct shared_threadpool
|
|||
threadpool_impl& get_shared() { return shared_storage; }
|
||||
|
||||
shared_threadpool(size_t n) : shared_storage(n) {}
|
||||
#endif // defined(_MSC_VER) && _MSC_VER < 1900
|
||||
|
||||
~shared_threadpool()
|
||||
{
|
||||
|
@ -132,15 +143,21 @@ namespace
|
|||
template<class T>
|
||||
struct uninitialized
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
typename std::aligned_storage<sizeof(T)>::type storage;
|
||||
|
||||
~uninitialized()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
reinterpret_cast<T&>(storage).~T();
|
||||
}
|
||||
}
|
||||
#else // ^^^ VS2013 ^^^ // vvv everything else vvv
|
||||
union {
|
||||
T storage;
|
||||
};
|
||||
|
||||
bool initialized;
|
||||
|
||||
uninitialized() CPPREST_NOEXCEPT : initialized(false) {}
|
||||
uninitialized(const uninitialized&) = delete;
|
||||
uninitialized& operator=(const uninitialized&) = delete;
|
||||
~uninitialized()
|
||||
{
|
||||
if (initialized)
|
||||
|
@ -148,6 +165,12 @@ struct uninitialized
|
|||
storage.~T();
|
||||
}
|
||||
}
|
||||
#endif // defined(_MSC_VER) && _MSC_VER < 1900
|
||||
|
||||
bool initialized;
|
||||
uninitialized() CPPREST_NOEXCEPT : initialized(false) {}
|
||||
uninitialized(const uninitialized&) = delete;
|
||||
uninitialized& operator=(const uninitialized&) = delete;
|
||||
|
||||
template<class... Args>
|
||||
void construct(Args&&... vals)
|
||||
|
@ -173,7 +196,15 @@ std::pair<bool, platform_shared_threadpool*> initialize_shared_threadpool(size_t
|
|||
initialized_this_time = true;
|
||||
});
|
||||
|
||||
return {initialized_this_time, &uninit_threadpool.storage};
|
||||
return
|
||||
{
|
||||
initialized_this_time,
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
reinterpret_cast<platform_shared_threadpool*>(&uninit_threadpool.storage)
|
||||
#else // ^^^ VS2013 ^^^ // vvv everything else vvv
|
||||
&uninit_threadpool.storage
|
||||
#endif // defined(_MSC_VER) && _MSC_VER < 1900
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ SUITE(oauth1_tests)
|
|||
|
||||
#undef TEST_ACCESSOR
|
||||
|
||||
// clang-format off
|
||||
TEST_FIXTURE(oauth1_token_setup, oauth1_signature_base_string)
|
||||
{
|
||||
// Basic base string generation.
|
||||
|
@ -137,9 +138,9 @@ SUITE(oauth1_tests)
|
|||
|
||||
utility::string_t base_string = m_oauth1_config._build_signature_base_string(r, state);
|
||||
utility::string_t correct_base_string(
|
||||
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%"
|
||||
"3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_"
|
||||
"token%26oauth_version%3D1.0"));
|
||||
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%")
|
||||
U("3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_")
|
||||
U("token%26oauth_version%3D1.0"));
|
||||
VERIFY_ARE_EQUAL(correct_base_string, base_string);
|
||||
}
|
||||
|
||||
|
@ -155,9 +156,9 @@ SUITE(oauth1_tests)
|
|||
|
||||
utility::string_t base_string = m_oauth1_config._build_signature_base_string(r, state);
|
||||
utility::string_t correct_base_string(
|
||||
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%"
|
||||
"3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_test%3Dxyzzy%26oauth_timestamp%3D12345678%"
|
||||
"26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
|
||||
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26oauth_consumer_key%3Dtest_key%26oauth_nonce%")
|
||||
U("3DABCDEFGH%26oauth_signature_method%3DHMAC-SHA1%26oauth_test%3Dxyzzy%26oauth_timestamp%3D12345678%")
|
||||
U("26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
|
||||
VERIFY_ARE_EQUAL(correct_base_string, base_string);
|
||||
}
|
||||
|
||||
|
@ -173,9 +174,9 @@ SUITE(oauth1_tests)
|
|||
|
||||
utility::string_t base_string = m_oauth1_config._build_signature_base_string(r, state);
|
||||
utility::string_t correct_base_string(
|
||||
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26MyVariableOne%3DValueOne%26%26MyVariableTwo%"
|
||||
"3DValueTwo%26oauth_consumer_key%3Dtest_key%26oauth_nonce%3DABCDEFGH%26oauth_signature_method%3DHMAC-"
|
||||
"SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
|
||||
U("POST&http%3A%2F%2Fexample.com%2Frequest&a%3Db%26c%3Dd%26MyVariableOne%3DValueOne%26%26MyVariableTwo%")
|
||||
U("3DValueTwo%26oauth_consumer_key%3Dtest_key%26oauth_nonce%3DABCDEFGH%26oauth_signature_method%3DHMAC-")
|
||||
U("SHA1%26oauth_timestamp%3D12345678%26oauth_token%3Dtest_token%26oauth_version%3D1.0"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,8 +215,8 @@ SUITE(oauth1_tests)
|
|||
m_server.server()->next_request().then([](test_request* request) {
|
||||
const utility::string_t header_authorization(request->m_headers[header_names::authorization]);
|
||||
const utility::string_t prefix(
|
||||
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", "
|
||||
"oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
|
||||
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", ")
|
||||
U("oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
|
||||
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
|
||||
request->reply(status_codes::OK);
|
||||
});
|
||||
|
@ -237,8 +238,8 @@ SUITE(oauth1_tests)
|
|||
m_server.server()->next_request().then([](test_request* request) {
|
||||
const utility::string_t header_authorization(request->m_headers[header_names::authorization]);
|
||||
const utility::string_t prefix(
|
||||
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", "
|
||||
"oauth_signature_method=\"PLAINTEXT\", oauth_timestamp=\""));
|
||||
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"test_token\", ")
|
||||
U("oauth_signature_method=\"PLAINTEXT\", oauth_timestamp=\""));
|
||||
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
|
||||
request->reply(status_codes::OK);
|
||||
});
|
||||
|
@ -254,8 +255,8 @@ SUITE(oauth1_tests)
|
|||
const utility::string_t header_authorization(request->m_headers[header_names::authorization]);
|
||||
|
||||
// Verify prefix, and without 'oauth_token'.
|
||||
const utility::string_t prefix(U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", "
|
||||
"oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
|
||||
const utility::string_t prefix(U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", ")
|
||||
U("oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
|
||||
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
|
||||
|
||||
// Verify suffix with proper 'oauth_callback'.
|
||||
|
@ -285,8 +286,8 @@ SUITE(oauth1_tests)
|
|||
|
||||
// Verify temporary token prefix.
|
||||
const utility::string_t prefix(
|
||||
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"xyzzy\", "
|
||||
"oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
|
||||
U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"xyzzy\", ")
|
||||
U("oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
|
||||
VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));
|
||||
|
||||
// Verify suffix with 'oauth_verifier'.
|
||||
|
@ -313,6 +314,8 @@ SUITE(oauth1_tests)
|
|||
VERIFY_ARE_EQUAL(m_oauth1_config.token().secret(), U("bar"));
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
|
||||
} // SUITE(oauth1_tests)
|
||||
|
||||
} // namespace client
|
||||
|
|
|
@ -130,16 +130,16 @@ SUITE(oauth2_tests)
|
|||
config.set_client_key(U("4567abcd"));
|
||||
config.set_auth_endpoint(U("https://test1"));
|
||||
config.set_redirect_uri(U("http://localhost:8080"));
|
||||
VERIFY_ARE_EQUAL(U("https://test1/?response_type=code&client_id=4567abcd&redirect_uri=http://"
|
||||
"localhost:8080&state=xyzzy&scope=testing_123"),
|
||||
VERIFY_ARE_EQUAL(U("https://test1/?response_type=code&client_id=4567abcd&redirect_uri=http://")
|
||||
U("localhost:8080&state=xyzzy&scope=testing_123"),
|
||||
config.build_authorization_uri(false));
|
||||
}
|
||||
|
||||
// Verify again with implicit grant.
|
||||
{
|
||||
config.set_implicit_grant(true);
|
||||
VERIFY_ARE_EQUAL(U("https://test1/?response_type=token&client_id=4567abcd&redirect_uri=http://"
|
||||
"localhost:8080&state=xyzzy&scope=testing_123"),
|
||||
VERIFY_ARE_EQUAL(U("https://test1/?response_type=token&client_id=4567abcd&redirect_uri=http://")
|
||||
U("localhost:8080&state=xyzzy&scope=testing_123"),
|
||||
config.build_authorization_uri(false));
|
||||
}
|
||||
|
||||
|
@ -190,8 +190,8 @@ SUITE(oauth2_tests)
|
|||
|
||||
VERIFY_ARE_EQUAL(U(""), request->m_headers[header_names::authorization]);
|
||||
|
||||
VERIFY_ARE_EQUAL(to_body_data(U("grant_type=authorization_code&code=789GHI&redirect_uri=https%3A%2F%"
|
||||
"2Fbar&client_id=123ABC&client_secret=456DEF")),
|
||||
VERIFY_ARE_EQUAL(to_body_data(U("grant_type=authorization_code&code=789GHI&redirect_uri=https%3A%2F%")
|
||||
U("2Fbar&client_id=123ABC&client_secret=456DEF")),
|
||||
request->m_body);
|
||||
|
||||
VERIFY_ARE_EQUAL(U("test_user_agent"), get_request_user_agent(request));
|
||||
|
|
|
@ -116,7 +116,7 @@ SUITE(outside_tests)
|
|||
});
|
||||
}
|
||||
|
||||
#if (defined(_MSC_VER) && (_MSC_VER >= 1800)) && !CPPREST_FORCE_PPLX
|
||||
#if (defined(_MSC_VER) && (_MSC_VER >= 1900)) && !CPPREST_FORCE_PPLX
|
||||
TEST_FIXTURE(uri_address, multiple_https_requests_sync_scheduler)
|
||||
{
|
||||
struct sync_scheduler : public scheduler_interface
|
||||
|
@ -175,9 +175,8 @@ SUITE(outside_tests)
|
|||
TEST_FIXTURE(uri_address, no_transfer_encoding_content_length)
|
||||
{
|
||||
handle_timeout([] {
|
||||
http_client client(
|
||||
U("http://ws.audioscrobbler.com/2.0/"
|
||||
"?method=artist.gettoptracks&artist=cher&api_key=6fcd59047568e89b1615975081258990&format=json"));
|
||||
http_client client(U("http://ws.audioscrobbler.com/2.0/") U(
|
||||
"?method=artist.gettoptracks&artist=cher&api_key=6fcd59047568e89b1615975081258990&format=json"));
|
||||
|
||||
client.request(methods::GET)
|
||||
.then([](http_response response) {
|
||||
|
|
|
@ -36,8 +36,8 @@ SUITE(to_string_tests)
|
|||
// to string
|
||||
http_response resp(status_codes::PartialContent);
|
||||
resp.set_body(U("data"));
|
||||
VERIFY_ARE_EQUAL(U("HTTP/1.1 206 Partial Content\r\nContent-Length: 4\r\nContent-Type: text/plain; "
|
||||
"charset=utf-8\r\n\r\ndata"),
|
||||
VERIFY_ARE_EQUAL(U("HTTP/1.1 206 Partial Content\r\nContent-Length: 4\r\nContent-Type: text/plain; ")
|
||||
U("charset=utf-8\r\n\r\ndata"),
|
||||
resp.to_string());
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче