Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build breaks on GCC 5.4, iOS, and OSX #894

Merged
merged 12 commits into from
Oct 9, 2018
6 changes: 5 additions & 1 deletion Release/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message("-- Setting gcc options")

set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -Wno-format-truncation)
set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0")
set(WARNINGS ${WARNINGS} -Wno-format-truncation)
endif()

set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")
Expand Down
10 changes: 5 additions & 5 deletions Release/include/cpprest/http_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class decompress_factory
{
public:
virtual const utility::string_t& algorithm() const = 0;
virtual const uint16_t weight() const = 0;
virtual uint16_t weight() const = 0;
virtual std::unique_ptr<decompress_provider> make_decompressor() const = 0;
virtual ~decompress_factory() = default;
};
Expand All @@ -117,9 +117,9 @@ _ASYNCRTIMP bool supported();
/// </summary>
namespace algorithm
{
constexpr utility::char_t *GZIP = _XPLATSTR("gzip");
constexpr utility::char_t *DEFLATE = _XPLATSTR("deflate");
constexpr utility::char_t *BROTLI = _XPLATSTR("br");
constexpr const utility::char_t *GZIP = _XPLATSTR("gzip");
constexpr const utility::char_t *DEFLATE = _XPLATSTR("deflate");
constexpr const utility::char_t *BROTLI = _XPLATSTR("br");

/// <summary>
/// Test whether cpprestsdk was built with built-in compression support and
Expand All @@ -129,7 +129,7 @@ constexpr utility::char_t *BROTLI = _XPLATSTR("br");
/// the supplied string matches a supported built-in algorithm, and false if not.</returns>
/// <summary>
_ASYNCRTIMP bool supported(const utility::string_t& algorithm);
};
}

/// <summary>
/// Factory function to instantiate a built-in compression provider with default parameters by compression algorithm
Expand Down
62 changes: 31 additions & 31 deletions Release/include/cpprest/http_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@ bool bind(const key_type &text, utility::string_t &ref) //const
return true;
}

namespace details
{
template<typename key_type, typename _t>
bool bind_impl(const key_type &text, _t &ref)
{
utility::istringstream_t iss(text);
iss.imbue(std::locale::classic());
iss >> ref;
if (iss.fail() || !iss.eof())
{
return false;
}

return true;
}

template<typename key_type>
bool bind_impl(const key_type &text, utf16string &ref)
{
ref = utility::conversions::to_utf16string(text);
return true;
}

template<typename key_type>
bool bind_impl(const key_type &text, std::string &ref)
{
ref = utility::conversions::to_utf8string(text);
return true;
}
}

/// <summary>
/// Represents HTTP headers, acts like a map.
/// </summary>
Expand Down Expand Up @@ -288,35 +319,4 @@ class http_headers
// Headers are stored in a map with case insensitive key.
inner_container m_headers;
};

