Commit 8f7a8518 authored by Geoff Simmons's avatar Geoff Simmons

Don't copy the subject string if it's already in workspace.

parent b0c33f72
Pipeline #203 skipped
...@@ -329,27 +329,22 @@ Version 2.0: compatible with Varnish 5.1 ...@@ -329,27 +329,22 @@ Version 2.0: compatible with Varnish 5.1
LIMITATIONS LIMITATIONS
=========== ===========
Regular expressions passed into the constructor and into ``match_dyn``
are compiled at run-time, so there are no errors at VCL compile-time
for invalid expressions. If an expression is invalid, then a
``VCL_error`` message is emitted to the Varnish log, matches always
fail, and errors in the constructor can be inspected with ``failed``
and ``error``.
The VMOD allocates memory for captured subexpressions from Varnish The VMOD allocates memory for captured subexpressions from Varnish
workspaces, whose sizes are determined by the runtime parameters workspaces, whose sizes are determined by the runtime parameters
``workspace_backend``, for calls within the ``vcl_backend_*`` ``workspace_backend``, for calls within the ``vcl_backend_*``
subroutines, and ``workspace_client``, for the other VCL subs. The subroutines, and ``workspace_client``, for the other VCL subs. The
VMOD copies the string to be matched into the workspace, along with VMOD copies the string to be matched into the workspace, if it's not
some overhead. For typical usage, the default workspace sizes are already in the workspace, and also uses workspace to save data about
probably enough; but if you are matching against many, long strings in backreferences.
each client or backend context, you might need to increase the Varnish
parameters for workspace sizes. If the VMOD cannot allocate enough For typical usage, the default workspace sizes are probably enough;
workspace, then a ``VCL_error`` message is emitted, and the match but if you are matching against many, long strings in each client or
methods as well as ``backref`` will fail. (If you're just using the backend context, you might need to increase the Varnish parameters for
regexen for matching and not to capture backrefs, then you might as workspace sizes. If the VMOD cannot allocate enough workspace, then a
well just use the standard VCL operators ``~`` and ``!~``, and save ``VCL_error`` message is emitted, and the match methods as well as
the workspace.) ``backref`` will fail. (If you're just using the regexen for matching
and not to capture backrefs, then you might as well just use the
standard VCL operators ``~`` and ``!~``, and save the workspace.)
``backref`` can extract up to 10 subexpressions, in addition to the ``backref`` can extract up to 10 subexpressions, in addition to the
full expression indicated by backref 0. If a ``match`` or full expression indicated by backref 0. If a ``match`` or
......
...@@ -136,8 +136,7 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task) ...@@ -136,8 +136,7 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task)
{ {
ov_t *ov; ov_t *ov;
int s, nov[MAX_OV]; int s, nov[MAX_OV];
uintptr_t snap; size_t cp, len;
size_t cp;
AN(vre); AN(vre);
if (subject == NULL) if (subject == NULL)
...@@ -173,10 +172,11 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task) ...@@ -173,10 +172,11 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task)
} }
task->len = sizeof(*ov); task->len = sizeof(*ov);
snap = WS_Snapshot(ctx->ws); len = strlen(subject);
ov->subject = WS_Copy(ctx->ws, (const void *) subject, -1); if (WS_Inside(ctx->ws, subject, subject + len))
if (ov->subject == NULL) { ov->subject = subject;
WS_Reset(ctx->ws, snap); else if ((ov->subject = WS_Copy(ctx->ws, (const void *) subject, len))
== NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, VSLb(ctx->vsl, SLT_VCL_Error,
"vmod re: insufficient workspace"); "vmod re: insufficient workspace");
return 0; return 0;
......
...@@ -265,27 +265,22 @@ Version 2.0: compatible with Varnish 5.1 ...@@ -265,27 +265,22 @@ Version 2.0: compatible with Varnish 5.1
LIMITATIONS LIMITATIONS
=========== ===========
Regular expressions passed into the constructor and into ``match_dyn``
are compiled at run-time, so there are no errors at VCL compile-time
for invalid expressions. If an expression is invalid, then a
``VCL_error`` message is emitted to the Varnish log, matches always
fail, and errors in the constructor can be inspected with ``failed``
and ``error``.
The VMOD allocates memory for captured subexpressions from Varnish The VMOD allocates memory for captured subexpressions from Varnish
workspaces, whose sizes are determined by the runtime parameters workspaces, whose sizes are determined by the runtime parameters
``workspace_backend``, for calls within the ``vcl_backend_*`` ``workspace_backend``, for calls within the ``vcl_backend_*``
subroutines, and ``workspace_client``, for the other VCL subs. The subroutines, and ``workspace_client``, for the other VCL subs. The
VMOD copies the string to be matched into the workspace, along with VMOD copies the string to be matched into the workspace, if it's not
some overhead. For typical usage, the default workspace sizes are already in the workspace, and also uses workspace to save data about
probably enough; but if you are matching against many, long strings in backreferences.
each client or backend context, you might need to increase the Varnish
parameters for workspace sizes. If the VMOD cannot allocate enough For typical usage, the default workspace sizes are probably enough;
workspace, then a ``VCL_error`` message is emitted, and the match but if you are matching against many, long strings in each client or
methods as well as ``backref`` will fail. (If you're just using the backend context, you might need to increase the Varnish parameters for
regexen for matching and not to capture backrefs, then you might as workspace sizes. If the VMOD cannot allocate enough workspace, then a
well just use the standard VCL operators ``~`` and ``!~``, and save ``VCL_error`` message is emitted, and the match methods as well as
the workspace.) ``backref`` will fail. (If you're just using the regexen for matching
and not to capture backrefs, then you might as well just use the
standard VCL operators ``~`` and ``!~``, and save the workspace.)
``backref`` can extract up to 10 subexpressions, in addition to the ``backref`` can extract up to 10 subexpressions, in addition to the
full expression indicated by backref 0. If a ``match`` or full expression indicated by backref 0. If a ``match`` or
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment