Add missing gnc_numeric wrapping for two Split methods:
- GetNoclosingBalance → GncNumeric
- GetCapGains → GncNumeric
Refactor test_price_and_wrapping.py to create all test data
programmatically in in-memory sessions, eliminating external data file
dependencies (pricedb1.gml2, sample1.gnucash) and XML backend
requirement. All 27 tests now run unconditionally.
Register tests in CI: add imports to runTests.py.in and add
test_price_and_wrapping.py to CMakeLists.txt dist list.
Wrap GncPriceDB.get_latest_price, get_nearest_price, and
get_nearest_before_price to return GncNumeric instead of raw
_gnc_numeric SWIG proxies.
Add double-wrap safety in ClassFromFunctions.__init__: if a wrapper
object is passed as instance=, unwrap it to the underlying SWIG proxy.
This prevents breakage when callers re-wrap a return value that changed
from a raw SWIG proxy to a wrapper class, e.g.
GncNumeric(instance=pricedb.get_latest_price(...)).
New tests:
TestGetPriceReturnsGncNumeric (4 tests):
get_latest_price, get_nearest_price, get_nearest_before_price
return GncNumeric; arithmetic works on the result.
TestDoubleWrapProtection (4 tests):
GncNumeric, GncCommodity double-wrap; raw SWIG proxy still works.
Many Python binding methods silently returned raw SwigPyObject pointers
instead of proper Python wrapper objects because the methods_return_instance
dicts were incomplete. This adds the missing entries and activates the
DeprecationWarning in the SWIG typemap fallback path from PR 1.
Return-type wrapping fixes (gnucash_core.py):
GncPrice (new dict — no wrapping existed before):
get_commodity → GncCommodity, get_currency → GncCommodity,
clone → GncPrice, get_value → GncNumeric
GncPriceDB (added to existing dict):
nth_price → GncPrice, lookup_day_t64 → GncPrice,
convert_balance_nearest_before_price_t64 → GncNumeric
GncPriceDB (new list wrapping):
lookup_latest_any_currency → list[GncPrice],
lookup_nearest_before_any_currency_t64 → list[GncPrice],
lookup_nearest_in_time_any_currency_t64 → list[GncPrice]
GncCommodity: obtain_twin → GncCommodity,
get_namespace_ds → GncCommodityNamespace
Account: get_currency_or_parent → GncCommodity,
GetLotList → list[GncLot]
GncLot: get_split_list → list[Split]
Example script cleanup:
Remove type(x).__name__ == 'SwigPyObject' workarounds from
gnc_convenience.py, gncinvoicefkt.py, str_methods.py — these are
no longer needed now that methods return proper wrapper objects.
SWIG typemap (gnucash_core.i):
Activate DeprecationWarning on the .instance fallback path, replacing
the TODO placeholder from the typemap compatibility layer commit.
New test file (test_price_and_wrapping.py):
18 tests covering all wrapping fixes and typemap compatibility,
using in-repo test data (pricedb1.gml2, sample1.gnucash).
Tests auto-skip when XML backend is unavailable.
Add GNC_ACCEPT_WRAPPER macro that generates %typemap(in) entries for
all core engine and business pointer types. These typemaps accept both
raw SWIG pointers (zero-overhead fast path) and ClassFromFunctions
wrapper objects (fallback path that extracts .instance).
This is pure infrastructure for an upcoming change that fixes missing
return-type wrapping in gnucash_core.py. Once methods like
GncPriceDB.nth_price() return proper GncPrice wrapper objects instead
of raw SwigPyObjects, existing code that passes those objects to
gnucash_core_c C functions would break. These typemaps prevent that
breakage: the C functions transparently unwrap the .instance pointer.
Covered types:
Core: Account, Split, Transaction, GNCLot, gnc_commodity,
gnc_commodity_namespace, gnc_commodity_table, GNCPrice,
GNCPriceDB, QofBook, QofSession, GncGUID
Business: GncCustomer, GncEmployee, GncVendor, GncJob,
GncAddress, GncBillTerm, GncTaxTable, GncInvoice, GncEntry
GncOwner is excluded — it has its own custom type-dispatching typemaps.
Existing files/databases obviously should still be loaded. What's
changed is that databases no longer need to be loaded to force creation,
they do that on their own.
when creating new file.
Reverts the fix for https://bugs.gnucash.org/show_bug.cgi?id=726891. The
underlying problem, that a new SQL database needed to be loaded to force
its creation, is no longer a problem. It was probably corrected as part
of the C++ rewrite of the SQL backend.
pass -DLEAKS=ON or -DODR=ON to enable these features. They have an
effect only with CMAKE_BUILD_TYPE=Asan and don't work on Apple because
Apple clang doesn't enable them.
There is a new find module since cmake 3.12. Cmake 3.27 will start
emitting warnings if the old modules are still in use.
Current implementation supports both. As soon as we can bump our minimal
cmake version to 3.12, the old support code can be dropped as well.
==64824== 171 (88 direct, 83 indirect) bytes in 1 blocks are definitely lost in loss record 392 of 418
==64824== at 0x4843FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==64824== by 0x528A935: qof_session_new (qofsession.cpp:148)
==64824== by 0x141832: main (sqlite3test.c:34)
Looks like a SWIG bug, creating an extra variable that it doesn't use
bindings/python/gnucash_core.c: In function ‘_wrap_xaccAccountGetReconcileLastDate’:
bindings/python/gnucash_core.c:10096:10: warning: unused variable ‘secs20’ [-Wunused-variable]
10096 | time64 secs20 ;
| ^~~~~~
bindings/python/gnucash_core.c: In function ‘_wrap_xaccAccountGetReconcilePostponeDate’:
bindings/python/gnucash_core.c:10298:10: warning: unused variable ‘secs20’ [-Wunused-variable]
10298 | time64 secs20 ;
| ^~~~~~
bindings/python/gnucash_core.c: In function ‘_wrap_qof_query_date_predicate_get_date’:
bindings/python/gnucash_core.c:20237:10: warning: unused variable ‘secs20’ [-Wunused-variable]
20237 | time64 secs20 ;
| ^~~~~~
The root cause of which is that on recent releases of GLib (recent
meaning 2.66 in the current Debian stable!) g_type_instance_get_private
looks in the wrong place for the private data. When running the script
in question it returned NULL and since the code didn't check for a valid
pointer, it crashed.
So this change replaces all calls to g_type_instance_get_private with
the function [type_prefix]_get_instance_private() added in glib-2.36
except for two register2 files that have been removed from master; those
are ignored to avoid unnecessary merge conflicts.
Python bindings already have some wrapping objects for
qof predicates. This adds the one missing for GncNumeric
comparisons.
Additionally fixes a wrong number for QOF_NUMERIC_MATCH_ANY
in example file.
Leave it to users to categorize their non-currency commodities. In the
QIF importer default non-classifiable commodities to
GNC_COMMODITY_NS_NONCURRENCY.