configuration: Constify more pointers

This continues the patch series constifying various pointers in the
configuration sub-system.

This is done as a separate commit as it involved a _slightly_ more
invasive change in nxt_conf_get_string().

While it takes a value parameter that is never modified, simply making
it const results in

  CC     build/src/nxt_conf.o
src/nxt_conf.c: In function ‘nxt_conf_get_string’:
src/nxt_conf.c:170:20: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
  170 |         str->start = value->u.str.start;
      |                    ^

due to the assignment operator. Making value const will allow for
numerous other constification and seeing as we are not modifying it,
seems worthwhile.

We can get around the warning by casting ->u.{str,string}.start

Reviewed-by: Zhidao HONG <z.hong@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
This commit is contained in:
Andrew Clayton 2024-04-17 15:50:40 +01:00
parent 33c978cc24
commit 31cec908cd
2 changed files with 28 additions and 24 deletions

View file

@ -130,16 +130,17 @@ static nxt_int_t nxt_conf_copy_array(nxt_mp_t *mp, const nxt_conf_op_t *op,
static nxt_int_t nxt_conf_copy_object(nxt_mp_t *mp, const nxt_conf_op_t *op, static nxt_int_t nxt_conf_copy_object(nxt_mp_t *mp, const nxt_conf_op_t *op,
nxt_conf_value_t *dst, const nxt_conf_value_t *src); nxt_conf_value_t *dst, const nxt_conf_value_t *src);
static size_t nxt_conf_json_string_length(nxt_conf_value_t *value); static size_t nxt_conf_json_string_length(const nxt_conf_value_t *value);
static u_char *nxt_conf_json_print_string(u_char *p, nxt_conf_value_t *value); static u_char *nxt_conf_json_print_string(u_char *p,
static size_t nxt_conf_json_array_length(nxt_conf_value_t *value, const nxt_conf_value_t *value);
static size_t nxt_conf_json_array_length(const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty); nxt_conf_json_pretty_t *pretty);
static u_char *nxt_conf_json_print_array(u_char *p, nxt_conf_value_t *value, static u_char *nxt_conf_json_print_array(u_char *p,
nxt_conf_json_pretty_t *pretty); const nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty);
static size_t nxt_conf_json_object_length(nxt_conf_value_t *value, static size_t nxt_conf_json_object_length(const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty);
static u_char *nxt_conf_json_print_object(u_char *p, nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty); nxt_conf_json_pretty_t *pretty);
static u_char *nxt_conf_json_print_object(u_char *p,
const nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty);
static size_t nxt_conf_json_escape_length(u_char *p, size_t size); static size_t nxt_conf_json_escape_length(u_char *p, size_t size);
static u_char *nxt_conf_json_escape(u_char *dst, u_char *src, size_t size); static u_char *nxt_conf_json_escape(u_char *dst, u_char *src, size_t size);
@ -162,21 +163,22 @@ nxt_conf_json_indentation(u_char *p, uint32_t level)
void void
nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str) nxt_conf_get_string(const nxt_conf_value_t *value, nxt_str_t *str)
{ {
if (value->type == NXT_CONF_VALUE_SHORT_STRING) { if (value->type == NXT_CONF_VALUE_SHORT_STRING) {
str->length = value->u.str.length; str->length = value->u.str.length;
str->start = value->u.str.start; str->start = (u_char *) value->u.str.start;
} else { } else {
str->length = value->u.string.length; str->length = value->u.string.length;
str->start = value->u.string.start; str->start = (u_char *) value->u.string.start;
} }
} }
nxt_str_t * nxt_str_t *
nxt_conf_get_string_dup(nxt_conf_value_t *value, nxt_mp_t *mp, nxt_str_t *str) nxt_conf_get_string_dup(const nxt_conf_value_t *value, nxt_mp_t *mp,
nxt_str_t *str)
{ {
nxt_str_t s; nxt_str_t s;
@ -2233,7 +2235,8 @@ nxt_conf_json_parse_error(nxt_conf_json_error_t *error, u_char *pos,
size_t size_t
nxt_conf_json_length(nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty) nxt_conf_json_length(const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty)
{ {
switch (value->type) { switch (value->type) {
@ -2265,7 +2268,7 @@ nxt_conf_json_length(nxt_conf_value_t *value, nxt_conf_json_pretty_t *pretty)
u_char * u_char *
nxt_conf_json_print(u_char *p, nxt_conf_value_t *value, nxt_conf_json_print(u_char *p, const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty) nxt_conf_json_pretty_t *pretty)
{ {
switch (value->type) { switch (value->type) {
@ -2299,7 +2302,7 @@ nxt_conf_json_print(u_char *p, nxt_conf_value_t *value,
static size_t static size_t
nxt_conf_json_string_length(nxt_conf_value_t *value) nxt_conf_json_string_length(const nxt_conf_value_t *value)
{ {
nxt_str_t str; nxt_str_t str;
@ -2310,7 +2313,7 @@ nxt_conf_json_string_length(nxt_conf_value_t *value)
static u_char * static u_char *
nxt_conf_json_print_string(u_char *p, nxt_conf_value_t *value) nxt_conf_json_print_string(u_char *p, const nxt_conf_value_t *value)
{ {
nxt_str_t str; nxt_str_t str;
@ -2327,7 +2330,7 @@ nxt_conf_json_print_string(u_char *p, nxt_conf_value_t *value)
static size_t static size_t
nxt_conf_json_array_length(nxt_conf_value_t *value, nxt_conf_json_array_length(const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty) nxt_conf_json_pretty_t *pretty)
{ {
size_t len; size_t len;
@ -2369,7 +2372,7 @@ nxt_conf_json_array_length(nxt_conf_value_t *value,
static u_char * static u_char *
nxt_conf_json_print_array(u_char *p, nxt_conf_value_t *value, nxt_conf_json_print_array(u_char *p, const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty) nxt_conf_json_pretty_t *pretty)
{ {
nxt_uint_t n; nxt_uint_t n;
@ -2421,7 +2424,7 @@ nxt_conf_json_print_array(u_char *p, nxt_conf_value_t *value,
static size_t static size_t
nxt_conf_json_object_length(nxt_conf_value_t *value, nxt_conf_json_object_length(const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty) nxt_conf_json_pretty_t *pretty)
{ {
size_t len; size_t len;
@ -2465,7 +2468,7 @@ nxt_conf_json_object_length(nxt_conf_value_t *value,
static u_char * static u_char *
nxt_conf_json_print_object(u_char *p, nxt_conf_value_t *value, nxt_conf_json_print_object(u_char *p, const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty) nxt_conf_json_pretty_t *pretty)
{ {
nxt_uint_t n; nxt_uint_t n;

View file

@ -108,17 +108,18 @@ nxt_conf_value_t *nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end,
#define nxt_conf_json_parse_str(mp, str) \ #define nxt_conf_json_parse_str(mp, str) \
nxt_conf_json_parse(mp, (str)->start, (str)->start + (str)->length, NULL) nxt_conf_json_parse(mp, (str)->start, (str)->start + (str)->length, NULL)
size_t nxt_conf_json_length(nxt_conf_value_t *value, size_t nxt_conf_json_length(const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty); nxt_conf_json_pretty_t *pretty);
u_char *nxt_conf_json_print(u_char *p, nxt_conf_value_t *value, u_char *nxt_conf_json_print(u_char *p, const nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty); nxt_conf_json_pretty_t *pretty);
void nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line, void nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line,
nxt_uint_t *column); nxt_uint_t *column);
nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt); nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt);
NXT_EXPORT void nxt_conf_get_string(nxt_conf_value_t *value, nxt_str_t *str); NXT_EXPORT void nxt_conf_get_string(const nxt_conf_value_t *value,
NXT_EXPORT nxt_str_t *nxt_conf_get_string_dup(nxt_conf_value_t *value, nxt_str_t *str);
NXT_EXPORT nxt_str_t *nxt_conf_get_string_dup(const nxt_conf_value_t *value,
nxt_mp_t *mp, nxt_str_t *str); nxt_mp_t *mp, nxt_str_t *str);
NXT_EXPORT void nxt_conf_set_string(nxt_conf_value_t *value, NXT_EXPORT void nxt_conf_set_string(nxt_conf_value_t *value,
const nxt_str_t *str); const nxt_str_t *str);