[sheepdog] [PATCH v2] employ gnu99 style of GCC

Hitoshi Mitake mitake.hitoshi at gmail.com
Mon Apr 29 16:36:21 CEST 2013


This patch lets sheepdog employ gnu99 (C99 + gnu extensions) style of
GCC. The main benefit of gnu99 is allowing interleaved statements and
declarations. sheepdog source tree has many functions with lots of
local variable declarations on their head part. They are harmful from
the perspective of readability. Basically, variable declarations
should be delayed until they are actually required. With gnu99, we can
write interleaved statements and declarations, so this can improve the
readability of sheepdog.

The RB_ROOT constant is not friendly with gnu99, so this patch also
add a minor change to it. In addition, RB_ROOT cannot be used in
statements (not declarations). This patch also prepares a new macro
INIT_RB_ROOT() for such usecases.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 configure.ac         |    2 +-
 include/rbtree.h     |    7 ++++++-
 sheep/object_cache.c |    2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0787b6f..fac698b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -354,7 +354,7 @@ fi
 # final build of *FLAGS
 CFLAGS="$ENV_CFLAGS $OPT_CFLAGS $GDB_FLAGS $OS_CFLAGS \
 	$TRACE_CFLAGS $COVERAGE_CFLAGS $EXTRA_WARNINGS $WERROR_CFLAGS $NSS_CFLAGS \
-	-D_GNU_SOURCE -D_LGPL_SOURCE"
+	-D_GNU_SOURCE -D_LGPL_SOURCE -std=gnu99"
 CPPFLAGS="$ENV_CPPFLAGS $ANSI_CPPFLAGS $OS_CPPFLAGS"
 LDFLAGS="$ENV_LDFLAGS $COVERAGE_LDFLAGS $OS_LDFLAGS $TRACE_LDFLAGS"
 
diff --git a/include/rbtree.h b/include/rbtree.h
index 27c511b..642d151 100644
--- a/include/rbtree.h
+++ b/include/rbtree.h
@@ -30,7 +30,12 @@ static inline void rb_set_color(struct rb_node *rb, int color)
 	rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
 }
 
-#define RB_ROOT ((struct rb_root) { NULL, })
+#define RB_ROOT { .rb_node = NULL }
+static inline void INIT_RB_ROOT(struct rb_root *root)
+{
+	root->rb_node = NULL;
+}
+
 #define rb_entry(ptr, type, member) container_of(ptr, type, member)
 
 #define RB_EMPTY_ROOT(root)     ((root)->rb_node == NULL)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 4eb8e9b..ed6570f 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -591,7 +591,7 @@ not_found:
 	if (create) {
 		cache = xzalloc(sizeof(*cache));
 		cache->vid = vid;
-		cache->lru_tree = RB_ROOT;
+		INIT_RB_ROOT(&cache->lru_tree);
 		create_dir_for(vid);
 		cache->push_efd = eventfd(0, 0);
 
-- 
1.7.10.rc0.41.gfa678




More information about the sheepdog mailing list