gnucash future: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Tue Jul 14 18:54:54 EDT 2026


Updated	 via  https://github.com/Gnucash/gnucash/commit/458b2ea4 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e417a6ea (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ce4099d5 (commit)
	from  https://github.com/Gnucash/gnucash/commit/8a9abe81 (commit)



commit 458b2ea4c482b62f9c3c22eb5287154ff0a7d549
Merge: 8a9abe818d e417a6ea27
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Jul 14 15:51:55 2026 -0700

    Merge Brent McBride's 'gnc-state-cpp' into future.

commit e417a6ea27f1441662cf43a580794035bfa5db6b
Author: Brent McBride <mcbridebt at hotmail.com>
Date:   Wed Jul 8 14:44:14 2026 -0700

    Modernize gnc-state.cpp to C++ and add unit tests
    
    Convert C idioms in gnc-state.cpp to modern C++ now that the file is
    compiled as C++:
    
    - Replace the static char* state-file-name globals with
      std::optional<std::string>, eliminating the manual g_free/NULL
      ownership dance.
    - Use std::string and std::format for filename construction.
    - Use std::filesystem::path::filename() for the file-URI basename
      instead of g_path_get_basename.
    - Compare book GUIDs with the C++ gnc::GUID value type
      (gnc::GUID::from_string + operator==, catching gnc::guid_syntax_exception
      on a malformed id) instead of the C GncGUID/string_to_guid/guid_equal
      API; drop the scratch encode buffer.
    - Replace g_strstr_len with std::string_view::find.
    - Wrap GLib-owned resources in std::unique_ptr with the matching deleter
      (g_free for gchar* buffers, g_key_file_free for the scratch GKeyFile,
      g_strfreev for the groups array), replacing shared_ptr and removing the
      manual free/double-free cleanup dance.
    - Iterate the g_key_file_get_groups() result via std::span for a
      range-based loop instead of an indexed char** walk.
    - Parse session URIs through the GncUri C++ class instead of the C
      gnc-uri-utils helpers, preserving the g_strjoin NULL-truncation
      behavior for database URIs.
    - Guard qof_session_get_url() against NULL before dereferencing (was
      strlen(uri), UB on null) in gnc_state_set_base/gnc_state_save.
    - Sweep remaining GLib tokens: gchar/gint/gsize -> char/int/size_t,
      TRUE/FALSE -> true/false, const gchar* -> const char* on
      gnc_state_drop_sections_for (and its declaration in gnc-state.h).
    - Apply the project CodingStandard: return type on its own line for
      definitions, s_ prefix on free statics, and lines under 80 columns.
    
    Boundary GLib retained deliberately: GKeyFile (.gcm on-disk format),
    GError, g_key_file_*/gnc_key_file_* wrappers, gnc_build_book_path, and
    the long-lived s_state_file singleton (never-free-until-exit contract).
    
    Add gtest-gnc-state.cpp (10 tests, 2 suites) covering the public API and
    both the file- and database-URI base-name paths, and register it in the
    app-utils test CMakeLists.

commit ce4099d57d3d35f908e133bc3f712b4375b871ad
Author: Brent McBride <mcbridebt at hotmail.com>
Date:   Tue Jun 23 21:22:13 2026 -0700

    Rename gnc-state.c to gnc-state.cpp
    
    Build the file as C++ in preparation for modernization. The body is
    unchanged; the only enabling change is adding extern "C" guards to
    gnc-gkeyfile-utils.h, whose gnc_key_file_* functions gnc-state is now
    the first C++ consumer of.



Summary of changes:
 libgnucash/app-utils/CMakeLists.txt                |   2 +-
 .../app-utils/{gnc-state.c => gnc-state.cpp}       | 240 ++++++++---------
 libgnucash/app-utils/gnc-state.h                   |   2 +-
 libgnucash/app-utils/test/CMakeLists.txt           |  23 ++
 libgnucash/app-utils/test/gtest-gnc-state.cpp      | 284 +++++++++++++++++++++
 libgnucash/core-utils/gnc-gkeyfile-utils.h         |   7 +
 po/POTFILES.in                                     |   2 +-
 7 files changed, 441 insertions(+), 119 deletions(-)
 rename libgnucash/app-utils/{gnc-state.c => gnc-state.cpp} (52%)
 create mode 100644 libgnucash/app-utils/test/gtest-gnc-state.cpp



More information about the gnucash-patches mailing list