[PATCH 1/3] maint: eliminate unnecessary global, cfg_file

Jim Meyering jim at meyering.net
Wed Apr 6 19:21:15 UTC 2011


There were several global variables that did not need to be
project global.  For most, I've just reduced their scope to file-wide.
One didn't need to be global at all, so I moved it into the sole
function from which it was used.

>From c68d76bada0e3cdb5af1ff5da8b359861e679429 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 6 Apr 2011 13:38:34 +0200
Subject: [PATCH 1/3] maint: eliminate unnecessary global, cfg_file

* rest.c (cfg_file): Move globally-scoped variable into...
(main): ...here.
---
 rest.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/rest.c b/rest.c
index 860ab1c..aa9be64 100644
--- a/rest.c
+++ b/rest.c
@@ -97,7 +97,6 @@ typedef struct {
 } rule;

 static unsigned short		 my_port	= MY_PORT;
-char				*cfg_file	= NULL;

 static const char *const (reserved_name[]) = {"_default", "_new", "_policy", "_query", NULL};
 static const char *const (reserved_attr[]) = {"_attrs", "_bucket", "_date", "_etag", "_key", "_loc", "_size", NULL};
@@ -2288,6 +2287,7 @@ main (int argc, char **argv)
 	char			*stctx = NULL;
 	char			*port_tmp;
 	bool			 autostart = false;
+	char *cfg_file = NULL;

 	set_program_name (argv[0]);
 	setlocale (LC_ALL, "");
--
1.7.5.rc0.353.g0244ef


>From 95ef9bea37aa1866c0bad6de1252e1ebad53a810 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 6 Apr 2011 13:40:34 +0200
Subject: [PATCH 2/3] maint: reduce scope from global to file: client_lock

* meta.cpp (client_lock): Declare static.
---
 meta.cpp |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/meta.cpp b/meta.cpp
index aa533c2..e55e5d1 100644
--- a/meta.cpp
+++ b/meta.cpp
@@ -46,7 +46,8 @@ using namespace mongo;

 #define SHOW_CONTENTION

-pthread_mutex_t		client_lock	= PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t client_lock = PTHREAD_MUTEX_INITIALIZER;
+
 #if defined(SHOW_CONTENTION)
 #define CLIENT_LOCK do {					\
 	if (pthread_mutex_trylock(&client_lock) != 0) {		\
--
1.7.5.rc0.353.g0244ef


>From 7a9d9a16c2b862fb780672c979b71c9a9c36fd9f Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 6 Apr 2011 13:41:56 +0200
Subject: [PATCH 3/3] maint: limit scope of backend.c globals

* backend.c (NFSGID): Declare as an enum, rather than via #define.
An enum is easier to reference via debugger.
(hstor, s3_success_pat, s3_failure_pat, regex_ok): Declare static.
---
 backend.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/backend.c b/backend.c
index 7ca4db0..10f6bf9 100644
--- a/backend.c
+++ b/backend.c
@@ -46,9 +46,10 @@

 #define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))

-#define NFSGID 36
+/* FIXME: describe/justify */
+enum { NFSGID = 36 };

-struct hstor_client	*hstor;
+static struct hstor_client *hstor;

 /***** Generic module stuff, not specific to one back end *****/

@@ -65,9 +66,9 @@ struct hstor_client	*hstor;
 #define S3_IMAGE_PATTERN "^IMAGE[[:blank:]]+([^[:space:]]+)"
 #define S3_ERROR_PATTERN "^ERROR[[:blank:]]+([^[:space:]]+)"

-regex_t s3_success_pat;
-regex_t s3_failure_pat;
-int	regex_ok = FALSE;
+static regex_t s3_success_pat;
+static regex_t s3_failure_pat;
+static int regex_ok = FALSE;

 void
 backend_init (void)
--
1.7.5.rc0.353.g0244ef


More information about the iwhd-devel mailing list