gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Tue Apr 17 19:32:54 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/cad6bb42 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/39aecb76 (commit)
	from  https://github.com/Gnucash/gnucash/commit/3138229c (commit)



commit cad6bb42726c20a21b88e3ec4ee246dc3d9125c4
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Apr 17 16:27:24 2018 -0700

    Bug 792105 - Startup takes several minutes, take two.
    
    First, remove the unnecessary locale push & pop on <CT_TIME64>load.
    
    Second, the registry accesses were caused by using g_win32_get_locale
    to convert the Microsoft locale strings to POSIX ones. We don't care
    what kind of string we get as long as we can pass it back to setlocale,
    so remove that.
    
    Third, gnc_push/pop_locale were used only in backend/dbi in a
    very limited way and did much more than was necessary, so
    convert them to C++ inlines in gnc-backend-dbi.hpp that does
    only what we need them to.

diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.cpp b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
index 68b8933..4017066 100644
--- a/libgnucash/backend/dbi/gnc-backend-dbi.cpp
+++ b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
@@ -1177,7 +1177,7 @@ dbi_library_test (dbi_conn conn)
         return GNC_DBI_FAIL_SETUP;
     }
     dbi_result_free (result);
-    gnc_push_locale (LC_NUMERIC, "C");
+    auto locale = gnc_push_locale (LC_NUMERIC, "C");
     result = dbi_conn_query (conn, "SELECT * FROM numtest");
     if (result == nullptr)
     {
@@ -1186,7 +1186,7 @@ dbi_library_test (dbi_conn conn)
         PWARN ("Test_DBI_Library: Failed to retrieve test row into table: %s",
                errmsg);
         dbi_conn_query (conn, "DROP TABLE numtest");
-        gnc_pop_locale (LC_NUMERIC);
+        gnc_pop_locale (LC_NUMERIC, locale);
         return GNC_DBI_FAIL_SETUP;
     }
     while (dbi_result_next_row (result))
@@ -1196,7 +1196,7 @@ dbi_library_test (dbi_conn conn)
         resultdouble = dbi_result_get_double (result, "test_double");
     }
     dbi_conn_query (conn, "DROP TABLE numtest");
-    gnc_pop_locale (LC_NUMERIC);
+    gnc_pop_locale (LC_NUMERIC, locale);
     if (testlonglong != resultlonglong)
     {
         PWARN ("Test_DBI_Library: LongLong Failed %" PRId64 " != % " PRId64,
diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.hpp b/libgnucash/backend/dbi/gnc-backend-dbi.hpp
index 5d02732..07b92e6 100644
--- a/libgnucash/backend/dbi/gnc-backend-dbi.hpp
+++ b/libgnucash/backend/dbi/gnc-backend-dbi.hpp
@@ -118,6 +118,21 @@ private:
     bool m_exists;         // Does the database exist?
 };
 
+/* locale-stack */
+inline std::string
+gnc_push_locale(const int category, const std::string locale)
+{
+    std::string retval(setlocale(category, nullptr));
+    setlocale(category, locale.c_str());
+    return retval;
+}
+
+inline void
+gnc_pop_locale(const int category, std::string locale)
+{
+    setlocale(category, locale.c_str());
+}
+
 /* external access required for tests */
 std::string adjust_sql_options_string(const std::string&);
 
diff --git a/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp b/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
index a4172f4..f24f693 100644
--- a/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
+++ b/libgnucash/backend/dbi/gnc-dbisqlconnection.cpp
@@ -252,7 +252,7 @@ GncDbiSqlConnection::execute_select_statement (const GncSqlStatementPtr& stmt)
     dbi_result result;
 
     DEBUG ("SQL: %s\n", stmt->to_sql());
-    gnc_push_locale (LC_NUMERIC, "C");
+    auto locale = gnc_push_locale (LC_NUMERIC, "C");
     do
     {
         init_error ();
@@ -261,7 +261,7 @@ GncDbiSqlConnection::execute_select_statement (const GncSqlStatementPtr& stmt)
     while (m_retry);
     if (result == nullptr)
         PERR ("Error executing SQL %s\n", stmt->to_sql());
-    gnc_pop_locale (LC_NUMERIC);
+    gnc_pop_locale (LC_NUMERIC, locale);
     return GncSqlResultPtr(new GncDbiSqlResult (this, result));
 }
 
diff --git a/libgnucash/backend/dbi/gnc-dbisqlresult.cpp b/libgnucash/backend/dbi/gnc-dbisqlresult.cpp
index a686fa4..5b2a784 100644
--- a/libgnucash/backend/dbi/gnc-dbisqlresult.cpp
+++ b/libgnucash/backend/dbi/gnc-dbisqlresult.cpp
@@ -117,9 +117,9 @@ GncDbiSqlResult::IteratorImpl::get_float_at_col(const char* col) const
     if(type != DBI_TYPE_DECIMAL ||
        (attrs & DBI_DECIMAL_SIZEMASK) != DBI_DECIMAL_SIZE4)
         throw (std::invalid_argument{"Requested float from non-float column."});
-    gnc_push_locale (LC_NUMERIC, "C");
+    auto locale = gnc_push_locale (LC_NUMERIC, "C");
     auto retval =  dbi_result_get_float(m_inst->m_dbi_result, col);
-    gnc_pop_locale (LC_NUMERIC);
+    gnc_pop_locale (LC_NUMERIC, locale);
     return retval;
 }
 
