Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Price guardian #1716
base: stable
Are you sure you want to change the base?
Price guardian #1716
Changes from all commits
df1ad99
4e3ddca
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bugs me. Does
(gnc:price-ref price)
putprice
or*price
(in C's meaning, Guile having no way to express it) on the guardian's list? If it's*price
then no problem; otherwise this will leak the original*price
and iftrans-price
will get an extra unref.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, the reports shouldn't generally call gnc-price-ref/unref, and shuould leave it to the guardians. I don't know whether it calls
price
or*price
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't generally, only the two portfolio reports do. Nothing in Scheme except test-engine-extras.scm writes to price objects, so one option would be to copy the few things that reports need from prices (currency, commodity, time, and value) and not swig any of the price API.
Do you understand the problem with
(set! price trans-price)
if the guardian is using the addresses ofprice
andtrans-price
instead of the addresses that they point to (e.g.*price
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two GncPrice pointers,
p1
andp2
.price
is initialized top1
andtrans-price
top2
.price-guardian
is called onprice
andtrans-price
when each is initialized, then(set! price trans-price)
happens and bothprice
andtrans-price
equalp2
.If
(price-guardian price)
causes the guardian to keep track ofp1
(what I called the '*price' scenario) then after theset!
call it's garbage-collected and returned and unreffed byreclaim-prices
. Later when bothprice
andtrans-price
go out of scope (maybe at the end of the report render)p2
is garbage collected and can be unreffed byreclaim-prices
. All good.But if
(price-guardian price)
keeps a reference toprice
(the 'price' scenario) then it's not guardingp1
. It doesn't return anything untilprice
ortrans-price
go out of scope, and when they do it returnsp2
for each one, sop1
leaks andp2
gets unreffed twice. Not good.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see slightly and don't know the answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you need to find out. If it's the latter case then the
set!
has to go, it's a potential use-after-free crasher.Alternative: Remove all of the price refs and unrefs, no guardians. I don't think any of these calculations will be interrupted by a status bar update, and even if they can the user would have to somehow queue a price-delete to run during an idle for a price to become invalid while the report is loading. Pretty darn unlikely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, #1403 resurrected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, probably safer than this. But copying it into a scheme record would be safer still.