]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: pattern: make all pattern tables read-only
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Apr 2021 15:44:27 +0000 (17:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Apr 2021 15:49:41 +0000 (17:49 +0200)
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.

include/haproxy/pattern.h
src/pattern.c

index 5b64c0d29460a81d68b3cbd1278e364f7de3ca0b..aaa8964ff57588f027b7a3997330d6ccf98f6d52 100644 (file)
 #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;
index 6394470a3674266371d0bba9305a7d5c1dd7b2ef..e6892f62a108d55457f573cf5b2a1940958a23cf 100644 (file)
@@ -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 @@ char *pat_match_names[PAT_MATCH_NUM] = {
        [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 @@ int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char *
        [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 @@ int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, ch
        [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 @@ void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = {
        [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 @@ struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern
 };
 
 /* 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,