gnucash stable: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Mon Nov 6 17:29:00 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/9e47c297 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/12f42333 (commit)
	from  https://github.com/Gnucash/gnucash/commit/4da655d0 (commit)



commit 9e47c297ba5ca217640ef81124b80c1b99b450d6
Merge: 4da655d0f9 12f4233396
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Tue Nov 7 06:28:39 2023 +0800

    Merge branch 'plug-recurrence-to-string' into stable #1812


commit 12f42333963c77b5c7fb61270934737a264a30e4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Nov 1 21:49:48 2023 +0800

    recurrencePeriodTypeToString and recurrenceWeekendAdjustToString g_strdup only when necessary
    
    ... for sql use only. xml use assumes they return a const char*.

diff --git a/libgnucash/backend/sql/gnc-recurrence-sql.cpp b/libgnucash/backend/sql/gnc-recurrence-sql.cpp
index 967d5b81aa..feeb32d9af 100644
--- a/libgnucash/backend/sql/gnc-recurrence-sql.cpp
+++ b/libgnucash/backend/sql/gnc-recurrence-sql.cpp
@@ -379,14 +379,13 @@ upgrade_recurrence_table_1_2 (GncSqlBackend* sql_be)
 
     /* Step 2: insert a default value in the newly created column */
     {
-        gchar* weekend_adj_str = recurrenceWeekendAdjustToString (WEEKEND_ADJ_NONE);
+        const gchar* weekend_adj_str = recurrenceWeekendAdjustToString (WEEKEND_ADJ_NONE);
         std::stringstream sql;
         sql << "UPDATE " << TABLE_NAME << " SET " <<
             weekend_adjust_col_table[0]->name() << "='" <<
             weekend_adj_str << "'";
         auto stmt = sql_be->create_statement_from_sql(sql.str());
         sql_be->execute_nonselect_statement(stmt);
-        g_free (weekend_adj_str);
     }
 
     /* Step 3: rewrite the table, requiring the weekend_adj column to be non-null */
diff --git a/libgnucash/engine/Recurrence.c b/libgnucash/engine/Recurrence.c
index 5054b0ba1e..f507396acf 100644
--- a/libgnucash/engine/Recurrence.c
+++ b/libgnucash/engine/Recurrence.c
@@ -518,10 +518,10 @@ recurrenceListToString(const GList *r)
     return g_string_free(str, FALSE);
 }
 
-gchar *
+const gchar *
 recurrencePeriodTypeToString(PeriodType pt)
 {
-    return VALID_PERIOD_TYPE(pt) ? g_strdup(period_type_strings[pt]) : NULL;
+    return VALID_PERIOD_TYPE(pt) ? period_type_strings[pt] : NULL;
 }
 
 PeriodType
@@ -535,10 +535,10 @@ recurrencePeriodTypeFromString(const gchar *str)
     return -1;
 }
 
-gchar *
+const gchar *
 recurrenceWeekendAdjustToString(WeekendAdjust wadj)
 {
-    return VALID_WEEKEND_ADJ(wadj) ? g_strdup(weekend_adj_strings[wadj]) : NULL;
+    return VALID_WEEKEND_ADJ(wadj) ? weekend_adj_strings[wadj] : NULL;
 }
 
 WeekendAdjust
diff --git a/libgnucash/engine/Recurrence.h b/libgnucash/engine/Recurrence.h
index 298cb6cbac..bcb92d86ed 100644
--- a/libgnucash/engine/Recurrence.h
+++ b/libgnucash/engine/Recurrence.h
@@ -155,9 +155,9 @@ void recurrenceListNextInstance(const GList *r, const GDate *refDate,
                                 GDate *nextDate);
 
 /* These four functions are only for xml storage, not user presentation. */
-gchar *recurrencePeriodTypeToString(PeriodType pt);
+const gchar *recurrencePeriodTypeToString(PeriodType pt);
 PeriodType recurrencePeriodTypeFromString(const gchar *str);
-gchar *recurrenceWeekendAdjustToString(WeekendAdjust wadj);
+const gchar *recurrenceWeekendAdjustToString(WeekendAdjust wadj);
 WeekendAdjust recurrenceWeekendAdjustFromString(const gchar *str);
 
 /* For debugging.  Caller owns the returned string.  Not intl. */



Summary of changes:
 libgnucash/backend/sql/gnc-recurrence-sql.cpp | 3 +--
 libgnucash/engine/Recurrence.c                | 8 ++++----
 libgnucash/engine/Recurrence.h                | 4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list