gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Sep 25 15:32:02 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/5e6f9b34 (commit)
via https://github.com/Gnucash/gnucash/commit/44fc52f5 (commit)
via https://github.com/Gnucash/gnucash/commit/1c556171 (commit)
from https://github.com/Gnucash/gnucash/commit/d642397d (commit)
commit 5e6f9b3460f2db06f60f273dbd20bb06986514d8
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Sep 25 12:31:52 2020 -0700
Fix some return of ptr-to-temporary errors
Flagged by new clang Apple version 12.
diff --git a/libgnucash/engine/qof-backend.hpp b/libgnucash/engine/qof-backend.hpp
index f2e898508..5fd51e42d 100644
--- a/libgnucash/engine/qof-backend.hpp
+++ b/libgnucash/engine/qof-backend.hpp
@@ -273,7 +273,7 @@ public:
QofBePercentageFunc get_percentage() { return m_percentage; }
/** Retrieve the backend's storage URI.
*/
- std::string get_uri() { return m_fullpath; }
+ const std::string& get_uri() { return m_fullpath; }
/**
* Class methods for dynamically loading the several backends and for freeing
* them at shutdown.
diff --git a/libgnucash/engine/qofsession.cpp b/libgnucash/engine/qofsession.cpp
index 7e3ad9420..86edb1fc6 100644
--- a/libgnucash/engine/qofsession.cpp
+++ b/libgnucash/engine/qofsession.cpp
@@ -69,6 +69,7 @@ static QofLogModule log_module = QOF_MOD_SESSION;
using ProviderVec = std::vector<QofBackendProvider_ptr>;
static ProviderVec s_providers;
+static const std::string empty_string{};
/*
* These getters are used in tests to reach static vars from outside
* They should be removed when no longer needed
@@ -383,7 +384,7 @@ QofSessionImpl::get_error () noexcept
return m_last_err;
}
-std::string
+const std::string&
QofSessionImpl::get_error_message () const noexcept
{
return m_error_message;
@@ -414,11 +415,11 @@ QofSession::get_backend () const noexcept
return m_backend;
}
-std::string
+const std::string&
QofSessionImpl::get_file_path () const noexcept
{
auto backend = qof_book_get_backend (m_book);
- if (!backend) return nullptr;
+ if (!backend) return empty_string;
return backend->get_uri();
}
@@ -583,8 +584,9 @@ qof_session_get_book (const QofSession *session)
const char *
qof_session_get_file_path (const QofSession *session)
{
- if (!session) return NULL;
- return session->get_file_path ().c_str ();
+ if (!session) return nullptr;
+ auto& path{session->get_file_path()};
+ return path.empty() ? nullptr : path.c_str ();
}
void
diff --git a/libgnucash/engine/qofsession.hpp b/libgnucash/engine/qofsession.hpp
index 9029320c3..ea845b54e 100644
--- a/libgnucash/engine/qofsession.hpp
+++ b/libgnucash/engine/qofsession.hpp
@@ -68,10 +68,10 @@ struct QofSessionImpl
* for an error in the backend.
*/
QofBackendError get_error () noexcept;
- std::string get_error_message () const noexcept;
+ const std::string& get_error_message () const noexcept;
QofBook * get_book () const noexcept;
QofBackend * get_backend () const noexcept;
- std::string get_file_path () const noexcept;
+ const std::string& get_file_path () const noexcept;
bool is_saving () const noexcept;
/**
commit 44fc52f5c64fdd95d2dc68f9af63857d070228cd
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Sep 25 12:31:13 2020 -0700
Fix unnecessary copy in range-for loop
Flagged by new clang Apple version 12.
diff --git a/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp b/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
index 16e2c63c1..3eaf4d9bc 100644
--- a/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
+++ b/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
@@ -485,7 +485,7 @@ create_index_ddl (const GncSqlConnection* conn, const std::string& index_name,
{
std::string ddl;
ddl += "CREATE INDEX " + index_name + " ON " + table_name + "(";
- for (auto const table_row : col_table)
+ for (const auto& table_row : col_table)
{
if (table_row != *col_table.begin())
{
commit 1c5561714def3babc9618ad3342a16b91ec9f8c2
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Sep 25 12:23:56 2020 -0700
Fix ptr-comparison-to-string-literal error
A new error raised in the latest versions of gcc and clang.
The address of string literals is undefined in the C standard so the
compiler raises an error if one tries to test for string equality by
comparing them. A better fix would be to replace QOF_ID strings with an
int-based identifier; an even better one would get rid of QOF_ID
entirely and use the C++ type system.
diff --git a/libgnucash/engine/qofid.h b/libgnucash/engine/qofid.h
index c9012b6ac..8a59865ff 100644
--- a/libgnucash/engine/qofid.h
+++ b/libgnucash/engine/qofid.h
@@ -96,27 +96,7 @@ typedef struct QofCollection_s QofCollection;
#define QOF_ID_BOOK "Book"
#define QOF_ID_SESSION "Session"
-/** Inline string comparison; compiler will optimize away most of this */
-#ifndef _MSC_VER
-# define QSTRCMP(da,db) ({ \
- gint val = 0; \
- if ((da) && (db)) { \
- if ((da) != (db)) { \
- val = strcmp ((da), (db)); \
- } \
- } else \
- if ((!(da)) && (db)) { \
- val = -1; \
- } else \
- if ((da) && (!(db))) { \
- val = 1; \
- } \
- val; /* block assumes value of last statement */ \
-})
-#else
-/* MSVC: Simply use g_strcmp */
-# define QSTRCMP g_strcmp0
-#endif
+#define QSTRCMP g_strcmp0
/** return TRUE if object is of the given type */
#define QOF_CHECK_TYPE(obj,type) (((obj) != NULL) && \
Summary of changes:
libgnucash/backend/dbi/gnc-dbisqlconnection.cpp | 2 +-
libgnucash/engine/qof-backend.hpp | 2 +-
libgnucash/engine/qofid.h | 22 +---------------------
libgnucash/engine/qofsession.cpp | 12 +++++++-----
libgnucash/engine/qofsession.hpp | 4 ++--
5 files changed, 12 insertions(+), 30 deletions(-)
More information about the gnucash-changes
mailing list