Skip to content

Commit

Permalink
Update config, reformat. (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv authored Dec 22, 2024
1 parent bf6ac20 commit d280c6c
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 111 deletions.
3 changes: 2 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -17135,8 +17135,9 @@ then

# "Iffy" g++ options. Some reasonably current g++-like
# compilers may not support these.
# TODO: Once false positive in std lib is fixed, simplify to "-fanalyzer".
# The -fanalyzer one is a macro option for many of the others.
add_compiler_opts_if_ok \
-fanalyzer \
-Wanalyzer-double-fclose \
-Wanalyzer-double-free \
-Wanalyzer-exposure-through-output-file \
Expand Down
2 changes: 1 addition & 1 deletion include/pqxx/connection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public:
* using, the message does go out immediately.)
*
* For listening to incoming notifications, it gets a bit more complicated.
* To avoid complicating its internal bookkeeping, libpqxx only lets you
* To avoid complicating its internal bookkeeping, libpqxx only lets you
* start listening while no transaction is open.
*
* No notifications will come in while you're in a transaction... again
Expand Down
4 changes: 3 additions & 1 deletion include/pqxx/errorhandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public:
#include "pqxx/internal/ignore-deprecated-pre.hxx"
/// Suppress error notices.
[[deprecated("Use notice handlers instead.")]]
quiet_errorhandler(connection &cx) : errorhandler{cx} {}
quiet_errorhandler(connection &cx) :
errorhandler{cx}
{}
#include "pqxx/internal/ignore-deprecated-post.hxx"

/// Revert to previous handling of error notices.
Expand Down
5 changes: 1 addition & 4 deletions include/pqxx/internal/gates/connection-pipeline.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class PQXX_PRIVATE connection_pipeline : callgate<connection>

int encoding_id() { return home().encoding_id(); }

auto get_notice_waiters() const
{
return home().m_notice_waiters;
}
auto get_notice_waiters() const { return home().m_notice_waiters; }
};
} // namespace pqxx::internal::gate
10 changes: 5 additions & 5 deletions include/pqxx/result.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ struct notice_waiters
std::function<void(zview)> notice_handler;
std::list<errorhandler *> errorhandlers;

notice_waiters() =default;
notice_waiters(notice_waiters const &) =delete;
notice_waiters(notice_waiters &&) =delete;
notice_waiters &operator=(notice_waiters const &) =delete;
notice_waiters &operator=(notice_waiters &&) =delete;
notice_waiters() = default;
notice_waiters(notice_waiters const &) = delete;
notice_waiters(notice_waiters &&) = delete;
notice_waiters &operator=(notice_waiters const &) = delete;
notice_waiters &operator=(notice_waiters &&) = delete;
};
} // namespace pqxx::internal

Expand Down
31 changes: 13 additions & 18 deletions src/connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ void process_notice_raw(
{
if ((waiters != nullptr) and not msg.empty())
{
auto const
rbegin = std::crbegin(waiters->errorhandlers),
rend = std::crend(waiters->errorhandlers);
auto const rbegin = std::crbegin(waiters->errorhandlers),
rend = std::crend(waiters->errorhandlers);
for (auto i{rbegin}; (i != rend) and (**i)(msg.data()); ++i);

if (waiters->notice_handler) waiters->notice_handler(msg);
if (waiters->notice_handler)
waiters->notice_handler(msg);
}
}
} // namespace
Expand Down Expand Up @@ -117,9 +117,9 @@ pqxx::encrypt_password(char const user[], char const password[])

