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.
diff --git a/include/haproxy/pattern.h b/include/haproxy/pattern.h
index 5b64c0d..aaa8964 100644
--- a/include/haproxy/pattern.h
+++ b/include/haproxy/pattern.h
@@ -29,13 +29,13 @@
#include <haproxy/sample-t.h>
/* pattern management function arrays */
-extern char *pat_match_names[PAT_MATCH_NUM];
-extern int pat_match_types[PAT_MATCH_NUM];
+extern const char *const pat_match_names[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 (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **);
-extern void (*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 int (*const pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **);
+extern int (*const pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **);
+extern void (*const pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *);
+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. */
extern struct list pattern_reference;
diff --git a/src/pattern.c b/src/pattern.c
index 6394470..e6892f6 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -28,7 +28,7 @@
#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_BOOL] = "bool",
[PAT_MATCH_INT] = "int",
@@ -45,7 +45,7 @@
[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_BOOL] = pat_parse_nothing,
[PAT_MATCH_INT] = pat_parse_int,
@@ -62,7 +62,7 @@
[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_BOOL] = pat_idx_list_val,
[PAT_MATCH_INT] = pat_idx_list_val,
@@ -79,7 +79,7 @@
[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_BOOL] = pat_prune_gen,
[PAT_MATCH_INT] = pat_prune_gen,
@@ -96,7 +96,7 @@
[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_BOOL] = pat_match_nothing,
[PAT_MATCH_INT] = pat_match_int,
@@ -114,7 +114,7 @@
};
/* 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_BOOL] = SMP_T_SINT,
[PAT_MATCH_INT] = SMP_T_SINT,