@@ -131,9 +131,9 @@ GncDbiSqlResult::IteratorImpl::get_double_at_col(const char* col) const
     if(type != DBI_TYPE_DECIMAL ||
        (attrs & DBI_DECIMAL_SIZEMASK) != DBI_DECIMAL_SIZE8)
         throw (std::invalid_argument{"Requested double from non-double column."});
-    gnc_push_locale (LC_NUMERIC, "C");
+    auto locale = gnc_push_locale (LC_NUMERIC, "C");
     auto retval =  dbi_result_get_double(m_inst->m_dbi_result, col);
-    gnc_pop_locale (LC_NUMERIC);
+    gnc_pop_locale (LC_NUMERIC, locale);
     return retval;
 }
 
@@ -160,7 +160,6 @@ GncDbiSqlResult::IteratorImpl::get_time64_at_col (const char* col) const
     auto attrs = dbi_result_get_field_attribs (result, col);
     if (type != DBI_TYPE_DATETIME)
         throw (std::invalid_argument{"Requested time64 from non-time64 column."});
-    gnc_push_locale (LC_NUMERIC, "C");
 #if HAVE_LIBDBI_TO_LONGLONG
     /* A less evil hack than the one required by libdbi-0.8, but
      * still necessary to work around the same bug.
@@ -179,7 +178,6 @@ GncDbiSqlResult::IteratorImpl::get_time64_at_col (const char* col) const
 #endif //HAVE_LIBDBI_TO_LONGLONG
     if (retval < MINTIME || retval > MAXTIME)
         retval = 0;
-    gnc_pop_locale (LC_NUMERIC);
     return retval;
 }
 
diff --git a/libgnucash/core-utils/gnc-locale-utils.c b/libgnucash/core-utils/gnc-locale-utils.c
index 94b1e1d..7af5359 100644
--- a/libgnucash/core-utils/gnc-locale-utils.c
+++ b/libgnucash/core-utils/gnc-locale-utils.c
@@ -150,43 +150,3 @@ gnc_locale_decimal_places (void)
 
     return places;
 }
-
-
-static GList *locale_stack = NULL;
-
-void
-gnc_push_locale (int category, const char *locale)
-{
-    char *saved_locale;
-
-    g_return_if_fail (locale != NULL);
-
-# ifdef G_OS_WIN32
-    /* On win32, setlocale() doesn't say anything useful. Use
-       glib's function instead. */
-    saved_locale = g_win32_getlocale();
-# else
-    saved_locale = g_strdup(setlocale(category, NULL) ?
-                            setlocale(category, NULL) : "C");
-#endif
-    locale_stack = g_list_prepend (locale_stack, saved_locale);
-    setlocale (category, locale);
-}
-
-void
-gnc_pop_locale (int category)
-{
-    char *saved_locale;
-    GList *node;
-
-    g_return_if_fail (locale_stack != NULL);
-
-    node = locale_stack;
-    saved_locale = node->data;
-
-    setlocale (category, saved_locale);
-
-    locale_stack = g_list_remove_link (locale_stack, node);
-    g_list_free_1 (node);
-    g_free (saved_locale);
-}
diff --git a/libgnucash/core-utils/gnc-locale-utils.h b/libgnucash/core-utils/gnc-locale-utils.h
index 5dbe4b1..5d90638 100644
--- a/libgnucash/core-utils/gnc-locale-utils.h
+++ b/libgnucash/core-utils/gnc-locale-utils.h
@@ -37,26 +37,4 @@ const char * gnc_locale_default_iso_currency_code (void);
 /* Returns the number of decimal place to print in the current locale */
 int gnc_locale_decimal_places (void);
 
-/** Temporarily change locale, pushing the old one onto a stack
- * Currently, this has no effect on gnc_localeconv.  i.e., after the
- * first call to gnc_localeconv, subsequent calls will return the same
- * information.
- *
- * WARNING: Be careful to maintain the correct nesting order of pushes
- * or pops; otherwise, the localization results might be
- * interesting. Note that the stack does not keep track of which
- * category a locale was pushed from, so careless use will alse
- * produce interesting results.
- *
- * @param category: The locale category (e.g. LC_ALL, LC_NUMERIC) to push onto
- * @param locale: The new locale to set
- */
-void gnc_push_locale (int category, const char *locale);
-
-/** Restore the last-pushed locale.
- * @param category: The locale category to restore the locale to.
- */
-void gnc_pop_locale (int category);
-
-
 #endif /* GNC_LOCALE_UTILS_H */

