From f77ee7bdd1997cf7fc45debc7bf3f3a5aa86bf26 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Mon, 27 Nov 2023 03:02:11 +0100 Subject: [PATCH] More fixes. --- include/pqxx/cursor.hxx | 2 +- include/pqxx/internal/result_iterator.hxx | 8 ++++---- include/pqxx/row.hxx | 8 ++++---- src/connection.cxx | 7 ++++--- src/cursor.cxx | 4 ++-- src/params.cxx | 4 ++-- src/pipeline.cxx | 14 +++++++++----- src/result.cxx | 18 ++++++++---------- src/row.cxx | 8 ++++---- src/stream_from.cxx | 4 ++-- src/stream_to.cxx | 3 ++- src/wait.cxx | 3 ++- 12 files changed, 44 insertions(+), 39 deletions(-) diff --git a/include/pqxx/cursor.hxx b/include/pqxx/cursor.hxx index 2f9786758..1bc933188 100644 --- a/include/pqxx/cursor.hxx +++ b/include/pqxx/cursor.hxx @@ -448,7 +448,7 @@ public: return &m_here; } icursor_iterator &operator++(); - icursor_iterator operator++(int); + icursor_iterator operator++(int) &; icursor_iterator &operator+=(difference_type); icursor_iterator &operator=(icursor_iterator const &) noexcept; diff --git a/include/pqxx/internal/result_iterator.hxx b/include/pqxx/internal/result_iterator.hxx index baa102012..7ff47a7a8 100644 --- a/include/pqxx/internal/result_iterator.hxx +++ b/include/pqxx/internal/result_iterator.hxx @@ -105,13 +105,13 @@ public: return *this; } - const_result_iterator operator++(int); + const_result_iterator operator++(int) &; const_result_iterator &operator++() { ++m_index; return *this; } - const_result_iterator operator--(int); + const_result_iterator operator--(int) &; const_result_iterator &operator--() { --m_index; @@ -264,13 +264,13 @@ public: iterator_type::operator--(); return *this; } - const_reverse_result_iterator operator++(int); + const_reverse_result_iterator operator++(int) &; const_reverse_result_iterator &operator--() { iterator_type::operator++(); return *this; } - const_reverse_result_iterator operator--(int); + const_reverse_result_iterator operator--(int) &; const_reverse_result_iterator &operator+=(difference_type i) { iterator_type::operator-=(i); diff --git a/include/pqxx/row.hxx b/include/pqxx/row.hxx index cf4257d88..d94494b0e 100644 --- a/include/pqxx/row.hxx +++ b/include/pqxx/row.hxx @@ -314,13 +314,13 @@ public: const_row_iterator &operator=(const_row_iterator const &) noexcept = default; const_row_iterator &operator=(const_row_iterator &&) noexcept = default; - const_row_iterator operator++(int) noexcept; + const_row_iterator operator++(int) & noexcept; const_row_iterator &operator++() noexcept { ++m_col; return *this; } - const_row_iterator operator--(int) noexcept; + const_row_iterator operator--(int) & noexcept; const_row_iterator &operator--() noexcept { --m_col; @@ -441,13 +441,13 @@ public: iterator_type::operator--(); return *this; } - const_reverse_row_iterator operator++(int) noexcept; + const_reverse_row_iterator operator++(int) & noexcept; const_reverse_row_iterator &operator--() noexcept { iterator_type::operator++(); return *this; } - const_reverse_row_iterator operator--(int); + const_reverse_row_iterator operator--(int) &; const_reverse_row_iterator &operator+=(difference_type i) noexcept { iterator_type::operator-=(i); diff --git a/src/connection.cxx b/src/connection.cxx index d64f35068..8ae284de5 100644 --- a/src/connection.cxx +++ b/src/connection.cxx @@ -477,6 +477,7 @@ void wrap_pgfreecancel(PGcancel *ptr) } +/// A fairly arbitrary buffer size for error strings and such. constexpr int buf_size{500u}; } // namespace @@ -489,7 +490,7 @@ void PQXX_COLD pqxx::connection::cancel_query() PQXX_UNLIKELY throw std::bad_alloc{}; - std::array errbuf; + std::array errbuf{}; auto const err{errbuf.data()}; auto const c{PQcancel(cancel.get(), err, buf_size)}; if (c == 0) @@ -506,13 +507,13 @@ void pqxx::connection::set_blocking(bool block) & unsigned long mode{not block}; if (::ioctlsocket(fd, FIONBIO, &mode) != 0) { - std::array errbuf; + std::array errbuf{}; char const *err{pqxx::internal::error_string(WSAGetLastError(), errbuf)}; throw broken_connection{ internal::concat("Could not set socket's blocking mode: ", err)}; } # else // _WIN32 - std::array errbuf; + std::array errbuf{}; auto flags{::fcntl(fd, F_GETFL, 0)}; if (flags == -1) { diff --git a/src/cursor.cxx b/src/cursor.cxx index 1499598d7..f7a79bc21 100644 --- a/src/cursor.cxx +++ b/src/cursor.cxx @@ -224,9 +224,9 @@ pqxx::icursor_iterator::~icursor_iterator() noexcept } -pqxx::icursor_iterator pqxx::icursor_iterator::operator++(int) +pqxx::icursor_iterator pqxx::icursor_iterator::operator++(int) & { - icursor_iterator old{*this}; + icursor_iterator const old{*this}; m_pos = difference_type( pqxx::internal::gate::icursorstream_icursor_iterator{*m_stream}.forward()); m_here.clear(); diff --git a/src/params.cxx b/src/params.cxx index 19896346c..fd1251d2f 100644 --- a/src/params.cxx +++ b/src/params.cxx @@ -80,7 +80,7 @@ void pqxx::params::append(std::basic_string &&value) & void PQXX_COLD pqxx::params::append(binarystring const &value) & { - m_params.push_back(entry{value.bytes_view()}); + m_params.emplace_back(value.bytes_view()); } @@ -88,7 +88,7 @@ void pqxx::params::append(params &&value) & { this->reserve(std::size(value.m_params) + std::size(this->m_params)); for (auto const ¶m : value.m_params) - m_params.emplace_back(std::move(param)); + m_params.emplace_back(param); value.m_params.clear(); } diff --git a/src/pipeline.cxx b/src/pipeline.cxx index 2a47faa90..63a9c38d4 100644 --- a/src/pipeline.cxx +++ b/src/pipeline.cxx @@ -25,11 +25,15 @@ #include "pqxx/internal/header-post.hxx" +using namespace std::literals::string_view_literals; + + namespace { -std::string const theSeparator{"; "}; -std::string const theDummyValue{"1"}; -std::string const theDummyQuery{"SELECT " + theDummyValue + theSeparator}; +constexpr std::string_view + theSeparator{"; "sv}, + theDummyValue{"1"sv}, + theDummyQuery{"SELECT 1; "sv}; } // namespace @@ -209,7 +213,7 @@ void pqxx::pipeline::issue() QueryMap::size_type(std::distance(oldest, std::end(m_queries)))}; bool const prepend_dummy{num_issued > 1}; if (prepend_dummy) - cum = theDummyQuery + cum; + cum = pqxx::internal::concat(theDummyQuery, cum); pqxx::internal::gate::connection_pipeline{m_trans->conn()}.start_exec( cum.c_str()); @@ -300,7 +304,7 @@ void pqxx::pipeline::obtain_dummy() PQXX_UNLIKELY internal_error("Unexpected result for dummy query in pipeline."); - if (R.at(0).at(0).as() != theDummyValue) + if (R.at(0).at(0).as() != theDummyValue) PQXX_UNLIKELY internal_error("Dummy query in pipeline returned unexpected value."); return; diff --git a/src/result.cxx b/src/result.cxx index f0680a724..673bb9cbe 100644 --- a/src/result.cxx +++ b/src/result.cxx @@ -319,8 +319,6 @@ std::string pqxx::result::status_error() const case PGRES_EMPTY_QUERY: // The string sent to the backend was empty. case PGRES_COMMAND_OK: // Successful completion, no result data. case PGRES_TUPLES_OK: // The query successfully executed. - break; - case PGRES_COPY_OUT: // Copy Out (from server) data transfer started. case PGRES_COPY_IN: // Copy In (to server) data transfer started. case PGRES_COPY_BOTH: // Copy In/Out. Used for streaming replication. @@ -524,17 +522,17 @@ int pqxx::result::column_type_modifier( // const_result_iterator -pqxx::const_result_iterator pqxx::const_result_iterator::operator++(int) +pqxx::const_result_iterator pqxx::const_result_iterator::operator++(int) & { - const_result_iterator old{*this}; + const_result_iterator const old{*this}; m_index++; return old; } -pqxx::const_result_iterator pqxx::const_result_iterator::operator--(int) +pqxx::const_result_iterator pqxx::const_result_iterator::operator--(int) & { - const_result_iterator old{*this}; + const_result_iterator const old{*this}; m_index--; return old; } @@ -549,18 +547,18 @@ pqxx::result::const_reverse_iterator::base() const noexcept pqxx::const_reverse_result_iterator -pqxx::const_reverse_result_iterator::operator++(int) +pqxx::const_reverse_result_iterator::operator++(int) & { - const_reverse_result_iterator tmp{*this}; + const_reverse_result_iterator const tmp{*this}; iterator_type::operator--(); return tmp; } pqxx::const_reverse_result_iterator -pqxx::const_reverse_result_iterator::operator--(int) +pqxx::const_reverse_result_iterator::operator--(int) & { - const_reverse_result_iterator tmp{*this}; + const_reverse_result_iterator const tmp{*this}; iterator_type::operator++(); return tmp; } diff --git a/src/row.cxx b/src/row.cxx index 890b21aab..4bb68a66e 100644 --- a/src/row.cxx +++ b/src/row.cxx @@ -208,7 +208,7 @@ bool PQXX_COLD pqxx::row::empty() const noexcept } -pqxx::const_row_iterator pqxx::const_row_iterator::operator++(int) noexcept +pqxx::const_row_iterator pqxx::const_row_iterator::operator++(int) & noexcept { auto const old{*this}; m_col++; @@ -216,7 +216,7 @@ pqxx::const_row_iterator pqxx::const_row_iterator::operator++(int) noexcept } -pqxx::const_row_iterator pqxx::const_row_iterator::operator--(int) noexcept +pqxx::const_row_iterator pqxx::const_row_iterator::operator--(int) & noexcept { auto const old{*this}; m_col--; @@ -233,7 +233,7 @@ pqxx::const_reverse_row_iterator::base() const noexcept pqxx::const_reverse_row_iterator -pqxx::const_reverse_row_iterator::operator++(int) noexcept +pqxx::const_reverse_row_iterator::operator++(int) & noexcept { auto tmp{*this}; operator++(); @@ -242,7 +242,7 @@ pqxx::const_reverse_row_iterator::operator++(int) noexcept pqxx::const_reverse_row_iterator -pqxx::const_reverse_row_iterator::operator--(int) +pqxx::const_reverse_row_iterator::operator--(int) & { auto tmp{*this}; operator--(); diff --git a/src/stream_from.cxx b/src/stream_from.cxx index 88d018533..8dc379236 100644 --- a/src/stream_from.cxx +++ b/src/stream_from.cxx @@ -245,7 +245,7 @@ void pqxx::stream_from::parse_line() // Would love to emplace_back() here, but gcc 9.1 warns about the // constructor not throwing. It suggests adding "noexcept." Which // we can hardly do, without std::string_view guaranteeing it. - m_fields.push_back(zview{field_begin, write - field_begin}); + m_fields.emplace_back(field_begin, write - field_begin); *write++ = '\0'; } // Set up for the next field. @@ -280,7 +280,7 @@ void pqxx::stream_from::parse_line() } else { - m_fields.push_back(zview{field_begin, write - field_begin}); + m_fields.emplace_back(field_begin, write - field_begin); *write++ = '\0'; } diff --git a/src/stream_to.cxx b/src/stream_to.cxx index 68afb4c79..270e0a615 100644 --- a/src/stream_to.cxx +++ b/src/stream_to.cxx @@ -50,7 +50,8 @@ char escape_char(char special) } PQXX_UNLIKELY throw pqxx::internal_error{pqxx::internal::concat( "Stream escaping unexpectedly stopped at '", - static_cast(static_cast(special)))}; + static_cast(static_cast(special)), + "'.")}; } } // namespace diff --git a/src/wait.cxx b/src/wait.cxx index d095e3295..ac4ae7201 100644 --- a/src/wait.cxx +++ b/src/wait.cxx @@ -128,7 +128,8 @@ void pqxx::internal::wait_fd( if (code == -1) { - std::array errbuf; + constexpr std::size_t buf_size{200u}; + std::array errbuf{}; int const err_code { #if defined(_WIN32) && (_WIN32_WINNT >= 0x0600)