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

* Move up bind_impl so that it can be found by non-MSVC.

* Avoid useless qualification making GCC unhappy.

* Make GZIP/DEFLATE/BROTLI constant chars.

* Remove unneeded ;

* Remove broken qualification attempting to forward declare web::http::compression::decompress_factory.

* Don't use nonstandard for each.

* Remove another unnecessary const.

* Mark unused parameters with (void).

* Guard -Wno-format-truncation from GCC 5.4.

* Fix bogus writtenSize warning from GCC 5.4.

* Attempt to avoid std::make_unique in compression tests.

* Avoid Concurrency::task_group_status because gcc 5.4 hates it for some reason.
This commit is contained in:
Billy O'Neal 2018-10-08 19:25:17 -07:00 коммит произвёл GitHub
Родитель 74da3723c6
Коммит ed94a6cddb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 80 добавлений и 63 удалений

Просмотреть файл

@ -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")

Просмотреть файл

@ -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;
};
@ -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
@ -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

Просмотреть файл

@ -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>
@ -288,35 +319,4 @@ private:
// 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;
}
}
}}

Просмотреть файл

@ -1754,6 +1754,7 @@ private:
.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();

Просмотреть файл

@ -620,7 +620,7 @@ public:
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(); }
@ -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
}
@ -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
}
@ -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
}
@ -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)
{
@ -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)
{

Просмотреть файл

@ -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 {

Просмотреть файл

@ -13,6 +13,7 @@
#include "cpprest/details/http_helpers.h"
#include "cpprest/version.h"
#include "cpprest/asyncrt_utils.h"
#include "stdafx.h"
#include <fstream>
@ -202,7 +203,7 @@ 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;
@ -210,8 +211,8 @@ SUITE(compression_tests)
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
{
@ -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);
@ -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;
@ -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);
@ -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;
}
@ -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;
@ -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);
@ -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);
@ -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);
@ -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
{
@ -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();
@ -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(
@ -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();
}
@ -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);
@ -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(),
@ -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