Skip to content

Commit

Permalink
Merge pull request microsoft#609 from garethsb-sony/gcc-4.7
Browse files Browse the repository at this point in the history
Support for GCC 4.7 (and VS2013)
  • Loading branch information
ras0219-msft authored Jan 24, 2018
2 parents b8d1c06 + d0ce63e commit 50e81a5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Release/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -D_GLIBCXX_USE_SCHED_YIELD -D_GLIBCXX_USE_NANOSLEEP")
endif()

elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message("-- Setting msvc options")
Expand Down
45 changes: 36 additions & 9 deletions Release/src/http/client/http_client_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@
#include <unordered_set>
#include <memory>

#if defined(__GNUC__)

#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS
#else
// GCC Bug 56222 - Pointer to member in lambda should not require this to be captured
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56222
// GCC Bug 51494 - Legal program rejection - capturing "this" when using static method inside lambda
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS , this
#endif

#elif defined(_MSC_VER)

#if _MSC_VER >= 1900
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS
#else
// This bug also afflicts VS2013 which incorrectly reports "warning C4573: the usage of 'symbol' requires the compiler to capture 'this' but the current default capture mode does not allow it"
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS , this
#endif

#else

#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS

#endif

using boost::asio::ip::tcp;

#ifdef __ANDROID__
Expand Down Expand Up @@ -621,7 +648,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
proxy_host = utility::conversions::to_utf8string(proxy_uri.host());
}

auto start_http_request_flow = [proxy_type, proxy_host, proxy_port](std::shared_ptr<asio_context> ctx)
auto start_http_request_flow = [proxy_type, proxy_host, proxy_port AND_CAPTURE_MEMBER_FUNCTION_POINTERS](std::shared_ptr<asio_context> ctx)
{
if (ctx->m_request._cancellation_token().is_canceled())
{
Expand Down Expand Up @@ -1011,7 +1038,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
auto readbuf = _get_readbuffer();
uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(chunkSize + http::details::chunked_encoding::additional_encoding_space));
const auto this_request = shared_from_this();
readbuf.getn(buf + http::details::chunked_encoding::data_offset, chunkSize).then([this_request, buf, chunkSize](pplx::task<size_t> op)
readbuf.getn(buf + http::details::chunked_encoding::data_offset, chunkSize).then([this_request, buf, chunkSize AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
{
size_t readSize = 0;
try
Expand Down Expand Up @@ -1068,7 +1095,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
const auto this_request = shared_from_this();
const auto readSize = static_cast<size_t>(std::min(static_cast<uint64_t>(m_http_client->client_config().chunksize()), m_content_length - m_uploaded));
auto readbuf = _get_readbuffer();
readbuf.getn(boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(readSize)), readSize).then([this_request](pplx::task<size_t> op)
readbuf.getn(boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(readSize)), readSize).then([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
{
try
{
Expand Down Expand Up @@ -1371,7 +1398,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
auto shared_decompressed = std::make_shared<data_buffer>(std::move(decompressed));

writeBuffer.putn_nocopy(shared_decompressed->data(), shared_decompressed->size())
.then([this_request, to_read, shared_decompressed](pplx::task<size_t> op)
.then([this_request, to_read, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
{
try
{
Expand All @@ -1389,7 +1416,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
}
else
{
writeBuffer.putn_nocopy(boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data()), to_read).then([this_request, to_read](pplx::task<size_t> op)
writeBuffer.putn_nocopy(boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data()), to_read).then([this_request, to_read AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
{
try
{
Expand Down Expand Up @@ -1486,7 +1513,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
auto shared_decompressed = std::make_shared<data_buffer>(std::move(decompressed));

writeBuffer.putn_nocopy(shared_decompressed->data(), shared_decompressed->size())
.then([this_request, read_size, shared_decompressed](pplx::task<size_t> op)
.then([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
{
size_t writtenSize = 0;
try
Expand All @@ -1508,7 +1535,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
else
{
writeBuffer.putn_nocopy(boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data()), read_size)
.then([this_request](pplx::task<size_t> op)
.then([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
{
size_t writtenSize = 0;
try
Expand Down Expand Up @@ -1559,7 +1586,7 @@ class asio_context : public request_context, public std::enable_shared_from_this

m_timer.expires_from_now(m_duration);
auto ctx = m_ctx;
m_timer.async_wait([ctx](const boost::system::error_code& ec)
m_timer.async_wait([ctx AND_CAPTURE_MEMBER_FUNCTION_POINTERS](const boost::system::error_code& ec)
{
handle_timeout(ec, ctx);
});
Expand All @@ -1574,7 +1601,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
// The existing handler was canceled so schedule a new one.
assert(m_state == started);
auto ctx = m_ctx;
m_timer.async_wait([ctx](const boost::system::error_code& ec)
m_timer.async_wait([ctx AND_CAPTURE_MEMBER_FUNCTION_POINTERS](const boost::system::error_code& ec)
{
handle_timeout(ec, ctx);
});
Expand Down
4 changes: 3 additions & 1 deletion Release/src/websockets/client/ws_client_wspp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
#endif
{}

~wspp_callback_client()
~wspp_callback_client() CPPREST_NOEXCEPT
{
_ASSERTE(m_state < DESTROYED);
std::unique_lock<std::mutex> lock(m_wspp_client_lock);
Expand Down Expand Up @@ -734,6 +734,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
};
struct websocketpp_client : websocketpp_client_base
{
~websocketpp_client() CPPREST_NOEXCEPT {}
websocketpp::client<websocketpp::config::asio_client> & non_tls_client() override
{
return m_client;
Expand All @@ -743,6 +744,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
};
struct websocketpp_tls_client : websocketpp_client_base
{
~websocketpp_tls_client() CPPREST_NOEXCEPT {}
websocketpp::client<websocketpp::config::asio_tls_client> & tls_client() override
{
return m_client;
Expand Down
4 changes: 2 additions & 2 deletions Release/tests/common/TestRunner/test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ testlist_t load_all_tests(test_module_loader& module_loader)
testlist_t testlists;

// Retrieve the static tests and clear for dll loading.
testlists.emplace("<static>", UnitTest::GetTestList());
testlists.insert({ "<static>", UnitTest::GetTestList() });
UnitTest::GetTestList().Clear();

// Cycle through all the test binaries and load them
Expand Down Expand Up @@ -445,7 +445,7 @@ testlist_t load_all_tests(test_module_loader& module_loader)
std::cout << "Loaded " << binary << "..." << std::endl;

// Store the loaded binary into the test list map
testlists.emplace(binary, UnitTest::GetTestList());
testlists.insert({ binary, UnitTest::GetTestList() });
UnitTest::GetTestList().Clear();
}
}
Expand Down
6 changes: 3 additions & 3 deletions Release/tests/functional/json/parsing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ TEST(escaping_control_characters)

for (int i : chars)
{
::utility::stringstream_t ss;
utility::stringstream_t ss;
ss << U("\"\\u") << std::uppercase << std::setfill(U('0')) << std::setw(4) << std::hex << i << U("\"");
const auto &str = ss.str();
auto expectedStr = str;
Expand Down Expand Up @@ -257,8 +257,8 @@ TEST(escaping_control_characters)
}

// Try constructing a json string value directly.
::utility::string_t schar;
schar.push_back(static_cast<::utility::string_t::value_type>(i));
utility::string_t schar;
schar.push_back(static_cast<utility::string_t::value_type>(i));
const auto &sv = json::value::string(schar);
VERIFY_ARE_EQUAL(expectedStr, sv.serialize());

Expand Down

0 comments on commit 50e81a5

Please sign in to comment.