Skip to content

Use std::array::const_iterator instead of raw char pointer. #652

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

Merged

Conversation

glynos
Copy link
Member

@glynos glynos commented May 13, 2016

There was a mismatch in the iterator type. I don't have access to VS2015, so it is as yet untested.

@glynos
Copy link
Member Author

glynos commented May 13, 2016

This might address #651.

@deanberris
Copy link
Member

LGTM

I think this should do it. Let's cross our fingers and hope it does...

There are a few duplicate issues too so we should probably triage those and merge into a single one.

@deanberris deanberris merged commit b6f27e0 into cpp-netlib:0.12-release May 16, 2016
@glynos glynos deleted the vs2015_compilation_failure branch May 18, 2016 18:54
@sneves
Copy link

sneves commented Jun 10, 2016

This is not a complete fix. Compiling, for example, the http_client example, you run into more errors of the same kind:

C:\cpp-netlib\boost/network/protocol/http/policies/async_connection.hpp(60): error C2664: 'boost::network::http::basic_response<Tag> boost::network::http::impl::async_connection_base<Tag,1,1>::start(const boost::network::http::basic_request<Tag> &,const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,bool,std::function<void (const boost::iterator_range<std::_Array_const_iterator<_Ty,1024>> &,const std::error_code &)>,std::function<bool (std::basic_string<char,std::char_traits<char>,std::allocator<_Ty>> &)>)': cannot convert argument 4 from 'boost::network::http::async_connection_policy<Tag,1,1>::body_callback_function_type' to 'std::function<void (const boost::iterator_range<std::_Array_const_iterator<_Ty,1024>> &,const std::error_code &)>'

It looks like async_connection_policy---and perhaps other classes---still have the old const char * iterator type on their callback type.

Below is a diff (against the 0.12-release branch) that gets around all the compilation errors. I have no idea if it breaks anything, though. Note that the servers.ipp patch is unrelated to this issue, but fixes #662.

diff --git a/boost/network/protocol/http/client/async_impl.hpp b/boost/network/protocol/http/client/async_impl.hpp
index fb1dc50..5fc6d43 100644
--- a/boost/network/protocol/http/client/async_impl.hpp
+++ b/boost/network/protocol/http/client/async_impl.hpp
@@ -31,7 +31,7 @@ struct async_client
   typedef typename resolver<Tag>::type resolver_type;
   typedef typename string<Tag>::type string_type;

-  typedef std::function<void(boost::iterator_range<char const*> const&,
+  typedef std::function<void(boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator> const&,
                              std::error_code const&)>
       body_callback_function_type;

diff --git a/boost/network/protocol/http/client/connection/async_normal.hpp b/boost/network/protocol/http/client/connection/async_normal.hpp
index 240a42a..b3fe72a 100644
--- a/boost/network/protocol/http/client/connection/async_normal.hpp
+++ b/boost/network/protocol/http/client/connection/async_normal.hpp
@@ -128,7 +128,7 @@ struct http_async_connection
     this->destination_promise.set_exception(std::make_exception_ptr(error));
     this->body_promise.set_exception(std::make_exception_ptr(error));
     if ( callback )
-      callback( boost::iterator_range<const char*>(), ec );
+      callback( boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator>(), ec );
     this->timer_.cancel();
   }

@@ -321,7 +321,7 @@ struct http_async_connection
             // body (in the case of a HEAD request).
             this->body_promise.set_value("");
             if ( callback )
-              callback( boost::iterator_range<const char*>(), ::asio::error::eof );
+              callback( boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator>(), ::asio::error::eof );
             this->destination_promise.set_value("");
             this->source_promise.set_value("");
             // this->part.assign('\0');
