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