From 3b63ca20f4c37e6ecf527c5fc400e4dcebe6df4c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 8 May 2021 14:10:42 +0200 Subject: [PATCH] REORG: stick-table: uninline stktable_alloc_data_type() This function has no business being inlined in stick_table.h since it's only used at boot time by the config parser. In addition it causes an undesired dependency on tools.h because it uses parse_time_err(). Let's move it to stick_table.c. --- include/haproxy/stick_table.h | 40 +---------------------------------- src/stick_table.c | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index 5a3b400ba..d8963b1d3 100644 --- a/include/haproxy/stick_table.h +++ b/include/haproxy/stick_table.h @@ -87,45 +87,7 @@ static inline int stktable_type_size(int type) return 0; } -/* reserve some space for data type , and associate argument at if - * not NULL. Returns PE_NONE (0) if OK or an error code among : - * - PE_ENUM_OOR if does not exist - * - PE_EXIST if is already registered - * - PE_ARG_NOT_USE if was provided but not expected - * - PE_ARG_MISSING if was expected but not provided - */ -static inline int stktable_alloc_data_type(struct stktable *t, int type, const char *sa) -{ - if (type >= STKTABLE_DATA_TYPES) - return PE_ENUM_OOR; - - if (t->data_ofs[type]) - /* already allocated */ - return PE_EXIST; - - switch (stktable_data_types[type].arg_type) { - case ARG_T_NONE: - if (sa) - return PE_ARG_NOT_USED; - break; - case ARG_T_INT: - if (!sa) - return PE_ARG_MISSING; - t->data_arg[type].i = atoi(sa); - break; - case ARG_T_DELAY: - if (!sa) - return PE_ARG_MISSING; - sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS); - if (sa) - return PE_ARG_INVC; /* invalid char */ - break; - } - - t->data_size += stktable_type_size(stktable_data_types[type].std_type); - t->data_ofs[type] = -t->data_size; - return PE_NONE; -} +int stktable_alloc_data_type(struct stktable *t, int type, const char *sa); /* return pointer for data type in sticky session of table , all * of which must exist (otherwise use stktable_data_ptr() if unsure). diff --git a/src/stick_table.c b/src/stick_table.c index bb5c0ba6f..d16e1d01b 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -707,6 +707,46 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke return 1; } +/* reserve some space for data type , and associate argument at if + * not NULL. Returns PE_NONE (0) if OK or an error code among : + * - PE_ENUM_OOR if does not exist + * - PE_EXIST if is already registered + * - PE_ARG_NOT_USE if was provided but not expected + * - PE_ARG_MISSING if was expected but not provided + */ +int stktable_alloc_data_type(struct stktable *t, int type, const char *sa) +{ + if (type >= STKTABLE_DATA_TYPES) + return PE_ENUM_OOR; + + if (t->data_ofs[type]) + /* already allocated */ + return PE_EXIST; + + switch (stktable_data_types[type].arg_type) { + case ARG_T_NONE: + if (sa) + return PE_ARG_NOT_USED; + break; + case ARG_T_INT: + if (!sa) + return PE_ARG_MISSING; + t->data_arg[type].i = atoi(sa); + break; + case ARG_T_DELAY: + if (!sa) + return PE_ARG_MISSING; + sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS); + if (sa) + return PE_ARG_INVC; /* invalid char */ + break; + } + + t->data_size += stktable_type_size(stktable_data_types[type].std_type); + t->data_ofs[type] = -t->data_size; + return PE_NONE; +} + /* * Parse a line with as number in configuration file to configure * the stick-table with as address and as ID.