@@ -392,7 +392,7 @@ struct http_async_connection
             } else {
               string_type body_string;
               std::swap(body_string, this->partial_parsed);
-              body_string.append(this->part.begin(), bytes_transferred);
+              body_string.append(this->part.begin(), this->part.begin() + bytes_transferred);
               if (this->is_chunk_encoding) {
                 this->body_promise.set_value(parse_chunk_encoding(body_string));
               } else {
@@ -468,7 +468,7 @@ struct http_async_connection
             this->body_promise.set_exception(std::make_exception_ptr(error));
           }
           else
-            callback( boost::iterator_range<const char*>(), report_code );
+            callback( boost::iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator>(), report_code );
           break;
         default:
           BOOST_ASSERT(false && "Bug, report this to the developers!");
diff --git a/boost/network/protocol/http/client/connection/async_protocol_handler.hpp b/boost/network/protocol/http/client/connection/async_protocol_handler.hpp
index b350862..5ceb103 100644
--- a/boost/network/protocol/http/client/connection/async_protocol_handler.hpp
+++ b/boost/network/protocol/http/client/connection/async_protocol_handler.hpp
@@ -328,7 +328,7 @@ struct http_async_protocol_handler {
   void parse_body(Delegate& delegate_, Callback callback, size_t bytes) {
     // TODO(dberris): we should really not use a string for the partial body
     // buffer.
-    partial_parsed.append(part_begin, bytes);
+    partial_parsed.append(part_begin, part_begin + bytes);
     part_begin = part.begin();
     delegate_->read_some(
         ::asio::mutable_buffers_1(part.data(), part.size()), callback);
diff --git a/boost/network/protocol/http/client/facade.hpp b/boost/network/protocol/http/client/facade.hpp
index ff05d07..c447dc1 100644
--- a/boost/network/protocol/http/client/facade.hpp
+++ b/boost/network/protocol/http/client/facade.hpp
@@ -45,7 +45,7 @@ class basic_client_facade {
    * body as it comes in. In case of errors, the second argument is an error
    * code.
    */
-  typedef std::function<void(iterator_range<char const*> const&,
+  typedef std::function<void(iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator> const&,
                              std::error_code const&)>
       body_callback_function_type;

diff --git a/boost/network/protocol/http/policies/async_connection.hpp b/boost/network/protocol/http/policies/async_connection.hpp
index 34a1f0c..f1a43a6 100644
--- a/boost/network/protocol/http/policies/async_connection.hpp
+++ b/boost/network/protocol/http/policies/async_connection.hpp
@@ -30,7 +30,7 @@ struct async_connection_policy : resolver_policy<Tag>::type {
   typedef typename resolver_base::resolve_function resolve_function;
   typedef typename resolver_base::resolve_completion_function
       resolve_completion_function;
-  typedef std::function<void(iterator_range<char const*> const&,
+  typedef std::function<void(iterator_range<typename std::array<typename char_<Tag>::type, 1024>::const_iterator> const&,
                              std::error_code const&)>
       body_callback_function_type;
   typedef std::function<bool(string_type&)> body_generator_function_type;
diff --git a/boost/network/protocol/http/server/async_connection.hpp b/boost/network/protocol/http/server/async_connection.hpp
index 915c6fb..e9394c7 100644
--- a/boost/network/protocol/http/server/async_connection.hpp
+++ b/boost/network/protocol/http/server/async_connection.hpp
@@ -579,7 +579,7 @@ struct async_connection
             }
             new_start = std::end(result_range);
             auto self = this->shared_from_this();
-            thread_pool().post([this, self] { handler(request_, self); });
+            thread_pool().post([this, self]() { handler(request_, self); });
             return;
           } else {
             partial_parsed.append(std::begin(result_range),
diff --git a/boost/network/protocol/http/server/impl/parsers.ipp b/boost/network/protocol/http/server/impl/parsers.ipp
index b0de375..b3f733a 100644
--- a/boost/network/protocol/http/server/impl/parsers.ipp
+++ b/boost/network/protocol/http/server/impl/parsers.ipp
@@ -56,9 +56,9 @@ BOOST_NETWORK_INLINE void parse_version(

 BOOST_NETWORK_INLINE void parse_headers(
     std::string const& input, std::vector<request_header_narrow>& container) {
-  using namespace boost::spirit::qi;
   u8_to_u32_iterator<std::string::const_iterator> begin = input.begin(),
                                                   end = input.end();
+  using namespace boost::spirit::qi;
   typedef as<boost::spirit::traits::u32_string> as_u32_string;
   parse(begin, end,
         *(+((alnum | punct) - ':') >> lit(": ") >>

@deanberris
Copy link
Member

Thanks @sneves -- can you please send a pull request instead of in-lining a patch? Would appreciate it very much.

@sneves
Copy link

sneves commented Jun 15, 2016

Well, I'm not sure a pull request is warranted. That patch does get you to a successful compilation, but the HTTP client tests (client_get_*) fail afterwards.

It appears that the assumption std::array<char, N>::const_iterator = const char * is made all over the place, and this is not the case in Visual Studio, which has a dedicated iterator class. I don't know how to fix this without it becoming a huge time sink.

@yuyoyuppe
Copy link

any update on this?

@deanberris
Copy link
Member

@yuyoyuppe Unfortunately I haven't had time to work on this. If you can, I'd certainly appreciate a pull request and I'll review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants