[master] f18fe9cba Use SF_Parse_Decimal() for double style parameters
Poul-Henning Kamp
phk at FreeBSD.org
Fri Jun 4 08:11:08 UTC 2021
commit f18fe9cba3b77cd7a545bb183f0c984b0be9037b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Jun 4 08:09:35 2021 +0000
Use SF_Parse_Decimal() for double style parameters
Annotate parameter tweak functions with v_matchproto_()
diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c
index d6a9c3fd2..89d1a1aa3 100644
--- a/bin/varnishd/mgt/mgt_param_bits.c
+++ b/bin/varnishd/mgt/mgt_param_bits.c
@@ -113,7 +113,7 @@ static const char * const VSL_tags[256] = {
# include "tbl/vsl_tags.h"
};
-static int
+static int v_matchproto_(tweak_t)
tweak_vsl_mask(struct vsb *vsb, const struct parspec *par, const char *arg)
{
unsigned j;
@@ -171,7 +171,7 @@ static const char * const debug_tags[] = {
NULL
};
-static int
+static int v_matchproto_(tweak_t)
tweak_debug(struct vsb *vsb, const struct parspec *par, const char *arg)
{
const char *s;
@@ -214,7 +214,7 @@ static const char * const feature_tags[] = {
NULL
};
-static int
+static int v_matchproto_(tweak_t)
tweak_feature(struct vsb *vsb, const struct parspec *par, const char *arg)
{
const char *s;
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 721e05292..b3148b857 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -55,50 +55,54 @@ static int
tweak_generic_double(struct vsb *vsb, volatile double *dest,
const char *arg, const char *min, const char *max, const char *fmt)
{
- volatile double u, minv = 0, maxv = 0;
+ volatile double u, minv = VRT_DECIMAL_MIN, maxv = VRT_DECIMAL_MAX;
+ const char *p, *err;
if (arg != NULL && arg != JSON_FMT) {
if (min != NULL) {
- minv = VNUM(min);
- if (isnan(minv)) {
- VSB_printf(vsb, "Illegal Min: %s\n", min);
+ p = min;
+ minv = SF_Parse_Decimal(&p, 0, &err);
+ if (errno) {
+ VSB_printf(vsb, "Min: %s (%s)\n", err, min);
return (-1);
}
}
if (max != NULL) {
- maxv = VNUM(max);
- if (isnan(maxv)) {
- VSB_printf(vsb, "Illegal Max: %s\n", max);
+ p = max;
+ maxv = SF_Parse_Decimal(&p, 0, &err);
+ if (errno) {
+ VSB_printf(vsb, "Max: %s (%s)\n", err, max);
return (-1);
}
}
- u = VNUM(arg);
- if (isnan(u)) {
- VSB_printf(vsb, "Not a number(%s)\n", arg);
+ p = arg;
+ u = SF_Parse_Decimal(&p, 0, &err);
+ if (errno) {
+ VSB_printf(vsb, "%s (%s)\n", err, arg);
return (-1);
}
- if (min != NULL && u < minv) {
+ if (u < minv) {
VSB_printf(vsb,
"Must be greater or equal to %s\n", min);
return (-1);
}
- if (max != NULL && u > maxv) {
+ if (u > maxv) {
VSB_printf(vsb,
"Must be less than or equal to %s\n", max);
return (-1);
}
*dest = u;
- } else
+ } else {
VSB_printf(vsb, fmt, *dest);
+ }
return (0);
}
/*--------------------------------------------------------------------*/
-int
-tweak_timeout(struct vsb *vsb, const struct parspec *par,
- const char *arg)
+int v_matchproto_(tweak_t)
+tweak_timeout(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile double *dest;
@@ -109,7 +113,7 @@ tweak_timeout(struct vsb *vsb, const struct parspec *par,
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_double(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile double *dest;
@@ -120,7 +124,7 @@ tweak_double(struct vsb *vsb, const struct parspec *par, const char *arg)
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_boolean(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *dest;
@@ -217,7 +221,7 @@ tweak_generic_uint(struct vsb *vsb, volatile unsigned *dest, const char *arg,
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_uint(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *dest;
@@ -306,7 +310,7 @@ tweak_generic_bytes(struct vsb *vsb, volatile ssize_t *dest, const char *arg,
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_bytes(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile ssize_t *dest;
@@ -317,7 +321,7 @@ tweak_bytes(struct vsb *vsb, const struct parspec *par, const char *arg)
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_bytes_u(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *d1;
@@ -335,7 +339,7 @@ tweak_bytes_u(struct vsb *vsb, const struct parspec *par, const char *arg)
* vsl_buffer and vsl_reclen have dependencies.
*/
-int
+int v_matchproto_(tweak_t)
tweak_vsl_buffer(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *d1;
@@ -350,7 +354,7 @@ tweak_vsl_buffer(struct vsb *vsb, const struct parspec *par, const char *arg)
return (0);
}
-int
+int v_matchproto_(tweak_t)
tweak_vsl_reclen(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *d1;
@@ -367,7 +371,7 @@ tweak_vsl_reclen(struct vsb *vsb, const struct parspec *par, const char *arg)
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_string(struct vsb *vsb, const struct parspec *par, const char *arg)
{
char **p = TRUST_ME(par->priv);
@@ -388,7 +392,7 @@ tweak_string(struct vsb *vsb, const struct parspec *par, const char *arg)
/*--------------------------------------------------------------------*/
-int
+int v_matchproto_(tweak_t)
tweak_poolparam(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile struct poolparam *pp, px;
@@ -458,7 +462,7 @@ tweak_poolparam(struct vsb *vsb, const struct parspec *par, const char *arg)
* limit, so they don't end up crossing.
*/
-int
+int v_matchproto_(tweak_t)
tweak_thread_pool_min(struct vsb *vsb, const struct parspec *par,
const char *arg)
{
@@ -472,7 +476,7 @@ tweak_thread_pool_min(struct vsb *vsb, const struct parspec *par,
return (0);
}
-int
+int v_matchproto_(tweak_t)
tweak_thread_pool_max(struct vsb *vsb, const struct parspec *par,
const char *arg)
{
More information about the varnish-commit
mailing list