commit 39aecb7610fe9e5241f7ab77e99cf86ed53f36a9
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Apr 17 12:02:04 2018 -0700

    Bug 794936 - 3.0 does not open previously saved sqlite3 files...
    
    properly - corrupted business data
    
    Turned out to be a pointer/value mismatch between <CT_NUMERIC>load()
    and most of the setter functions, so the address was getting set
    as the value.

diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp
index ca719f3..980439f 100644
--- a/libgnucash/backend/sql/gnc-slots-sql.cpp
+++ b/libgnucash/backend/sql/gnc-slots-sql.cpp
@@ -95,7 +95,7 @@ static void set_timespec_val (gpointer pObject, Timespec *ts);
 static  gpointer get_guid_val (gpointer pObject);
 static void set_guid_val (gpointer pObject,  gpointer pValue);
 static gnc_numeric get_numeric_val (gpointer pObject);
-static void set_numeric_val (gpointer pObject, gnc_numeric *value);
+static void set_numeric_val (gpointer pObject, gnc_numeric value);
 static GDate* get_gdate_val (gpointer pObject);
 static void set_gdate_val (gpointer pObject, GDate* value);
 static slot_info_t* slot_info_copy (slot_info_t* pInfo, GncGUID* guid);
@@ -515,7 +515,7 @@ get_numeric_val (gpointer pObject)
 }
 
 static void
-set_numeric_val (gpointer pObject, gnc_numeric *value)
+set_numeric_val (gpointer pObject, gnc_numeric value)
 {
     slot_info_t* pInfo = (slot_info_t*)pObject;
     KvpValue* pValue = NULL;
@@ -523,7 +523,7 @@ set_numeric_val (gpointer pObject, gnc_numeric *value)
     g_return_if_fail (pObject != NULL);
 
     if (pInfo->value_type != KvpValue::Type::NUMERIC) return;
-    set_slot_from_value (pInfo, new KvpValue {*value});
+    set_slot_from_value (pInfo, new KvpValue {value});
 }
 
 static GDate*
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
index 81e1938..7a38b82 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
@@ -593,7 +593,7 @@ GncSqlColumnTableEntryImpl<CT_GDATE>::add_to_query(QofIdTypeConst obj_name,
 
 /* ----------------------------------------------------------------- */
 typedef gnc_numeric (*NumericGetterFunc) (const gpointer);
-typedef void (*NumericSetterFunc) (gpointer, gnc_numeric*);
+typedef void (*NumericSetterFunc) (gpointer, gnc_numeric);
 
 static const EntryVec numeric_col_table =
 {
@@ -601,6 +601,16 @@ static const EntryVec numeric_col_table =
     gnc_sql_make_table_entry<CT_INT64>("denom", 0, COL_NNUL, "guid")
 };
 
+template <>
+void set_parameter<gpointer, gnc_numeric>(gpointer object,
+                                          gnc_numeric item,
+                                          const char* property)
+{
+    qof_instance_increase_editlevel(object);
+    g_object_set(object, property, &item, nullptr);
+    qof_instance_decrease_editlevel(object);
+};
+
 template<> void
 GncSqlColumnTableEntryImpl<CT_NUMERIC>::load (const GncSqlBackend* sql_be,
                                               GncSqlRow& row,
@@ -626,7 +636,7 @@ GncSqlColumnTableEntryImpl<CT_NUMERIC>::load (const GncSqlBackend* sql_be,
     {
         return;
     }
-    set_parameter(pObject, &n,
+    set_parameter(pObject, n,
                   reinterpret_cast<NumericSetterFunc>(get_setter(obj_name)),
                   m_gobj_param_name);
 }



Summary of changes:
 libgnucash/backend/dbi/gnc-backend-dbi.cpp         |  6 ++--
 libgnucash/backend/dbi/gnc-backend-dbi.hpp         | 15 ++++++++
 libgnucash/backend/dbi/gnc-dbisqlconnection.cpp    |  4 +--
 libgnucash/backend/dbi/gnc-dbisqlresult.cpp        | 10 +++---
 libgnucash/backend/sql/gnc-slots-sql.cpp           |  6 ++--
 .../backend/sql/gnc-sql-column-table-entry.cpp     | 14 ++++++--
 libgnucash/core-utils/gnc-locale-utils.c           | 40 ----------------------
 libgnucash/core-utils/gnc-locale-utils.h           | 22 ------------
 8 files changed, 39 insertions(+), 78 deletions(-)



More information about the gnucash-changes mailing list