From d280c6c9a6d063638b5bb0d2450bc15ed641c27c Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Sun, 22 Dec 2024 19:24:39 +0100 Subject: [PATCH] Update config, reformat. (#913) --- configure | 3 +- include/pqxx/connection.hxx | 2 +- include/pqxx/errorhandler.hxx | 4 +- .../internal/gates/connection-pipeline.hxx | 5 +- include/pqxx/result.hxx | 10 +-- src/connection.cxx | 31 +++---- src/except.cxx | 5 +- src/pipeline.cxx | 5 +- src/result.cxx | 6 +- src/row.cxx | 3 +- src/transaction_base.cxx | 4 +- test/test04.cxx | 10 +-- test/test70.cxx | 2 +- test/test79.cxx | 7 +- test/test87.cxx | 7 +- test/unit/test_connection.cxx | 2 +- test/unit/test_notice_handler.cxx | 24 ++---- test/unit/test_notification.cxx | 82 ++++++++++--------- 18 files changed, 101 insertions(+), 111 deletions(-) diff --git a/configure b/configure index 627e064ee..b7a2e0b82 100755 --- a/configure +++ b/configure @@ -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 \ diff --git a/include/pqxx/connection.hxx b/include/pqxx/connection.hxx index d54d4cad1..e7416095c 100644 --- a/include/pqxx/connection.hxx +++ b/include/pqxx/connection.hxx @@ -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 diff --git a/include/pqxx/errorhandler.hxx b/include/pqxx/errorhandler.hxx index e44476c62..39ba04a77 100644 --- a/include/pqxx/errorhandler.hxx +++ b/include/pqxx/errorhandler.hxx @@ -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. diff --git a/include/pqxx/internal/gates/connection-pipeline.hxx b/include/pqxx/internal/gates/connection-pipeline.hxx index c59b3d0e0..ff9acd65a 100644 --- a/include/pqxx/internal/gates/connection-pipeline.hxx +++ b/include/pqxx/internal/gates/connection-pipeline.hxx @@ -20,9 +20,6 @@ class PQXX_PRIVATE connection_pipeline : callgate 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 diff --git a/include/pqxx/result.hxx b/include/pqxx/result.hxx index c3f98b063..99a2cda78 100644 --- a/include/pqxx/result.hxx +++ b/include/pqxx/result.hxx @@ -56,11 +56,11 @@ struct notice_waiters std::function notice_handler; std::list 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 diff --git a/src/connection.cxx b/src/connection.cxx index 6df8ec2da..e817a820f 100644 --- a/src/connection.cxx +++ b/src/connection.cxx @@ -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 @@ -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; @@ -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(); } @@ -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; } @@ -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( @@ -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) @@ -719,8 +715,7 @@ std::vector { return { std::begin(m_notice_waiters->errorhandlers), - std::end(m_notice_waiters->errorhandlers) - }; + std::end(m_notice_waiters->errorhandlers)}; } diff --git a/src/except.cxx b/src/except.cxx index b5cd16ae2..3901a08c1 100644 --- a/src/except.cxx +++ b/src/except.cxx @@ -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 }, diff --git a/src/pipeline.cxx b/src/pipeline.cxx index a779f3d34..918d7f975 100644 --- a/src/pipeline.cxx +++ b/src/pipeline.cxx @@ -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 diff --git a/src/result.cxx b/src/result.cxx index 7f0e239d9..8b1599073 100644 --- a/src/result.cxx +++ b/src/result.cxx @@ -53,8 +53,10 @@ pqxx::result::result( std::shared_ptr const &query, std::shared_ptr const ¬ice_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) {} diff --git a/src/row.cxx b/src/row.cxx index 289685af8..bed623b97 100644 --- a/src/row.cxx +++ b/src/row.cxx @@ -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} {} diff --git a/src/transaction_base.cxx b/src/transaction_base.cxx index 99a39f11b..ce182db95 100644 --- a/src/transaction_base.cxx +++ b/src/transaction_base.cxx @@ -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); @@ -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); diff --git a/test/test04.cxx b/test/test04.cxx index 9fe0b1552..b59655a98 100644 --- a/test/test04.cxx +++ b/test/test04.cxx @@ -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] { @@ -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."); } diff --git a/test/test70.cxx b/test/test70.cxx index 1ca597c78..388c8ca3e 100644 --- a/test/test70.cxx +++ b/test/test70.cxx @@ -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" diff --git a/test/test79.cxx b/test/test79.cxx index 73cd0e902..764114840 100644 --- a/test/test79.cxx +++ b/test/test79.cxx @@ -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)}; diff --git a/test/test87.cxx b/test/test87.cxx index 6635c542a..628f2cbd4 100644 --- a/test/test87.cxx +++ b/test/test87.cxx @@ -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}; diff --git a/test/unit/test_connection.cxx b/test/unit/test_connection.cxx index 868940164..4a88e8efb 100644 --- a/test/unit/test_connection.cxx +++ b/test/unit/test_connection.cxx @@ -1,7 +1,7 @@ #include -#include #include +#include #include "../test_helpers.hxx" diff --git a/test/unit/test_notice_handler.cxx b/test/unit/test_notice_handler.cxx index 04d66f391..45b7957b9 100644 --- a/test/unit/test_notice_handler.cxx +++ b/test/unit/test_notice_handler.cxx @@ -9,12 +9,7 @@ void test_notice_handler_receives_notice() pqxx::connection cx; int notices{0}; - cx.set_notice_handler( - [¬ices](pqxx::zview) noexcept - { - ++notices; - } - ); + cx.set_notice_handler([¬ices](pqxx::zview) noexcept { ++notices; }); pqxx::work tx{cx}; // Start a transaction while already in a transaction, to trigger a notice. @@ -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."); @@ -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 { @@ -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); diff --git a/test/unit/test_notification.cxx b/test/unit/test_notification.cxx index 7ae15e9a9..c98a85c9b 100644 --- a/test/unit/test_notification.cxx +++ b/test/unit/test_notification.cxx @@ -97,7 +97,7 @@ void test_notification_to_self_arrives_after_commit() cx.listen( channel, - [¬ifications, &conn, &incoming, &payload, &pid](pqxx::notification n){ + [¬ifications, &conn, &incoming, &payload, &pid](pqxx::notification n) { ++notifications; conn = &n.conn; incoming = n.channel; @@ -126,7 +126,8 @@ void test_notification_to_self_arrives_after_commit() PQXX_CHECK_EQUAL(notifications, 1, "Miscounted notifcations."); PQXX_CHECK(conn == &cx, "Wrong connection on notification from self."); PQXX_CHECK_EQUAL( - pid, cx.backendpid(), "Notification from self came from wrong connection."); + pid, cx.backendpid(), + "Notification from self came from wrong connection."); PQXX_CHECK_EQUAL(incoming, channel, "Notification is on wrong channel."); PQXX_CHECK_EQUAL(payload, "", "Unexpected payload."); } @@ -140,12 +141,10 @@ void test_notification_has_payload() int notifications{0}; std::string received; - cx.listen( - channel, - [¬ifications, &received](pqxx::notification n) { - ++notifications; - received = n.payload; - }); + cx.listen(channel, [¬ifications, &received](pqxx::notification n) { + ++notifications; + received = n.payload; + }); pqxx::work tx{cx}; tx.notify(channel, payload); @@ -208,7 +207,7 @@ void test_abort_cancels_notification() auto const chan{"pqxx-test-channel"}; pqxx::connection cx; bool received{false}; - cx.listen(chan, [&received](pqxx::notification){ received = true; }); + cx.listen(chan, [&received](pqxx::notification) { received = true; }); pqxx::work tx{cx}; tx.notify(chan); @@ -223,7 +222,7 @@ void test_notification_channels_are_case_sensitive() { pqxx::connection cx; std::string in; - cx.listen("pqxx-AbC", [&in](pqxx::notification n){ in = n.channel; }); + cx.listen("pqxx-AbC", [&in](pqxx::notification n) { in = n.channel; }); pqxx::work tx{cx}; tx.notify("pqxx-AbC"); @@ -242,7 +241,7 @@ void test_notification_channels_may_contain_weird_chars() auto const chan{"pqxx-A_#&*!"}; pqxx::connection cx; std::string got; - cx.listen(chan, [&got](pqxx::notification n){ got = n.channel; }); + cx.listen(chan, [&got](pqxx::notification n) { got = n.channel; }); pqxx::work tx{cx}; tx.notify(chan); tx.commit(); @@ -258,7 +257,7 @@ void test_nontransaction_sends_notification() auto const chan{"pqxx-test-chan"}; pqxx::connection cx; bool got{false}; - cx.listen(chan, [&got](pqxx::notification){ got = true; }); + cx.listen(chan, [&got](pqxx::notification) { got = true; }); pqxx::nontransaction tx{cx}; tx.notify(chan); @@ -274,7 +273,7 @@ void test_subtransaction_sends_notification() auto const chan{"pqxx-test-chan6301"}; pqxx::connection cx; bool got{false}; - cx.listen(chan, [&got](pqxx::notification){ got = true; }); + cx.listen(chan, [&got](pqxx::notification) { got = true; }); pqxx::work tx{cx}; pqxx::subtransaction sx{tx}; @@ -292,7 +291,7 @@ void test_subtransaction_abort_cancels_notification() auto const chan{"pqxx-test-chan123278w"}; pqxx::connection cx; bool got{false}; - cx.listen(chan, [&got](pqxx::notification){ got = true; }); + cx.listen(chan, [&got](pqxx::notification) { got = true; }); pqxx::work tx{cx}; pqxx::subtransaction sx{tx}; @@ -312,7 +311,7 @@ void test_cannot_listen_during_transaction() // a nontransaction. pqxx::nontransaction tx{cx}; PQXX_CHECK_THROWS( - cx.listen("pqxx-test-chan02756", [](pqxx::notification){}), + cx.listen("pqxx-test-chan02756", [](pqxx::notification) {}), pqxx::usage_error, "Expected usage_error when listening during transaction."); } @@ -324,16 +323,14 @@ void test_notifications_cross_connections() pqxx::connection cx_listen, cx_notify; int sender_pid{0}; cx_listen.listen( - chan, - [&sender_pid](pqxx::notification n){ sender_pid = n.backend_pid; }); + chan, [&sender_pid](pqxx::notification n) { sender_pid = n.backend_pid; }); pqxx::work tx{cx_notify}; tx.notify(chan); tx.commit(); cx_listen.await_notification(3); - PQXX_CHECK_EQUAL( - sender_pid, cx_notify.backendpid(), "Sender pid mismatch."); + PQXX_CHECK_EQUAL(sender_pid, cx_notify.backendpid(), "Sender pid mismatch."); } @@ -343,15 +340,18 @@ void test_notification_goes_to_right_handler() std::string got; int count{0}; - cx.listen( - "pqxx-chanX", - [&got, &count](pqxx::notification){ got = "chanX"; ++count; }); - cx.listen( - "pqxx-chanY", - [&got, &count](pqxx::notification){ got = "chanY"; ++count; }); - cx.listen( - "pqxx-chanZ", - [&got, &count](pqxx::notification){ got = "chanZ"; ++count; }); + cx.listen("pqxx-chanX", [&got, &count](pqxx::notification) { + got = "chanX"; + ++count; + }); + cx.listen("pqxx-chanY", [&got, &count](pqxx::notification) { + got = "chanY"; + ++count; + }); + cx.listen("pqxx-chanZ", [&got, &count](pqxx::notification) { + got = "chanZ"; + ++count; + }); pqxx::work tx{cx}; tx.notify("pqxx-chanY"); @@ -370,12 +370,18 @@ void test_listen_on_same_channel_overwrites() std::string got; int count{0}; - cx.listen( - chan, [&got, &count](pqxx::notification){ got = "first"; ++count; }); - cx.listen( - chan, [&got, &count](pqxx::notification){ got = "second"; ++count; }); - cx.listen( - chan, [&got, &count](pqxx::notification){ got = "third"; ++count; }); + cx.listen(chan, [&got, &count](pqxx::notification) { + got = "first"; + ++count; + }); + cx.listen(chan, [&got, &count](pqxx::notification) { + got = "second"; + ++count; + }); + cx.listen(chan, [&got, &count](pqxx::notification) { + got = "third"; + ++count; + }); pqxx::work tx{cx}; tx.notify(chan); @@ -383,7 +389,7 @@ void test_listen_on_same_channel_overwrites() cx.await_notification(3); PQXX_CHECK_EQUAL(count, 1, "Expected 1 notification despite overwrite."); - PQXX_CHECK_EQUAL(got,"third", "Wrong handler called."); + PQXX_CHECK_EQUAL(got, "third", "Wrong handler called."); } @@ -392,7 +398,7 @@ void test_empty_notification_handler_disables() auto const chan{"pqxx-chan812710"}; pqxx::connection cx; bool got{false}; - cx.listen(chan, [&got](pqxx::notification){ got = true; }); + cx.listen(chan, [&got](pqxx::notification) { got = true; }); cx.listen(chan); pqxx::work tx{cx}; tx.notify(chan); @@ -406,7 +412,7 @@ void test_notifications_do_not_come_in_until_commit() auto const chan{"pqxx-chan95017834"}; pqxx::connection cx; bool got{false}; - cx.listen(chan, [&got](pqxx::notification){ got = true; }); + cx.listen(chan, [&got](pqxx::notification) { got = true; }); // This applies even during a nontransaction. Another test verifies that // a notification goes _out_ even if we abort the nontransaction, because @@ -425,7 +431,7 @@ void test_notification_handlers_follow_connection_move() auto const chan{"pqxx-chan3782"}; pqxx::connection cx1; pqxx::connection *got{nullptr}; - cx1.listen(chan, [&got](pqxx::notification n){ got = &n.conn; }); + cx1.listen(chan, [&got](pqxx::notification n) { got = &n.conn; }); pqxx::connection cx2{std::move(cx1)}; pqxx::connection cx3; cx3 = std::move(cx2);