[RFC PATCH 12/20] force consistent number of function arguments

Asbjørn Sloth Tønnesen ast at 2e8.dk
Mon Dec 30 17:56:38 CET 2019


---
 conf/cf-lex.l   | 1 +
 conf/conf.h     | 1 +
 filter/adapt.c  | 5 +++++
 filter/config.Y | 2 ++
 4 files changed, 9 insertions(+)

diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index 9b7df0b2..ab984dca 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -677,6 +677,7 @@ cf_type_symbol(struct symbol *sym, const int class, const u8 net_type)
 
   sym->class = class;
   sym->flags |= SYM_FLAG_IS_TYPED;
+  typed->parent = sym;
 
   cf_assert(typed->scope == new_config->root_scope, "wrong scope for typed symbol");
 
diff --git a/conf/conf.h b/conf/conf.h
index 0104d070..c3031a65 100644
--- a/conf/conf.h
+++ b/conf/conf.h
@@ -112,6 +112,7 @@ extern int (*cf_read_hook)(byte *buf, uint max, int fd);
 struct symbol {
   node n;				/* In list of symbols in config */
   struct symbol *next;
+  struct symbol *parent;		/* for parent of typed symbol */
   struct sym_scope *scope;
   int class;				/* SYM_* */
   u8 net_type;				/* Routing table network type (NET_*), 0 for undefined */
diff --git a/filter/adapt.c b/filter/adapt.c
index cb43177d..13c090da 100644
--- a/filter/adapt.c
+++ b/filter/adapt.c
@@ -33,6 +33,11 @@ filter_tree_has_typed_symbols(const struct f_tree *t)
 void
 filter_validate_function(struct symbol *sym)
 {
+  const struct symbol *parent = sym->parent;
+  if (parent && parent->function->args != sym->function->args)
+    cf_error("Incorrent amount of arguments in definition of %s:%s",
+      sym->name, net_label[sym->net_type]);
+
   if (f_has_typed_symbols(sym->function))
     sym->flags |= SYM_FLAG_DO_ADAPT;
 }
diff --git a/filter/config.Y b/filter/config.Y
index 1caef0fc..caca0d2b 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -615,6 +615,8 @@ function_def:
      $5->args = $4;
      $2->function = $5;
      cf_pop_scope();
+     if ($2->parent && !$2->parent->function)
+       $2->parent->function = $5;
      filter_validate_function($2);
    }
  ;
-- 
2.24.0



More information about the Bird-users mailing list