Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config Create a new type struct attrlist to manage l...



details:   https://anonhg.NetBSD.org/src/rev/6acacb7982a6
branches:  trunk
changeset: 777972:6acacb7982a6
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Mar 11 07:32:41 2012 +0000

description:
Create a new type struct attrlist to manage lists of attributes,
instead of using struct nvlist.

(struct nvlist holds lists (or trees!) of semi-arbitrary stuff with no
structure and almost no type safety; it should go away.)

diffstat:

 usr.bin/config/defs.h     |  20 +++++++++--
 usr.bin/config/gram.y     |  50 ++++++++++++++++++++++++++++--
 usr.bin/config/lint.c     |   7 ++-
 usr.bin/config/main.c     |   9 +++--
 usr.bin/config/mkioconf.c |   8 ++--
 usr.bin/config/sem.c      |  77 ++++++++++++++++++++++++----------------------
 usr.bin/config/sem.h      |  10 +++---
 usr.bin/config/util.c     |  48 ++++++++++++++++++++++++++++-
 8 files changed, 167 insertions(+), 62 deletions(-)

diffs (truncated from 611 to 300 lines):

diff -r 7775d72a510a -r 6acacb7982a6 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Sun Mar 11 07:27:02 2012 +0000
+++ b/usr.bin/config/defs.h     Sun Mar 11 07:32:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.37 2012/03/11 05:31:37 dholland Exp $       */
+/*     $NetBSD: defs.h,v 1.38 2012/03/11 07:32:41 dholland Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -161,11 +161,19 @@
        int     a_loclen;               /* length of above list */
        struct  nvlist *a_devs;         /* children */
        struct  nvlist *a_refs;         /* parents */
-       struct  nvlist *a_deps;         /* we depend on these other attrs */
+       struct  attrlist *a_deps;       /* we depend on these other attrs */
        int     a_expanding;            /* to detect cycles in attr graph */
 };
 
 /*
+ * List of attributes.
+ */
+struct attrlist {
+       struct attrlist *al_next;
+       struct attr *al_this;
+};
+
+/*
  * Parent specification.  Multiple device instances may share a
  * given parent spec.  Parent specs are emitted only if there are
  * device instances which actually reference it.
@@ -209,7 +217,7 @@
        int     d_isdef;                /* set once properly defined */
        int     d_ispseudo;             /* is a pseudo-device */
        devmajor_t d_major;             /* used for "root on sd0", e.g. */
-       struct  nvlist *d_attrs;        /* attributes, if any */
+       struct  attrlist *d_attrs;      /* attributes, if any */
        int     d_umax;                 /* highest unit number + 1 */
        struct  devi *d_ihead;          /* first instance, if any */
        struct  devi **d_ipp;           /* used for tacking on more instances */
@@ -225,7 +233,7 @@
        int     d_isdef;                /* set once properly defined */
        struct  devbase *d_devbase;     /* the base device */
        struct  nvlist *d_atlist;       /* e.g., "at tg" (attr list) */
-       struct  nvlist *d_attrs;        /* attributes, if any */
+       struct  attrlist *d_attrs;      /* attributes, if any */
        struct  devi *d_ihead;          /* first instance, if any */
        struct  devi **d_ipp;           /* used for tacking on more instances */
 };
@@ -572,6 +580,10 @@
 void   nvfreel(struct nvlist *);
 struct nvlist *nvcat(struct nvlist *, struct nvlist *);
 void   autogen_comment(FILE *, const char *);
+struct attrlist *attrlist_create(void);
+struct attrlist *attrlist_cons(struct attrlist *, struct attr *);
+void attrlist_destroy(struct attrlist *);
+void attrlist_destroyall(struct attrlist *);
 
 /* liby */
 void   yyerror(const char *);
diff -r 7775d72a510a -r 6acacb7982a6 usr.bin/config/gram.y
--- a/usr.bin/config/gram.y     Sun Mar 11 07:27:02 2012 +0000
+++ b/usr.bin/config/gram.y     Sun Mar 11 07:32:41 2012 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.31 2012/03/11 07:27:02 dholland Exp $       */
+/*     $NetBSD: gram.y,v 1.32 2012/03/11 07:32:41 dholland Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -70,6 +70,7 @@
  * Allocation wrapper type codes
  */
 #define WRAP_CODE_nvlist       1
