Skip to content

Stash objcore references until the end of the task to avoid copies #4269

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions bin/varnishd/cache/cache_vrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ VRT_synth(VRT_CTX, VCL_INT code, VCL_STRING reason)
return;
}

if (reason && !WS_Allocated(ctx->ws, reason, -1)) {
reason = WS_Copy(ctx->ws, reason, -1);
if (!reason) {
VRT_fail(ctx, "Workspace overflow");
return;
}
}
Comment on lines -96 to -102
Copy link
Member

Choose a reason for hiding this comment

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

This might not be safe actually:

return (synth(200, some_vmod.some_string()));

In that case we can't assume a lifetime beyond the VRT_synth() call for the reason argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

see #4269 (comment) regarding this and the next four review comments.


if (ctx->req == NULL) {
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
ctx->bo->err_code = (uint16_t)code;
Expand Down Expand Up @@ -445,12 +437,11 @@ VRT_StrandsWS(struct ws *ws, const char *h, VCL_STRANDS s)
}
}

if (q == NULL) {
if (h == NULL)
return ("");
if (WS_Allocated(ws, h, -1))
return (h);
} else if (h == NULL && WS_Allocated(ws, q, -1)) {
if (q == NULL && h == NULL)
return ("");
if (q == NULL)
return (h);
if (h == NULL) {
Comment on lines -448 to +444
Copy link
Member

Choose a reason for hiding this comment

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

Likewise, we can't assume a task lifetime of the arguments.

for (i++; i < s->n; i++)
if (s->p[i] != NULL && *s->p[i] != '\0')
break;
Expand Down
6 changes: 0 additions & 6 deletions vmod/vmod_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,6 @@ xyzzy_concatenate(VRT_CTX, VCL_STRANDS s)

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
r = VRT_StrandsWS(ctx->ws, NULL, s);
if (r != NULL && *r != '\0')
AN(WS_Allocated(ctx->ws, r, strlen(r) + 1));
Comment on lines 647 to -649
Copy link
Member

Choose a reason for hiding this comment

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

If our concern is coverage for VRT_StrandsWS() then we need to keep a check that the result effectively belongs to the workspace.

return (r);
}

Expand All @@ -657,8 +655,6 @@ xyzzy_collect(VRT_CTX, VCL_STRANDS s)

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
r = VRT_STRANDS_string(ctx, s);
if (r != NULL && *r != '\0')
AN(WS_Allocated(ctx->ws, r, strlen(r) + 1));
Comment on lines -660 to -661
Copy link
Member

Choose a reason for hiding this comment

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

See previous.

return (r);
}

Expand Down Expand Up @@ -690,8 +686,6 @@ xyzzy_sethdr(VRT_CTX, VCL_HEADER hdr, VCL_STRANDS s)
VSLbs(ctx->vsl, SLT_LostHeader,
TOSTRAND(hdr->what + 1));
} else {
if (*b != '\0')
AN(WS_Allocated(hp->ws, b, strlen(b) + 1));
Comment on lines -693 to -694
Copy link
Member

Choose a reason for hiding this comment

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

See previous.

http_Unset(hp, hdr->what);
http_SetHeader(hp, b);
}
Expand Down