GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use std::array::const_iterator instead of raw char pointer. by glynos · Pull Request #652 · cpp-netlib/cpp-netlib

Conversation

@glynos

@glynos glynos commented May 13, 2016

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@glynos
Use std::array::const_iterator instead of raw char pointer.
464249c
@glynos

glynos commented May 13, 2016

Copy link
Copy Markdown
Member Author

This might address #651.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@deanberris

deanberris commented May 16, 2016

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

sneves commented Jun 10, 2016

Copy link
Copy Markdown

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(": ") >>

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@deanberris

deanberris commented Jun 14, 2016

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sneves

sneves commented Jun 15, 2016

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yuyoyuppe

yuyoyuppe commented Jul 27, 2016

Copy link
Copy Markdown

any update on this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@deanberris

deanberris commented Jul 27, 2016

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yuyoyuppe yuyoyuppe mentioned this pull request Jul 27, 2016
Fix/vs2015 compatibility glynos/cpp-netlib#25
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@glynos @deanberris @sneves @yuyoyuppe
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.