This commit is contained in:
Christopher Lam 2025-02-10 08:47:38 +08:00 committed by GitHub
commit b16c2abc28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 15 deletions

View File

@ -29,3 +29,20 @@
(load-and-reexport (sw_engine)
(gnucash engine business-core)
(gnucash engine gnc-numeric))
(export gnc:price-ref)
(define price-guardian (make-guardian))
(define (reclaim-prices)
(let ((price (price-guardian)))
(when price
(gnc-price-unref price)
(reclaim-prices))))
(add-hook! after-gc-hook reclaim-prices)
(define (gnc:price-ref price)
(gnc-price-ref price)
(price-guardian price))

View File

@ -222,6 +222,10 @@ gnc_run_report_with_error_handling (gint report_id, gchar ** data, gchar **errms
html = scm_car (res);
captured_error = scm_cadr (res);
/* Force a gc run after the report is finished to ensure that
guardians are called to unref objects */
scm_gc();
if (!scm_is_false (html))
{
*data = gnc_scm_to_utf8_string (html);

View File

@ -331,7 +331,7 @@ by preventing negative stock balances.<br/>")
(if (gnc-commodity-equiv currency (gnc-price-get-commodity p))
(set! price (gnc-price-invert p))))
price-list)
(gnc-price-ref price)
(gnc:price-ref price)
(gnc-price-list-destroy price-list)
price)))
@ -470,7 +470,6 @@ by preventing negative stock balances.<br/>")
(if (not (gnc-numeric-zero-p (gnc:gnc-monetary-amount trans-price)))
;; We can exchange the price from this transaction into the report currency
(begin
(if price (gnc-price-unref price))
(set! pricing-txn trans)
(set! price trans-price)
(gnc:debug "Transaction price is " (gnc:monetary->string price))
@ -942,15 +941,9 @@ by preventing negative stock balances.<br/>")
row-style
activecols)
(if (and (not use-txn) price) (gnc-price-unref price))
(table-add-stock-rows-internal rest (not odd-row?))
)
(begin
(if (and (not use-txn) price) (gnc-price-unref price))
(table-add-stock-rows-internal rest odd-row?)
)
)
)))
(table-add-stock-rows-internal rest odd-row?)))))
(set! work-to-do (gnc:accounts-count-splits accounts))
(table-add-stock-rows-internal accounts #t)))

View File

@ -143,10 +143,8 @@
"number-cell" value)))
;;(display (format #f "Shares: ~6d " (gnc-numeric-to-double units)))
;;(display units) (newline)
(if price (gnc-price-unref price))
(table-add-stock-rows-internal rest (not odd-row?)))
(begin (if price (gnc-price-unref price))
(table-add-stock-rows-internal rest odd-row?))))))
(table-add-stock-rows-internal rest odd-row?)))))
(set! work-to-do (length accounts))
(table-add-stock-rows-internal accounts #t)))
@ -211,7 +209,7 @@
(car price)
(gnc-price-invert (car price))))
(v (gnc-price-get-value the_price)))
(gnc-price-ref (car price))
(gnc:price-ref (car price))
(cons (car price) v))
(cons #f (gnc-numeric-zero)))))
(if price (gnc-price-list-destroy price))
@ -223,7 +221,7 @@
(cond
((null? price) (cons #f 0))
(else (let ((p (car price)))
(gnc-price-ref p)
(gnc:price-ref p)
(gnc-price-list-destroy price)
(cons p (gnc-price-get-value p))))))))
((pricedb-nearest)
@ -233,7 +231,7 @@
pricedb foreign (time64CanonicalDayTime date)))
(fn (if (and price (> (length price) 0))
(let* ((v (gnc-price-get-value (car price))))
(gnc-price-ref (car price))
(gnc:price-ref (car price))
(cons (car price) v))
(cons #f (gnc-numeric-zero)))))
(if price (gnc-price-list-destroy price))