+#define WRAP_CODE_attrlist     2
 
 /*
  * The allocation wrappers themselves
@@ -77,11 +78,13 @@
 #define DECL_ALLOCWRAP(t)      static struct t *wrap_mk_##t(struct t *arg)
 
 DECL_ALLOCWRAP(nvlist);
+DECL_ALLOCWRAP(attrlist);
 
 /*
  * Macros for allocating new objects
  */
 
+/* old-style for struct nvlist */
 #define        new0(n,s,p,i,x) wrap_mk_nvlist(newnv(n, s, p, i, x))
 #define        new_n(n)        new0(n, NULL, NULL, 0, NULL)
 #define        new_nx(n, x)    new0(n, NULL, NULL, 0, x)
@@ -101,6 +104,17 @@
 #define        fx_and(e1, e2)  new0(NULL, NULL, e1, FX_AND, e2)
 #define        fx_or(e1, e2)   new0(NULL, NULL, e1, FX_OR, e2)
 
+/* new style, type-polymorphic */
+#define MK0(t)         wrap_mk_##t(mk_##t())
+#define MK1(t, a0)     wrap_mk_##t(mk_##t(a0))
+#define MK2(t, a0, a1) wrap_mk_##t(mk_##t(a0, a1))
+
+/*
+ * Data constructors
+ */
+
+static struct attrlist *mk_attrlist(struct attrlist *, struct attr *);
+
 /*
  * Other private functions
  */
@@ -120,6 +134,7 @@
        struct  devbase *devb;
        struct  deva *deva;
        struct  nvlist *list;
+       struct attrlist *attrlist;
        const char *str;
        struct  numconst num;
        int64_t val;
@@ -160,7 +175,7 @@
 %type  <list>  loclist locdef
 %type  <str>   locdefault
 %type  <list>  values locdefaults
-%type  <list>  attrs_opt attrs
+%type  <attrlist>      attrs_opt attrs
 %type  <list>  locators locator
 %type  <list>  dev_spec
 %type  <str>   device_instance
@@ -472,8 +487,8 @@
 
 /* one or more attributes */
 attrs:
-         attr                          { $$ = new_p($1); }
-       | attrs ',' attr                { $$ = new_px($3, $1); }
+         attr                          { $$ = MK2(attrlist, NULL, $1); }
+       | attrs ',' attr                { $$ = MK2(attrlist, $1, $3); }
 ;
 
 /* one attribute */
@@ -935,11 +950,25 @@
                    case WRAP_CODE_nvlist:
                        nvfree(wrapstack[i].ptr);
                        break;
+                   case WRAP_CODE_attrlist:
+                       {
+                               struct attrlist *al = wrapstack[i].ptr;
+
+                               /*
+                                * Contents got wrapped separately;
+                                * just blank it out to destroy.
+                                */
+                               al->al_next = NULL;
+                               al->al_this = NULL;
+                               attrlist_destroy(al);
+                       }
+                       break;
                    default:
                        panic("invalid code %u on allocation wrapper stack",
                              wrapstack[i].typecode);
                }
        }
+
        wrap_depth = 0;
 }
 
@@ -959,6 +988,19 @@
        }
 
 DEF_ALLOCWRAP(nvlist);
+DEF_ALLOCWRAP(attrlist);
+
+/************************************************************/
+
+/*
+ * Data constructors
+ */
+
+static struct attrlist *
+mk_attrlist(struct attrlist *next, struct attr *a)
+{
+       return attrlist_cons(next, a);
+}
 
 /************************************************************/
 
diff -r 7775d72a510a -r 6acacb7982a6 usr.bin/config/lint.c
--- a/usr.bin/config/lint.c     Sun Mar 11 07:27:02 2012 +0000
+++ b/usr.bin/config/lint.c     Sun Mar 11 07:32:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lint.c,v 1.8 2009/08/30 21:07:41 cube Exp $    */
+/*     $NetBSD: lint.c,v 1.9 2012/03/11 07:32:41 dholland Exp $        */
 
 /*
  *  Copyright (c) 2007 The NetBSD Foundation.
@@ -102,6 +102,7 @@
 do_emit_instances(struct devbase *d, struct attr *at)
 {
        struct nvlist *nv, *nv1;
+       struct attrlist *al;
        struct attr *a;
        struct deva *da;
 
@@ -142,8 +143,8 @@
         * Children attachments are found the same way as in the orphan
         * detection code in main.c.
         */
-       for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) {
-               a = nv->nv_ptr;
+       for (al = d->d_attrs; al != NULL; al = al->al_next) {
+               a = al->al_this;
                for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
                        do_emit_instances(nv1->nv_ptr, a);
        }
diff -r 7775d72a510a -r 6acacb7982a6 usr.bin/config/main.c
--- a/usr.bin/config/main.c     Sun Mar 11 07:27:02 2012 +0000
+++ b/usr.bin/config/main.c     Sun Mar 11 07:32:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.43 2011/07/09 08:01:58 matt Exp $   */
+/*     $NetBSD: main.c,v 1.44 2012/03/11 07:32:41 dholland Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -1589,7 +1589,8 @@
 do_kill_orphans(struct devbase *d, struct attr *at, struct devbase *parent,
     int state)
 {
-       struct nvlist *nv, *nv1;
+       struct nvlist *nv1;
+       struct attrlist *al;
        struct attr *a;
        struct devi *i, *j = NULL;
        struct pspec *p;
@@ -1677,8 +1678,8 @@
                }
        }
 
-       for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) {
-               a = nv->nv_ptr;
+       for (al = d->d_attrs; al != NULL; al = al->al_next) {
+               a = al->al_this;
                for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
                        do_kill_orphans(nv1->nv_ptr, a, d, active);
        }
diff -r 7775d72a510a -r 6acacb7982a6 usr.bin/config/mkioconf.c
--- a/usr.bin/config/mkioconf.c Sun Mar 11 07:27:02 2012 +0000
+++ b/usr.bin/config/mkioconf.c Sun Mar 11 07:32:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkioconf.c,v 1.19 2011/03/03 14:53:01 nakayama Exp $   */
+/*     $NetBSD: mkioconf.c,v 1.20 2012/03/11 07:32:41 dholland Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -200,7 +200,7 @@
 emitcfdrivers(FILE *fp)
 {
        struct devbase *d;
-       struct nvlist *nv;
+       struct attrlist *al;
        struct attr *a;
        int has_iattrs;
 
@@ -212,8 +212,8 @@
                if (!devbase_has_instances(d, WILD))
                        continue;
                has_iattrs = 0;
-               for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) {
-                       a = nv->nv_ptr;
+               for (al = d->d_attrs; al != NULL; al = al->al_next) {
+                       a = al->al_this;
                        if (a->a_iattr == 0)
                                continue;
                        if (has_iattrs == 0)
diff -r 7775d72a510a -r 6acacb7982a6 usr.bin/config/sem.c
--- a/usr.bin/config/sem.c      Sun Mar 11 07:27:02 2012 +0000
+++ b/usr.bin/config/sem.c      Sun Mar 11 07:32:41 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.c,v 1.38 2010/05/02 15:35:00 pooka Exp $   */
+/*     $NetBSD: sem.c,v 1.39 2012/03/11 07:32:41 dholland Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -70,7 +70,7 @@
 static struct devbase errdev;
 static struct deva errdeva;
 
-static int has_errobj(struct nvlist *, void *);
+static int has_errobj(struct attrlist *, struct attr *);
 static struct nvlist *addtoattr(struct nvlist *, struct devbase *);
 static int resolve(struct nvlist **, const char *, const char *,
                   struct nvlist *, int);
@@ -194,10 +194,11 @@
  * all locator lists include a dummy head node, which we discard here.
  */
 int
-defattr(const char *name, struct nvlist *locs, struct nvlist *deps,
+defattr(const char *name, struct nvlist *locs, struct attrlist *deps,
     int devclass)
 {
        struct attr *a, *dep;
+       struct attrlist *al;
        struct nvlist *nv;
        int len;



Home | Main Index | Thread Index | Old Index