namespace details
{
template<typename key_type, typename _t>
bool bind_impl(const key_type &text, _t &ref)
{
utility::istringstream_t iss(text);
iss.imbue(std::locale::classic());
iss >> ref;
if (iss.fail() || !iss.eof())
{
return false;
}

return true;
}

template<typename key_type>
bool bind_impl(const key_type &text, utf16string &ref)
{
ref = utility::conversions::to_utf16string(text);
return true;
}

template<typename key_type>
bool bind_impl(const key_type &text, std::string &ref)
{
ref = utility::conversions::to_utf8string(text);
return true;
}
}
}}
1 change: 1 addition & 0 deletions Release/src/http/client/http_client_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,7 @@ class asio_context final : public request_context, public std::enable_shared_fro
.then([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS](
pplx::task<size_t> op) {
size_t writtenSize = 0;
(void)writtenSize;
try
{
writtenSize = op.get();
Expand Down
17 changes: 14 additions & 3 deletions Release/src/http/common/http_compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ class generic_decompress_factory : public decompress_factory

const utility::string_t& algorithm() const { return m_algorithm; }

const uint16_t weight() const { return m_weight; }
uint16_t weight() const { return m_weight; }

std::unique_ptr<decompress_provider> make_decompressor() const { return _make_decompressor(); }

Expand Down Expand Up @@ -753,6 +753,10 @@ std::unique_ptr<compress_provider> make_gzip_compressor(int compressionLevel, in
#if defined(CPPREST_HTTP_COMPRESSION)
return std::move(std::make_unique<gzip_compressor>(compressionLevel, method, strategy, memLevel));
#else // CPPREST_HTTP_COMPRESSION
(void)compressionLevel;
(void)method;
(void)strategy;
(void)memLevel;
return std::unique_ptr<compress_provider>();
#endif // CPPREST_HTTP_COMPRESSION
}
Expand All @@ -762,6 +766,10 @@ std::unique_ptr<compress_provider> make_deflate_compressor(int compressionLevel,
#if defined(CPPREST_HTTP_COMPRESSION)
return std::move(std::make_unique<deflate_compressor>(compressionLevel, method, strategy, memLevel));
#else // CPPREST_HTTP_COMPRESSION
(void)compressionLevel;
(void)method;
(void)strategy;
(void)memLevel;
return std::unique_ptr<compress_provider>();
#endif // CPPREST_HTTP_COMPRESSION
}
Expand All @@ -771,6 +779,9 @@ std::unique_ptr<compress_provider> make_brotli_compressor(uint32_t window, uint3
#if defined(CPPREST_HTTP_COMPRESSION) && defined(CPPREST_BROTLI_COMPRESSION)
return std::move(std::make_unique<brotli_compressor>(window, quality, mode));
#else // CPPREST_BROTLI_COMPRESSION
(void)window;
(void)quality;
(void)mode;
return std::unique_ptr<compress_provider>();
#endif // CPPREST_BROTLI_COMPRESSION
}
Expand Down Expand Up @@ -800,7 +811,7 @@ const std::vector<std::shared_ptr<decompress_factory>> get_decompress_factories(
}
} // namespace builtin

static bool is_http_whitespace(utility::char_t ch) { return ch == _XPLATSTR(' ') || ch == _XPLATSTR('\t'); }
static bool is_http_whitespace(const utility::char_t ch) { return ch == _XPLATSTR(' ') || ch == _XPLATSTR('\t'); }

static void remove_surrounding_http_whitespace(const utility::string_t& encoding, size_t& start, size_t& length)
{
Expand Down Expand Up @@ -1084,7 +1095,7 @@ utility::string_t build_supported_header(header_types type,
// Add all specified algorithms and their weights to the header
start = true;
os.imbue(std::locale::classic());
for each (auto& factory in f)
for (auto& factory : f)
{
if (factory)
{
Expand Down
2 changes: 1 addition & 1 deletion Release/src/http/common/internal_http_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool validate_method(const utility::string_t& method);

namespace web { namespace http { namespace compression {

class compression::decompress_factory;
class decompress_factory;

namespace details { namespace builtin {

Expand Down
45 changes: 23 additions & 22 deletions Release/tests/functional/http/client/compression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "cpprest/details/http_helpers.h"
#include "cpprest/version.h"
#include "cpprest/asyncrt_utils.h"
#include "stdafx.h"
#include <fstream>

Expand Down Expand Up @@ -202,16 +203,16 @@ SUITE(compression_tests)
std::vector<uint8_t> dcmp_buffer;
web::http::compression::operation_result r;
std::vector<size_t> chunk_sizes;
Concurrency::task_group_status result;
pplx::task_status result;
size_t csize;
size_t dsize;
size_t i;
size_t nn;

if (algorithm == fake_provider::FAKE)
{
compressor = std::make_unique<fake_provider>(buffer_size);
decompressor = std::make_unique<fake_provider>(buffer_size);
compressor = utility::details::make_unique<fake_provider>(buffer_size);
decompressor = utility::details::make_unique<fake_provider>(buffer_size);
}
else
{
Expand Down Expand Up @@ -247,7 +248,7 @@ SUITE(compression_tests)
web::http::compression::operation_hint::has_more)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
VERIFY_ARE_EQUAL(r.input_bytes_processed, std::min(chunk_size, buffer_size - i));
VERIFY_ARE_EQUAL(r.done, false);
chunk_sizes.push_back(r.output_bytes_produced);
Expand All @@ -272,7 +273,7 @@ SUITE(compression_tests)
web::http::compression::operation_hint::is_last)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
chunk_sizes.push_back(r.output_bytes_produced);
csize += r.output_bytes_produced;
Expand All @@ -283,7 +284,7 @@ SUITE(compression_tests)
result = compressor->compress(NULL, 0, NULL, 0, web::http::compression::operation_hint::is_last)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
VERIFY_ARE_EQUAL(r.done, true);
Expand Down Expand Up @@ -311,7 +312,7 @@ SUITE(compression_tests)
hint)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
nn += *it;
dsize += r.output_bytes_produced;
}
Expand Down Expand Up @@ -339,7 +340,7 @@ SUITE(compression_tests)
web::http::compression::operation_hint::has_more)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
dsize += r.output_bytes_produced;
nn += r.input_bytes_processed;
n -= r.input_bytes_processed;
Expand All @@ -354,7 +355,7 @@ SUITE(compression_tests)
result = decompressor->decompress(NULL, 0, NULL, 0, web::http::compression::operation_hint::has_more)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
VERIFY_IS_TRUE(r.done);
Expand All @@ -370,7 +371,7 @@ SUITE(compression_tests)
web::http::compression::operation_hint::is_last)
.then([&r](web::http::compression::operation_result x) { r = x; })
.wait();
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
VERIFY_ARE_EQUAL(r.output_bytes_produced, buffer_size);
VERIFY_ARE_EQUAL(input_buffer, dcmp_buffer);

Expand Down Expand Up @@ -448,28 +449,28 @@ SUITE(compression_tests)

std::shared_ptr<web::http::compression::compress_factory> fcf = web::http::compression::make_compress_factory(
fake_provider::FAKE, []() -> std::unique_ptr<web::http::compression::compress_provider> {
return std::make_unique<fake_provider>();
return utility::details::make_unique<fake_provider>();
});
std::vector<std::shared_ptr<web::http::compression::compress_factory>> fcv;
fcv.push_back(fcf);
std::shared_ptr<web::http::compression::decompress_factory> fdf =
web::http::compression::make_decompress_factory(
fake_provider::FAKE, 800, []() -> std::unique_ptr<web::http::compression::decompress_provider> {
return std::make_unique<fake_provider>();
return utility::details::make_unique<fake_provider>();
});
std::vector<std::shared_ptr<web::http::compression::decompress_factory>> fdv;
fdv.push_back(fdf);

std::shared_ptr<web::http::compression::compress_factory> ncf = web::http::compression::make_compress_factory(
_NONE, []() -> std::unique_ptr<web::http::compression::compress_provider> {
return std::make_unique<fake_provider>();
return utility::details::make_unique<fake_provider>();
});
std::vector<std::shared_ptr<web::http::compression::compress_factory>> ncv;
ncv.push_back(ncf);
std::shared_ptr<web::http::compression::decompress_factory> ndf =
web::http::compression::make_decompress_factory(
_NONE, 800, []() -> std::unique_ptr<web::http::compression::decompress_provider> {
return std::make_unique<fake_provider>();
return utility::details::make_unique<fake_provider>();
});
std::vector<std::shared_ptr<web::http::compression::decompress_factory>> ndv;
ndv.push_back(ndf);
Expand Down Expand Up @@ -794,7 +795,7 @@ SUITE(compression_tests)
{
test_http_server* p_server = nullptr;
std::unique_ptr<test_http_server::scoped_server> scoped =
std::move(std::make_unique<test_http_server::scoped_server>(m_uri));
std::move(utility::details::make_unique<test_http_server::scoped_server>(m_uri));
scoped->server()->next_request().then([&skip_transfer_put](pplx::task<test_request*> op) {
try
{
Expand All @@ -810,7 +811,7 @@ SUITE(compression_tests)

http_client client(m_uri);
http_request msg(methods::PUT);
msg.set_compressor(std::make_unique<fake_provider>(0));
msg.set_compressor(utility::details::make_unique<fake_provider>(0));
msg.set_body(concurrency::streams::rawptr_stream<uint8_t>::open_istream((const uint8_t*)nullptr, 0));
http_response rsp = client.request(msg).get();
rsp.content_ready().wait();
Expand Down Expand Up @@ -872,7 +873,7 @@ SUITE(compression_tests)
if (encoding.find(fake_provider::FAKE) != utility::string_t::npos)
{
// This one won't be found in the server's default set...
rsp._get_impl()->set_compressor(std::make_unique<fake_provider>(buffer_size));
rsp._get_impl()->set_compressor(utility::details::make_unique<fake_provider>(buffer_size));
}
#endif // _WIN32
rsp.set_body(
Expand Down Expand Up @@ -913,7 +914,7 @@ SUITE(compression_tests)
}
else
{
scoped = std::move(std::make_unique<test_http_server::scoped_server>(m_uri));
scoped = std::move(utility::details::make_unique<test_http_server::scoped_server>(m_uri));
p_server = scoped->server();
}

Expand Down Expand Up @@ -968,12 +969,12 @@ SUITE(compression_tests)
fake_provider::FAKE,
1000,
[buffer_size]() -> std::unique_ptr<web::http::compression::decompress_provider> {
return std::make_unique<fake_provider>(buffer_size);
return utility::details::make_unique<fake_provider>(buffer_size);
});
dfactories.push_back(dmap[fake_provider::FAKE]);
cfactories.push_back(web::http::compression::make_compress_factory(
fake_provider::FAKE, [buffer_size]() -> std::unique_ptr<web::http::compression::compress_provider> {
return std::make_unique<fake_provider>(buffer_size);
return utility::details::make_unique<fake_provider>(buffer_size);
}));

v.resize(buffer_size);
Expand Down Expand Up @@ -1037,7 +1038,7 @@ SUITE(compression_tests)
if (algorithm == fake_provider::FAKE)
{
VERIFY_IS_FALSE((bool)c);
c = std::make_unique<fake_provider>(buffer_size);
c = utility::details::make_unique<fake_provider>(buffer_size);
}
VERIFY_IS_TRUE((bool)c);
auto got = c->compress(v.data(),
Expand Down Expand Up @@ -1069,7 +1070,7 @@ SUITE(compression_tests)
VERIFY_ARE_EQUAL(boo, algorithm != fake_provider::FAKE);
if (algorithm == fake_provider::FAKE)
{
msg.set_compressor(std::make_unique<fake_provider>(buffer_size));
msg.set_compressor(utility::details::make_unique<fake_provider>(buffer_size));
}
}
else
Expand Down