Commit 41b4b679 authored by Geoff Simmons's avatar Geoff Simmons

The 'select' ENUM used for some the set operations defaults to UNIQUE.

NULL is no longer possible as an ENUM value.
parent 6e396497
Pipeline #414 skipped
......@@ -758,7 +758,7 @@ set
::
new OBJ = set(ENUM {none,start,both} anchor="none", BOOL utf8=0, BOOL posix_syntax=0, BOOL longest_match=0, INT max_mem=8388608, BOOL literal=0, BOOL never_nl=0, BOOL dot_nl=0, BOOL case_sensitive=1, BOOL perl_classes=0, BOOL word_boundary=0, BOOL one_line=0)
new OBJ = set(ENUM {none,start,both} anchor=none, BOOL utf8=0, BOOL posix_syntax=0, BOOL longest_match=0, INT max_mem=8388608, BOOL literal=0, BOOL never_nl=0, BOOL dot_nl=0, BOOL case_sensitive=1, BOOL perl_classes=0, BOOL word_boundary=0, BOOL one_line=0)
Initialize a set object that represents several patterns combined by
alternation -- ``|`` for "or".
......@@ -1007,7 +1007,7 @@ set.which
::
INT set.which(ENUM {FIRST,LAST} select=0)
INT set.which(ENUM {FIRST,LAST,UNIQUE} select=UNIQUE)
Returns a number indicating which pattern in a set matched in the most
recent invocation of ``.match()`` in the client or backend
......@@ -1015,9 +1015,9 @@ context. The number corresponds to the order in which patterns were
added to the set in ``vcl_init``, counting from 1.
If exactly one pattern matched in the most recent ``.match()`` call
(so that ``.nmatches()`` returns 1), then the number for that pattern
is returned. The ``select`` ENUM is ignored in this case, and can be
left out.
(so that ``.nmatches()`` returns 1), and the ``select`` ENUM is set to
``UNIQUE``, then the number for that pattern is returned. ``select``
defaults to ``UNIQUE``, so it can be left out in this case.
If more than one pattern matched in the most recent ``.match()`` call
(``.nmatches()`` > 1), then the ``select`` ENUM determines the integer
......@@ -1033,7 +1033,8 @@ if:
backend transaction, or if the previous call returned ``false``.
* More than one pattern in the set matched in the previous
``.match()`` call, but the ``select`` parameter is not set.
``.match()`` call, but the ``select`` parameter is set to ``UNIQUE``
(or left out, since ``select`` defaults to ``UNIQUE``).
Examples::
......@@ -1073,7 +1074,7 @@ set.string
::
STRING set.string(INT n=0, ENUM {FIRST,LAST} select=0)
STRING set.string(INT n=0, ENUM {FIRST,LAST,UNIQUE} select=UNIQUE)
Returns the string associated with the `nth` pattern added to the set,
or with the pattern in the set that matched in the most recent call to
......@@ -1098,9 +1099,10 @@ methods documented in the following.
* If ``n`` <= 0 and exactly one pattern in the set matched in the most
recent invocation of ``.match()`` (and hence ``.nmatches()`` returns
1), then select that pattern. The ``select`` parameter is ignored in
this case. So when exactly one pattern in the set matched, both
``n`` and ``select`` can be left out.
1), and ``select`` is set to ``UNIQUE``, then select that
pattern. ``select`` defaults to ``UNIQUE``, so when exactly one
pattern in the set matched, both ``n`` and ``select`` can be left
out.
* If ``n`` <= 0 and more than one pattern matched in the most recent
``.match()`` call (``.nmatches()`` > 1), then the selection of a
......@@ -1124,8 +1126,8 @@ the log, if:
* ``n`` <= 0, but the previous ``.match()`` call returned ``false``.
* ``n`` <= 0 and no value is given for the ``select`` ENUM, but more
than one pattern matched in the previous ``.match()`` call.
* ``n`` <= 0 and the ``select`` ENUM is ``UNIQUE`` (or default), but
more than one pattern matched in the previous ``.match()`` call.
* No string was associated with the pattern selected by ``n`` and
``select``; that is, the ``string`` parameter was not set in the
......@@ -1205,7 +1207,7 @@ set.backend
::
BACKEND set.backend(INT n=0, ENUM {FIRST,LAST} select=0)
BACKEND set.backend(INT n=0, ENUM {FIRST,LAST,UNIQUE} select=UNIQUE)
Returns the backend associated with the `nth` pattern added to the
set, or with the pattern in the set that matched in the most recent
......@@ -1258,7 +1260,7 @@ set.sub
::
STRING set.sub(STRING text, STRING rewrite, STRING fallback="**SUB METHOD FAILED**", INT n=0, ENUM {FIRST,LAST} select=0)
STRING set.sub(STRING text, STRING rewrite, STRING fallback="**SUB METHOD FAILED**", INT n=0, ENUM {FIRST,LAST,UNIQUE} select=UNIQUE)
Returns the result of the method call ``.sub(text, rewrite, fallback)``,
as documented above for the ``regex`` interface, invoked on the `nth`
......
......@@ -76,8 +76,6 @@ struct task_set_match {
size_t nmatches;
};
static const char null[] = "NULL";
static inline int
decimal_digits(int n)
{
......@@ -470,15 +468,15 @@ get_match_idx(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects,
return -1;
}
if (task->nmatches > 1) {
if (selects == NULL) {
if (selects == vmod_enum_UNIQUE) {
VERR(ctx, "%s.%s(%lld): %d successful matches",
set->vcl_name, method, n, task->nmatches);
return -1;
}
if (strcmp(selects, "LAST") == 0)
if (selects == vmod_enum_LAST)
idx = task->nmatches - 1;
else
AZ(strcmp(selects, "FIRST"));
assert(selects == vmod_enum_FIRST);
}
WS_Assert_Allocated(ctx->ws, task->matches,
task->nmatches * sizeof(int));
......@@ -512,8 +510,7 @@ vmod_set_sub(VRT_CTX, struct vmod_re2_set *set, VCL_STRING text,
if (idx < 0)
return NULL;
if (!vbit_test(set->added[RE_ADDED], idx)) {
if (selects == NULL)
selects = null;
AN(selects);
VERR(ctx, "%s.sub(%s, %s, %lld, %s): Pattern %d was not saved",
set->vcl_name, text, rewrite, n, selects, idx + 1);
return NULL;
......@@ -538,8 +535,7 @@ vmod_set_string(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
if (idx < 0)
return NULL;
if (!vbit_test(set->added[STR_ADDED], idx)) {
if (selects == NULL)
selects = null;
AN(selects);
VERR(ctx, "%s.string(%lld, %s): String %lld was not added",
set->vcl_name, n, selects, idx + 1);
return NULL;
......@@ -564,8 +560,7 @@ vmod_set_backend(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
if (idx < 0)
return NULL;
if (!vbit_test(set->added[BE_ADDED], idx)) {
if (selects == NULL)
selects = null;
AN(selects);
VERR(ctx, "%s.backend(%lld, %s): Backend %lld was not added",
set->vcl_name, n, selects, idx + 1);
return NULL;
......
......@@ -251,9 +251,9 @@ varnish v1 -vcl {
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: s.string.1, NULL.: String 1 was not added$"
expect * = VCL_Error "^vmod re2 error: s.string.1, UNIQUE.: String 1 was not added$"
expect * = VCL_Error "^vmod re2 error: s.string.0, FIRST.: String 1 was not added$"
expect * = VCL_Error "^vmod re2 error: b.backend.2, NULL.: Backend 2 was not added$"
expect * = VCL_Error "^vmod re2 error: b.backend.2, UNIQUE.: Backend 2 was not added$"
expect * = VCL_Error "^vmod re2 error: b.backend.0, LAST.: Backend 2 was not added$"
expect * = End
......
......@@ -69,7 +69,7 @@ client c1 {
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: n.sub.bbbbbb, bb, 1, NULL.: Pattern 1 was not saved$"
expect * = VCL_Error "^vmod re2 error: n.sub.bbbbbb, bb, 1, UNIQUE.: Pattern 1 was not saved$"
expect * = VCL_Error "^vmod re2 error: n.sub.bbbbbb, bb, 0, FIRST.: Pattern 1 was not saved$"
expect * = End
......
......@@ -876,7 +876,7 @@ Example::
+ " patterns from the set");
}
$Method INT .which(ENUM {FIRST, LAST} select=0)
$Method INT .which(ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
Returns a number indicating which pattern in a set matched in the most
recent invocation of ``.match()`` in the client or backend
......@@ -884,9 +884,9 @@ context. The number corresponds to the order in which patterns were
added to the set in ``vcl_init``, counting from 1.
If exactly one pattern matched in the most recent ``.match()`` call
(so that ``.nmatches()`` returns 1), then the number for that pattern
is returned. The ``select`` ENUM is ignored in this case, and can be
left out.
(so that ``.nmatches()`` returns 1), and the ``select`` ENUM is set to
``UNIQUE``, then the number for that pattern is returned. ``select``
defaults to ``UNIQUE``, so it can be left out in this case.
If more than one pattern matched in the most recent ``.match()`` call
(``.nmatches()`` > 1), then the ``select`` ENUM determines the integer
......@@ -902,7 +902,8 @@ if:
backend transaction, or if the previous call returned ``false``.
* More than one pattern in the set matched in the previous
``.match()`` call, but the ``select`` parameter is not set.
``.match()`` call, but the ``select`` parameter is set to ``UNIQUE``
(or left out, since ``select`` defaults to ``UNIQUE``).
Examples::
......@@ -935,7 +936,7 @@ Examples::
# unsuccessful.
}
$Method STRING .string(INT n=0, ENUM {FIRST, LAST} select=0)
$Method STRING .string(INT n=0, ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
Returns the string associated with the `nth` pattern added to the set,
or with the pattern in the set that matched in the most recent call to
......@@ -960,9 +961,10 @@ methods documented in the following.
* If ``n`` <= 0 and exactly one pattern in the set matched in the most
recent invocation of ``.match()`` (and hence ``.nmatches()`` returns
1), then select that pattern. The ``select`` parameter is ignored in
this case. So when exactly one pattern in the set matched, both
``n`` and ``select`` can be left out.
1), and ``select`` is set to ``UNIQUE``, then select that
pattern. ``select`` defaults to ``UNIQUE``, so when exactly one
pattern in the set matched, both ``n`` and ``select`` can be left
out.
* If ``n`` <= 0 and more than one pattern matched in the most recent
``.match()`` call (``.nmatches()`` > 1), then the selection of a
......@@ -986,8 +988,8 @@ the log, if:
* ``n`` <= 0, but the previous ``.match()`` call returned ``false``.
* ``n`` <= 0 and no value is given for the ``select`` ENUM, but more
than one pattern matched in the previous ``.match()`` call.
* ``n`` <= 0 and the ``select`` ENUM is ``UNIQUE`` (or default), but
more than one pattern matched in the previous ``.match()`` call.
* No string was associated with the pattern selected by ``n`` and
``select``; that is, the ``string`` parameter was not set in the
......@@ -1060,7 +1062,7 @@ Examples::
# vcl_synth is implemented as shown above
$Method BACKEND .backend(INT n=0, ENUM {FIRST, LAST} select=0)
$Method BACKEND .backend(INT n=0, ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
Returns the backend associated with the `nth` pattern added to the
set, or with the pattern in the set that matched in the most recent
......@@ -1108,7 +1110,7 @@ Example::
$Method STRING .sub(STRING text, STRING rewrite,
STRING fallback="**SUB METHOD FAILED**",
INT n=0, ENUM {FIRST, LAST} select=0)
INT n=0, ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
Returns the result of the method call ``.sub(text, rewrite, fallback)``,
as documented above for the ``regex`` interface, invoked on the `nth`
......
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