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.
With the new SRFI-64 implementation tests are failing without setting
expected and actual values on the test result. Dump the test-result-alist
to get more information.
Leverages the FakePrefsBackend from the previous commit to change the
fiscal year for testing.
Makes now_t a defaulted parameter of gnc_relative_date_to_time64 so
that we can inject different reference dates for testing.
because xaccAccountGetSplitList will create GList, scan and build SCM
reverse order, and scm_reverse.
xaccAccountGetSplits scans the vector, builds the SCM list in reverse.
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.
It's extremely out of date and we no longer use it to keep track
of our design decisions and suggestions.
Only a section on KVP policy has been move into kvp_doc.txt
as it may make sense there.
gnc_get_match_commodity_splits needs to scan the account splitlists to
find suitable splits upto end_date. Because splitlist is date-sorted,
use gnc_account_foreach_split_until_date to avoid scanning later
splits.
The scheme version is very inefficient: (1) it uses QofQuery to
retrieve all splits, and QofQuery is slow. (2) The whole splitlist
typically is thousands splits long needs to be converted from C to
guile via consing and reverse. (3) The scheme list is immediately
filtered to select "interesting" splits only.
This function performs all of the above using Account's efficient
methods, selecting only interesting splits into a GList. This list is
then converted to scheme via cons and reverse.
The QofQuery param_list is a GSList of const char*. Every SCM Query
would typically leak the GSList. This change will store the params
into the string cache, and the cached string is passed onto the
QofQuery param.
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.
xaccSplitComputeCapGains creates gains_split pointers in both the Cap Gains Split and its Income split to the original split, but the original's gains_split pointer can point to only one of them, the Cap Gains split. When the original split is freed both the Cap Gains split's and its Income split need their gains_split pointers NULLed or when it's the Income split's turn to be freed it will try to deref the dangling pointer.