CLEANUP: pattern: make all pattern tables read-only

Interestingly, all arrays used to declare patterns were read-write while
only hard-coded. Let's mark them const so that they move from data to
rodata and don't risk to experience false sharing.
This commit is contained in:
Willy Tarreau 2021-04-10 17:44:27 +02:00
parent 9dee2150f6
commit 9057a0026e
2 changed files with 12 additions and 12 deletions

View File

@ -29,13 +29,13 @@
#include <haproxy/sample-t.h> #include <haproxy/sample-t.h>
/* pattern management function arrays */ /* pattern management function arrays */
extern char *pat_match_names[PAT_MATCH_NUM]; extern const char *const pat_match_names[PAT_MATCH_NUM];
extern int pat_match_types[PAT_MATCH_NUM]; extern int const pat_match_types[PAT_MATCH_NUM];
extern int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **); extern int (*const pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **);
extern int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **); extern int (*const pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **);
extern void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *); extern void (*const pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *);
extern struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int); extern struct pattern *(*const pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int);
/* This is the root of the list of all pattern_ref avalaibles. */ /* This is the root of the list of all pattern_ref avalaibles. */
extern struct list pattern_reference; extern struct list pattern_reference;

View File

@ -28,7 +28,7 @@
#include <haproxy/tools.h> #include <haproxy/tools.h>
char *pat_match_names[PAT_MATCH_NUM] = { const char *const pat_match_names[PAT_MATCH_NUM] = {
[PAT_MATCH_FOUND] = "found", [PAT_MATCH_FOUND] = "found",
[PAT_MATCH_BOOL] = "bool", [PAT_MATCH_BOOL] = "bool",
[PAT_MATCH_INT] = "int", [PAT_MATCH_INT] = "int",
@ -45,7 +45,7 @@ char *pat_match_names[PAT_MATCH_NUM] = {
[PAT_MATCH_REGM] = "regm", [PAT_MATCH_REGM] = "regm",
}; };
int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **) = { int (*const pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **) = {
[PAT_MATCH_FOUND] = pat_parse_nothing, [PAT_MATCH_FOUND] = pat_parse_nothing,
[PAT_MATCH_BOOL] = pat_parse_nothing, [PAT_MATCH_BOOL] = pat_parse_nothing,
[PAT_MATCH_INT] = pat_parse_int, [PAT_MATCH_INT] = pat_parse_int,
@ -62,7 +62,7 @@ int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char *
[PAT_MATCH_REGM] = pat_parse_reg, [PAT_MATCH_REGM] = pat_parse_reg,
}; };
int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **) = { int (*const pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **) = {
[PAT_MATCH_FOUND] = pat_idx_list_val, [PAT_MATCH_FOUND] = pat_idx_list_val,
[PAT_MATCH_BOOL] = pat_idx_list_val, [PAT_MATCH_BOOL] = pat_idx_list_val,
[PAT_MATCH_INT] = pat_idx_list_val, [PAT_MATCH_INT] = pat_idx_list_val,
@ -79,7 +79,7 @@ int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, ch
[PAT_MATCH_REGM] = pat_idx_list_regm, [PAT_MATCH_REGM] = pat_idx_list_regm,
}; };
void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = { void (*const pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = {
[PAT_MATCH_FOUND] = pat_prune_gen, [PAT_MATCH_FOUND] = pat_prune_gen,
[PAT_MATCH_BOOL] = pat_prune_gen, [PAT_MATCH_BOOL] = pat_prune_gen,
[PAT_MATCH_INT] = pat_prune_gen, [PAT_MATCH_INT] = pat_prune_gen,
@ -96,7 +96,7 @@ void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = {
[PAT_MATCH_REGM] = pat_prune_gen, [PAT_MATCH_REGM] = pat_prune_gen,
}; };
struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int) = { struct pattern *(*const pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int) = {
[PAT_MATCH_FOUND] = NULL, [PAT_MATCH_FOUND] = NULL,
[PAT_MATCH_BOOL] = pat_match_nothing, [PAT_MATCH_BOOL] = pat_match_nothing,
[PAT_MATCH_INT] = pat_match_int, [PAT_MATCH_INT] = pat_match_int,
@ -114,7 +114,7 @@ struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern
}; };
/* Just used for checking configuration compatibility */ /* Just used for checking configuration compatibility */
int pat_match_types[PAT_MATCH_NUM] = { int const pat_match_types[PAT_MATCH_NUM] = {
[PAT_MATCH_FOUND] = SMP_T_SINT, [PAT_MATCH_FOUND] = SMP_T_SINT,
[PAT_MATCH_BOOL] = SMP_T_SINT, [PAT_MATCH_BOOL] = SMP_T_SINT,
[PAT_MATCH_INT] = SMP_T_SINT, [PAT_MATCH_INT] = SMP_T_SINT,