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
Redmine#7871: use VarRefValueToJson consistently #2476
Redmine#7871: use VarRefValueToJson consistently #2476
Conversation
93aa2b2
to
2f1b5b5
Compare
I added a commit that copies and frees |
I think there should be a changelog entry for all the functions that now accept any kind of container. This PR is big though! I got through some of it, but I need to continue this later. I had to make the comments on each commit because the diff is too big for github to show in the PR itself. For this reason I ask that you don't update the branch just yet, I'd like to pick up in the same place. I'll let you know when I'm done. |
I can list the functions in the cleanup stage after the code is finished. Do you need the list sooner? I made the changes I acknowledged on your comments so far in my local copy, and will rebase and resubmit when you give the go-ahead. Thank you for reviewing. I think this PR, besides helping performance, will substantially improve CFEngine functions and data containers. I'm sorry it's big but the behavior is best introduced all at once, in my opinion. |
No, that's ok, we can take care of that at the end.
Good, I'm still working on it.
Oh, certainly, I'm not arguing with that! :-) |
Alright, I have looked at all the code, looks good to me apart from the comments. The tests I only took a very brief look at, it's quite extensive. I assume that if you run the new tests with the old code, they will fail now because they will attempt to use JSON? Otherwise it would be a good confirmation that you did the test conversion correctly. |
Yes, the new tests fail against the old code. |
ca15351
to
f7a82b4
Compare
OK, I have made the adjustment for multiple array indices so the test from #2492 passes now. It was a one-line fix. All the other acceptance tests pass too. This is rebased, squashed, and ready for final review. The list of modified functions is at the top of this PR. |
f7a82b4
to
e291e1a
Compare
Thanks for updating. One last thing, can you put the entire block of information in the top of the PR in the commit message (apart from the last sentence, perhaps). It should be there for future reading. |
trigger build |
e291e1a
to
18423a4
Compare
I updated the commit message as suggested, I hope that's what you were looking for. |
Thanks! There a few tests that fail with this though.
In addition,
It looks like only the order has changed, not the content. I vaguely recall us talking about canonical JSON at some point, where all JSON keys would be sorted. But maybe that doesn't apply to lists? I'm puzzled why this only fails on non-Linux platforms. Any idea, just looking at the test case? And finally |
18423a4
to
81cda98
Compare
@kacf the |
5825886
to
d1e2fbd
Compare
The |
Don't use staging anymore, we want to move away from that structure. Use I guess the fact that you need scopeless and namespaceless variables is proof that it works, and hence the checks are not needed. Looks good to me. |
trigger build |
FYI, your beast baby, Do you have access to that one? This is the output from RHEL7:
|
…eeded VarRefValueToJson() was no longer used so VarRefValueToJsonAllowScalars() was renamed to it. Fixes a bug in VarRefValueToJsonAllowScalars() that leaked cf_nulls (typo: used value instead of rp). Fixes a bug in SeqShuffle() so it doesn't crash with a 0-length sequence. For https://dev.cfengine.com/issues/7871 the following functions now take a list or an array or a data container, or inline JSON: filter(), getindices(), getvalues(), join(), length(), maplist(), reverse(), unique(), intersection(), difference(), shuffle(), sort(), storejson(), string_mustache(), sublist(), sum(), product(); all the rewritten function got new acceptance tests. Some tests were redundant and thus removed. The following functions were left alone because they're either not needed or too tricky due to legacy issues: regarray(), reglist(), makerule(), nth() We only create copies of the variables if needed, and free them only in that case, which will improve performance. Changelog: Allow inline JSON to be used in function calls (Redmine#7871).
d1e2fbd
to
5916b28
Compare
@kacf OK, I moved the test out of I have no idea why |
Regarding the scopeless thing, what actually happens in Normally that lookup is not necessary because we try to parse as inline JSON as soon as possible, but |
I have to admit that I barely understand this test myself, if so only at a conceptual level. Digging into it would be time consuming for me. But you wrote it back in the day, didn't you? I'm hoping you still remember it well enough to spot the problem without too much trouble. :-) If you have any problems building enterprise though, just let me know! The test fails across the board on all platforms, and never fails anywhere else (it's not one of those timing dependent "may-sometimes-fail-for-no-reason" cases), so it's definitely being triggered by your changes. |
OTOH I also see it as a natural development: We now place different demands on the contents of the variable table compared to data we parse from function parameters, so it's only natural the asserted invariants need to change over time. But yeah, it probably could be prettier! |
Your great expectations are my command: see https://github.com/cfengine/enterprise/pull/298 for the updated test that works for me. |
* inline-json: Redmine#7871: use VarRefValueToJson consistently and copy only when needed
Merged manually. Thanks for the great work Ted, and for updating the incredibly complex Enterprise test! |
The remaining work will be discussed https://dev.cfengine.com/issues/7871 |
VarRefValueToJson()
was no longer used soVarRefValueToJsonAllowScalars()
was renamed to itVarRefValueToJsonAllowScalars()
that leakedcf_null
s (typo: usedvalue
instead ofrp
)SeqShuffle()
so it doesn't crash with a 0-length sequencefilter()
,getindices()
,getvalues()
,join()
,length()
,maplist()
,reverse()
,unique()
,intersection()
,difference()
,shuffle()
,sort()
,storejson()
,string_mustache()
,sublist()
,sum()
,product()
regarray()
,reglist()
,makerule()
,nth()
The bulk of this PR is new tests. I did it thus: 1) make sure the old test works, 2) convert the old test to expected JSON style, 3) when the converted test works fine, add at least one inline JSON test to verify operation, and usually even more cases. The rest of the C code changes are pretty small and remove a significant amount of non-standard code in favor of a uniform data reference interface.
We may have performance concerns about creating and destroying containers on every call. I don't think it's a significant issue in normal usage, but we can optimize it after the merge (correctness before premature optimization). I added a second commit that optimizes the common case of needing a read-only reference to a
JsonElement
from the variable table. Note that second commit also fixes some missing places where we should have been destroyingJsonElement
s.All the acceptance tests passed for me.
I can break the first two bugfixes into separate commits if you prefer.