pqxx::connection::connection(connection &&rhs) :
m_conn{rhs.m_conn},
m_notice_waiters{std::move(rhs.m_notice_waiters)},
m_notification_handlers{std::move(rhs.m_notification_handlers)},
m_unique_id{rhs.m_unique_id}
m_notice_waiters{std::move(rhs.m_notice_waiters)},
m_notification_handlers{std::move(rhs.m_notification_handlers)},
m_unique_id{rhs.m_unique_id}
{
rhs.check_movable();
rhs.m_conn = nullptr;
Expand All @@ -145,8 +145,7 @@ pqxx::connection::connection(
}


pqxx::connection::connection(internal::pq::PGconn *raw_conn) :
m_conn{raw_conn}
pqxx::connection::connection(internal::pq::PGconn *raw_conn) : m_conn{raw_conn}
{
set_up_notice_handlers();
}
Expand Down Expand Up @@ -278,10 +277,8 @@ pqxx::result pqxx::connection::make_result(
throw broken_connection{"Lost connection to the database server."};
}
auto const enc{internal::enc_group(encoding_id())};
auto r{
pqxx::internal::gate::result_creation::create(
smart, query, m_notice_waiters, enc)
};
auto r{pqxx::internal::gate::result_creation::create(
smart, query, m_notice_waiters, enc)};
pqxx::internal::gate::result_creation{r}.check_status(desc);
return r;
}
Expand Down Expand Up @@ -423,7 +420,7 @@ void PQXX_COLD pqxx::connection::add_receiver(pqxx::notification_receiver *n)


void pqxx::connection::listen(
std::string_view channel, notification_handler handler)
std::string_view channel, notification_handler handler)
{
if (m_trans != nullptr)
throw usage_error{pqxx::internal::concat(
Expand All @@ -432,8 +429,7 @@ void pqxx::connection::listen(

std::string str_name{channel};

auto const
pos{m_notification_handlers.lower_bound(str_name)},
auto const pos{m_notification_handlers.lower_bound(str_name)},
handlers_end{std::end(m_notification_handlers)};

if (handler)
Expand Down Expand Up @@ -719,8 +715,7 @@ std::vector<pqxx::errorhandler *>
{
return {
std::begin(m_notice_waiters->errorhandlers),
std::end(m_notice_waiters->errorhandlers)
};
std::end(m_notice_waiters->errorhandlers)};
}


Expand Down
5 changes: 3 additions & 2 deletions src/except.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ pqxx::sql_error::sql_error(
std::source_location loc
#endif
) :
failure{whatarg
failure{
whatarg
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
,
loc
#endif
},
Expand Down
5 changes: 2 additions & 3 deletions src/pipeline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,8 @@ void pqxx::pipeline::obtain_dummy()

pqxx::internal::gate::connection_pipeline const pgate{m_trans->conn()};
auto handler{pgate.get_notice_waiters()};
result const R{
pqxx::internal::gate::result_creation::create(
r, text, handler, m_encoding)};
result const R{pqxx::internal::gate::result_creation::create(
r, text, handler, m_encoding)};

bool OK{false};
try
Expand Down
6 changes: 4 additions & 2 deletions src/result.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ pqxx::result::result(
std::shared_ptr<std::string> const &query,
std::shared_ptr<pqxx::internal::notice_waiters> const &notice_waiters,
internal::encoding_group enc) :
m_data{rhs}, m_query{query}, m_notice_waiters{notice_waiters},
m_encoding(enc)
m_data{rhs},
m_query{query},
m_notice_waiters{notice_waiters},
m_encoding(enc)
{}


Expand Down
3 changes: 1 addition & 2 deletions src/row.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ extern "C"
#include "pqxx/internal/header-post.hxx"


pqxx::row::row(
result r, result::size_type index, size_type cols) noexcept :
pqxx::row::row(result r, result::size_type index, size_type cols) noexcept :
m_result{std::move(r)}, m_index{index}, m_end{cols}
{}

Expand Down
4 changes: 2 additions & 2 deletions src/transaction_base.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void pqxx::transaction_base::register_pending_error(zview err) noexcept
{
PQXX_UNLIKELY
process_notice("UNABLE TO PROCESS ERROR\n");
// TODO: Make at least an attempt to append a newline.
// TODO: Make at least an attempt to append a newline.
process_notice(e.what());
process_notice("ERROR WAS:\n");
process_notice(err);
Expand All @@ -483,7 +483,7 @@ void pqxx::transaction_base::register_pending_error(std::string &&err) noexcept
{
PQXX_UNLIKELY
process_notice("UNABLE TO PROCESS ERROR\n");
// TODO: Make at least an attempt to append a newline.
// TODO: Make at least an attempt to append a newline.
process_notice(e.what());
process_notice("ERROR WAS:\n");
process_notice(err);
Expand Down
10 changes: 4 additions & 6 deletions test/test04.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ void test_004()
auto const channel{"pqxx_test_notif"};
pqxx::connection cx;
int backend_pid{0};
cx.listen(
channel,
[&backend_pid](pqxx::notification n) noexcept
{ backend_pid = n.backend_pid; });
cx.listen(channel, [&backend_pid](pqxx::notification n) noexcept {
backend_pid = n.backend_pid;
});

// Trigger our notification receiver.
pqxx::perform([&cx, &channel] {
Expand All @@ -46,8 +45,7 @@ void test_004()
}

PQXX_CHECK_EQUAL(
backend_pid,
cx.backendpid(),
backend_pid, cx.backendpid(),
"Did not get our notification from our own backend.");
PQXX_CHECK_EQUAL(notifs, 1, "Got too many notifications.");
}
Expand Down
2 changes: 1 addition & 1 deletion test/test70.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void test_070()
// See if regular retain()/resume() works
for (int i{0}; i < 5; ++i) TestPipeline(P, i);

// See if retrieve() fails on an empty pipeline, as it should
// See if retrieve() fails on an empty pipeline, as it should
#include "pqxx/internal/ignore-deprecated-pre.hxx"
quiet_errorhandler d(cx);
#include "pqxx/internal/ignore-deprecated-post.hxx"
Expand Down
7 changes: 3 additions & 4 deletions test/test79.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ void test_079()
std::string const channel{"mylistener"};
int backend_pid{0};

cx.listen(
channel,
[&backend_pid](pqxx::notification n) noexcept
{ backend_pid = n.backend_pid; });
cx.listen(channel, [&backend_pid](pqxx::notification n) noexcept {
backend_pid = n.backend_pid;
});

// First see if the timeout really works: we're not expecting any notifs
int notifs{cx.await_notification(0, 1)};
Expand Down
7 changes: 3 additions & 4 deletions test/test87.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ void test_087()
std::string const channel{"my notification"};
int backend_pid{0};

cx.listen(
channel,
[&backend_pid](pqxx::notification n) noexcept
{ backend_pid = n.backend_pid; });
cx.listen(channel, [&backend_pid](pqxx::notification n) noexcept {
backend_pid = n.backend_pid;
});

pqxx::perform([&cx, &channel] {
pqxx::work tx{cx};
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_connection.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <numeric>

#include <pqxx/transaction>
#include <pqxx/nontransaction>
#include <pqxx/transaction>

#include "../test_helpers.hxx"

Expand Down
24 changes: 8 additions & 16 deletions test/unit/test_notice_handler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ void test_notice_handler_receives_notice()
pqxx::connection cx;
int notices{0};

cx.set_notice_handler(
[&notices](pqxx::zview) noexcept
{
++notices;
}
);
cx.set_notice_handler([&notices](pqxx::zview) noexcept { ++notices; });

pqxx::work tx{cx};
// Start a transaction while already in a transaction, to trigger a notice.
Expand Down Expand Up @@ -55,9 +50,10 @@ void test_process_notice_calls_notice_handler()
const std::string msg{"Hello there\n"};

pqxx::connection cx;
cx.set_notice_handler(
[&calls, &received](auto x) noexcept { ++calls; received = x; }
);
cx.set_notice_handler([&calls, &received](auto x) noexcept {
++calls;
received = x;
});
cx.process_notice(msg);

PQXX_CHECK_EQUAL(calls, 1, "Expected exactly 1 call to notice handler.");
Expand Down Expand Up @@ -100,11 +96,8 @@ struct notice_handler_test_functor
int &count;
std::string &received;

notice_handler_test_functor(int &c, std::string &r) :
count{c},
received{r}
{
}
notice_handler_test_functor(int &c, std::string &r) : count{c}, received{r}
{}

void operator()(pqxx::zview msg) noexcept
{
Expand Down Expand Up @@ -139,8 +132,7 @@ void test_notice_handler_works_after_moving_connection()
bool got_message{false};
pqxx::connection cx;
cx.set_notice_handler(
[&got_message](pqxx::zview) noexcept { got_message = true; }
);
[&got_message](pqxx::zview) noexcept { got_message = true; });
auto cx2{std::move(cx)};
pqxx::connection cx3;
cx3 = std::move(cx2);
Expand Down
Loading

0 comments on commit d280c6c

Please sign in to comment.