Module Name:    src
Committed By:   uebayasi
Date:           Fri Oct 10 06:59:38 UTC 2014

Modified Files:
        src/usr.bin/config: sem.c sem.h

Log Message:
Implicitly define empty "attribute" for "device attachment".  Much less
troublesome than "device" and "interface attribute".


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/config/sem.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/config/sem.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/config/sem.c
diff -u src/usr.bin/config/sem.c:1.49 src/usr.bin/config/sem.c:1.50
--- src/usr.bin/config/sem.c:1.49	Fri Oct 10 06:13:30 2014
+++ src/usr.bin/config/sem.c	Fri Oct 10 06:59:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sem.c,v 1.49 2014/10/10 06:13:30 uebayasi Exp $	*/
+/*	$NetBSD: sem.c,v 1.50 2014/10/10 06:59:38 uebayasi Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -236,23 +236,37 @@ defattr(const char *name, struct loclist
 		}
 	}
 
-	a = ecalloc(1, sizeof *a);
-	if (ht_insert(attrtab, name, a)) {
-		free(a);
+	a = mkattr(name);
+	if (a == NULL) {
 		cfgerror("attribute `%s' already defined", name);
 		loclist_destroy(locs);
 		return (1);
 	}
 
-	a->a_name = name;
 	a->a_deps = deps;
-	a->a_expanding = 0;
-	TAILQ_INIT(&a->a_files);
 	expandattr(a, NULL);
+	CFGDBG(3, "attr `%s' defined", a->a_name);
 
 	return (0);
 }
 
+struct attr *
+mkattr(const char *name)
+{
+	struct attr *a;
+
+	a = ecalloc(1, sizeof *a);
+	if (ht_insert(attrtab, name, a)) {
+		free(a);
+		return NULL;
+	}
+	a->a_name = name;
+	TAILQ_INIT(&a->a_files);
+	CFGDBG(3, "attr `%s' allocated", name);
+
+	return a;
+}
+
 /* "interface attribute" initialization */
 int
 defiattr(const char *name, struct loclist *locs, struct attrlist *deps,
@@ -543,6 +557,12 @@ defdevattach(struct deva *deva, struct d
 	deva->d_attrs = attrs;
 	deva->d_atlist = atlist;
 	deva->d_devbase = dev;
+	CFGDBG(3, "deva `%s' defined", deva->d_name);
+
+	/*
+	 * Implicit attribute definition.
+	 */
+	refattr(deva->d_name);
 
 	/*
 	 * Turn the `at' list into interface attributes (map each
@@ -644,6 +664,17 @@ getattr(const char *name)
 }
 
 /*
+ * Implicit attribute definition.
+ */
+void
+refattr(const char *name)
+{
+
+	if ((ht_lookup(attrtab, name)) == NULL)
+		(void)mkattr(name);
+}
+
+/*
  * Recursively expand an attribute and its dependencies, checking for
  * cycles, and invoking a callback for each attribute found.
  */

Index: src/usr.bin/config/sem.h
diff -u src/usr.bin/config/sem.h:1.11 src/usr.bin/config/sem.h:1.12
--- src/usr.bin/config/sem.h:1.11	Fri Oct 10 06:13:30 2014
+++ src/usr.bin/config/sem.h	Fri Oct 10 06:59:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sem.h,v 1.11 2014/10/10 06:13:30 uebayasi Exp $	*/
+/*	$NetBSD: sem.h,v 1.12 2014/10/10 06:59:38 uebayasi Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -55,7 +55,9 @@ void		defdevattach(struct deva *, struct
 			     struct attrlist *);
 struct devbase *getdevbase(const char *);
 struct deva    *getdevattach(const char *);
+struct attr	*mkattr(const char *);
 struct attr    *getattr(const char *);
+void		refattr(const char *);
 void		expandattr(struct attr *, void (*)(struct attr *));
 void		selectattr(struct attr *);
 void		setmajor(struct devbase *, int);

Reply via email to