-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix protect/unprotect rchk issues #27
Comments
I had a similar problem with the UP checks. Conditional UNPROTECT/PROTECT in loops do not work well for What I would do that I think will fix the problem is do one |
I made some changes in https://github.com/alexcb/rjson/tree/simplify-protection-logic which gets the warnings down to a single imbalance:
I'm scratching my head on what's causing this one. |
My 2c of advice is to forsake the seeming convenience of the early return. It makes keeping track of the logic harder, and it makes it easier to introduce bugs later even if the code is correct when first written (e.g. you have one return that needs to UNPROTECT(2) vs the others; if you add more code later you need to make sure that remains right everywhere). I reviewed the code and at first I thought it was balanced, although it is complicated enough I wouldn't have bet my life on it. Then, I searched for each return statement in the function, and noticed that this return is unbalanced. There is the original PROTECT left that needs to be UNPROTECT(1), AFAICT (untested, so I could be wrong). I don't trust myself to be able to rigorously maintain multiple exit points from my functions, so I very rarely use multiple returns, even though I am often tempted to do so. Even if the code does turn out to be balanced (and I'm wrong), it still worth writing simpler code that |
Great eyes @brodieG, that was a bug I introduced with this refactor. It's been fixed in bb313d7 I agree it's complicated code to look over -- I wrote it over a decade ago, and find myself scratching my head at times.
perhaps having an Thank you very much for helping me get this cleaned up to the state where I can try a new update-submission to CRAN. |
rjson has two functions with loops that build up elements and protects them as they are created.
upon an error, a call to
UNPROTECT( objs );
is made whereobjs
is anint
which is incremented for eachPROTECT
; however the rchk PROTECT/UNPROTECT linter does not support this form (however R does, and rjson predates these rchk checks).I then also tried calling UNPROTECT in a loop ( see 9d05c9b ) but that introduced other issues.
A CRAN update is blocked until this is resolved.
The text was updated successfully, but these errors were encountered: