Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Use TAILQ_FOREACH() instead of open-coding it.



details:   https://anonhg.NetBSD.org/src/rev/21ecf25a03d7
branches:  trunk
changeset: 749011:21ecf25a03d7
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Thu Nov 12 23:16:28 2009 +0000

description:
Use TAILQ_FOREACH() instead of open-coding it.

I applied this patch with Coccinelle's semantic patch tool, spatch(1).
I installed Coccinelle from pkgsrc: devel/coccinelle/.  I wrote
tailq.spatch and kdefs.h (see below) and ran this command,

spatch -debug -macro_file_builtins ./kdefs.h -outplace \
    -sp_file sys/kern/tailq.spatch sys/kern/subr_autoconf.c

which wrote the transformed source file to /tmp/subr_autoconf.c.  Then I
used indent(1) to fix the indentation.

::::::::::::::::::::
::: tailq.spatch :::
::::::::::::::::::::

@@
identifier I, N;
expression H;
statement S;
iterator name TAILQ_FOREACH;
@@

- for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N)) S
+ TAILQ_FOREACH(I, H, N) S

:::::::::::::::
::: kdefs.h :::
:::::::::::::::

#define MAXUSERS 64
#define _KERNEL
#define _KERNEL_OPT
#define i386

/*
 * Tail queue definitions.
 */
#define _TAILQ_HEAD(name, type, qual)                                   \
struct name {                                                           \
        qual type *tqh_first;           /* first element */             \
        qual type *qual *tqh_last;      /* addr of last next element */ \
}
#define TAILQ_HEAD(name, type)  _TAILQ_HEAD(name, struct type,)

#define TAILQ_HEAD_INITIALIZER(head)                                    \
        { NULL, &(head).tqh_first }

#define _TAILQ_ENTRY(type, qual)                                        \
struct {                                                                \
        qual type *tqe_next;            /* next element */              \
        qual type *qual *tqe_prev;      /* address of previous next element */\
}
#define TAILQ_ENTRY(type)       _TAILQ_ENTRY(struct type,)

#define PMF_FN_PROTO1   pmf_qual_t
#define PMF_FN_ARGS1    pmf_qual_t qual
#define PMF_FN_CALL1    qual

#define PMF_FN_PROTO    , pmf_qual_t
#define PMF_FN_ARGS     , pmf_qual_t qual
#define PMF_FN_CALL     , qual

#define __KERNEL_RCSID(a, b)

diffstat:

 sys/kern/subr_autoconf.c |  10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diffs (38 lines):

diff -r 09e7c0cf92f6 -r 21ecf25a03d7 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Thu Nov 12 22:46:47 2009 +0000
+++ b/sys/kern/subr_autoconf.c  Thu Nov 12 23:16:28 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.187 2009/11/12 19:10:30 dyoung Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.188 2009/11/12 23:16:28 dyoung Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.187 2009/11/12 19:10:30 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.188 2009/11/12 23:16:28 dyoung Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1629,8 +1629,7 @@
                panic("config_defer: can't defer config of a root device");
 
 #ifdef DIAGNOSTIC
-       for (dc = TAILQ_FIRST(&deferred_config_queue); dc != NULL;
-            dc = TAILQ_NEXT(dc, dc_queue)) {
+       TAILQ_FOREACH(dc, &deferred_config_queue, dc_queue) {
                if (dc->dc_dev == dev)
                        panic("config_defer: deferred twice");
        }
@@ -1664,8 +1663,7 @@
        }
 
 #ifdef DIAGNOSTIC
-       for (dc = TAILQ_FIRST(&interrupt_config_queue); dc != NULL;
-            dc = TAILQ_NEXT(dc, dc_queue)) {
+       TAILQ_FOREACH(dc, &interrupt_config_queue, dc_queue) {
                if (dc->dc_dev == dev)
                        panic("config_interrupts: deferred twice");
        }



Home | Main Index | Thread Index | Old Index