Skip to content

Commit

Permalink
Temporary fix for VS2013. (#1033)
Browse files Browse the repository at this point in the history
* Workaround some VS2013 bugs.

* Fix threadpool.cpp under VS2013.
  • Loading branch information
BillyONeal authored Jan 28, 2019
1 parent 5a885dd commit 4ddaec3
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Release/samples/BlackJack/BlackJack_Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions Release/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions Release/src/http/listener/http_server_httpsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 10 additions & 8 deletions Release/src/pplx/pplxwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
43 changes: 37 additions & 6 deletions Release/src/pplx/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -102,13 +105,21 @@ struct threadpool_impl final : crossplat::threadpool
#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;
};

threadpool_impl& get_shared() { return shared_storage; }

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

~shared_threadpool()
{
Expand All @@ -132,22 +143,34 @@ 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)
{
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)
Expand All @@ -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

Expand Down
37 changes: 20 additions & 17 deletions Release/tests/functional/http/client/oauth1_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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"));
}
}

Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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'.
Expand Down Expand Up @@ -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'.
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Release/tests/functional/http/client/oauth2_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
Expand Down
7 changes: 3 additions & 4 deletions Release/tests/functional/http/client/outside_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions Release/tests/functional/http/listener/to_string_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 4ddaec3

Please sign in to comment.