Skip to content
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

libvcc: Fix STRING/STRANDS comparison without STRING folding #4148

Merged
merged 7 commits into from
Aug 16, 2024

Conversation

nigoroll
Copy link
Member

@nigoroll nigoroll commented Aug 1, 2024

I do not consider myself enough of an expert on VCC and would appreciate reviews by those who do.
Side note: STRING vs STRINGS vs. STRANDS is confusing

Fixes #4146

@nigoroll
Copy link
Member Author

nigoroll commented Aug 5, 2024

bugwash @walid-git was asked to review, thank you in advance.

@nigoroll nigoroll requested a review from walid-git August 5, 2024 13:37
Copy link
Member

@walid-git walid-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the changes generate syntactically correct C code and that the STRING/STRANDS comparison error is gone, there is still something wrong here:
With these changes, the following VCL code:

 if ("string" == debug.return_strands("string")) {
                    ...
        }

Will generate this C code:

 if (
        (0 == VRT_CompareStrands(TOSTRAND("string"), vrt_null_strands))
  ) {
  ...

The STRANDS part of debug.return_strands("string") is being translated to vrt_null_strands which is wrong. I need to look closer to find which part of the PR is causing this, but that might be related to the first commit. We should also improve test coverage to not only test the syntactic part but also the semantic.

@nigoroll nigoroll force-pushed the fix-strands-compare branch from 3a368c5 to 4dd1eee Compare August 12, 2024 14:34
@nigoroll
Copy link
Member Author

nigoroll commented Aug 12, 2024

@walid-git thank you very much for catching this significant regression. I have force-pushed an update, the delta is

diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index a348e9b83..cd4b03c2f 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -159,7 +159,11 @@ static void
 vcc_strands_edit(const struct expr *e1, const struct expr *e2)
 {
 
-       if (e2->nstr == 0)
+       assert(e2->fmt == STRANDS || e2->fmt == STRINGS);
+
+       if (e2->fmt == STRANDS)
+               VSB_cat(e1->vsb, VSB_data(e2->vsb));
+       else if (e2->nstr == 0)
                VSB_printf(e1->vsb, "vrt_null_strands");
        else if (e2->nstr == 1)
                VSB_printf(e1->vsb, "TOSTRAND(%s)", VSB_data(e2->vsb));

edit: the first force-push applied the fix to the wrong commit

Copy link
Member

@walid-git walid-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nigoroll. This looks good to me now. I left a comment for test coverage improvement.

bin/varnishtest/tests/v00019.vtc Outdated Show resolved Hide resolved
by moving test VCL from vcl_recv {} to vcl_init {}

As suggested by walid here: varnishcache#4148 (comment)
this almost halves runtime of the test case
@nigoroll nigoroll force-pushed the fix-strands-compare branch from fa02fce to 808a8dd Compare August 16, 2024 10:41
@nigoroll nigoroll merged commit 808a8dd into varnishcache:master Aug 16, 2024
1 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: all STRANDS are STRINGS again now
2 participants