Skip to content

Commit

Permalink
More fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Dec 23, 2023
1 parent 3a67c92 commit f77ee7b
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion include/pqxx/cursor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions include/pqxx/internal/result_iterator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions include/pqxx/row.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -489,7 +490,7 @@ void PQXX_COLD pqxx::connection::cancel_query()
PQXX_UNLIKELY
throw std::bad_alloc{};

std::array<char, buf_size> errbuf;
std::array<char, buf_size> errbuf{};
auto const err{errbuf.data()};
auto const c{PQcancel(cancel.get(), err, buf_size)};
if (c == 0)
Expand All @@ -506,13 +507,13 @@ void pqxx::connection::set_blocking(bool block) &
unsigned long mode{not block};
if (::ioctlsocket(fd, FIONBIO, &mode) != 0)
{
std::array<char, buf_size> errbuf;
std::array<char, buf_size> 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<char, buf_size> errbuf;
std::array<char, buf_size> errbuf{};
auto flags{::fcntl(fd, F_GETFL, 0)};
if (flags == -1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cursor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/params.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ void pqxx::params::append(std::basic_string<std::byte> &&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());
}


void pqxx::params::append(params &&value) &
{
this->reserve(std::size(value.m_params) + std::size(this->m_params));
for (auto const &param : value.m_params)
m_params.emplace_back(std::move(param));
m_params.emplace_back(param);
value.m_params.clear();
}

Expand Down
14 changes: 9 additions & 5 deletions src/pipeline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<std::string>() != theDummyValue)
if (R.at(0).at(0).as<std::string_view>() != theDummyValue)
PQXX_UNLIKELY
internal_error("Dummy query in pipeline returned unexpected value.");
return;
Expand Down
18 changes: 8 additions & 10 deletions src/result.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/row.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ 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++;
return old;
}


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--;
Expand All @@ -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++();
Expand All @@ -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--();
Expand Down
4 changes: 2 additions & 2 deletions src/stream_from.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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';
}

Expand Down
3 changes: 2 additions & 1 deletion src/stream_to.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>(static_cast<unsigned char>(special)))};
static_cast<unsigned>(static_cast<unsigned char>(special)),
"'.")};
}
} // namespace

Expand Down
3 changes: 2 additions & 1 deletion src/wait.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ void pqxx::internal::wait_fd(

if (code == -1)
{
std::array<char, 200> errbuf;
constexpr std::size_t buf_size{200u};
std::array<char, buf_size> errbuf{};
int const err_code
{
#if defined(_WIN32) && (_WIN32_WINNT >= 0x0600)
Expand Down

0 comments on commit f77ee7b

Please sign in to comment.