From e9abfb49d66bc2c11f560bf61fd313d6bf04b261 Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Thu, 17 May 2012 21:09:13 +0400
Subject: [PATCH] Rename: extern struct space *space (global) -> spaces

Rename a global variable, which had too common name,
to avoid easy to miss bugs.
---
 mod/box/box.m       |  4 ++--
 mod/box/box_lua.m   |  6 +++---
 mod/box/memcached.m |  4 ++--
 mod/box/request.m   |  2 +-
 mod/box/space.h     |  6 +++---
 mod/box/space.m     | 51 ++++++++++++++++++++++-----------------------
 6 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/mod/box/box.m b/mod/box/box.m
index 3080f05adf..2a102fe571 100644
--- a/mod/box/box.m
+++ b/mod/box/box.m
@@ -548,10 +548,10 @@ mod_snapshot(struct log_io_iter *i)
 	struct tuple *tuple;
 
 	for (uint32_t n = 0; n < BOX_SPACE_MAX; ++n) {
-		if (!space[n].enabled)
+		if (!spaces[n].enabled)
 			continue;
 
-		Index *pk = space[n].index[0];
+		Index *pk = spaces[n].index[0];
 
 		struct iterator *it = pk->position;
 		[pk initIterator: it :ITER_FORWARD];
diff --git a/mod/box/box_lua.m b/mod/box/box_lua.m
index b85b4584e1..9823cb4c7e 100644
--- a/mod/box/box_lua.m
+++ b/mod/box/box_lua.m
@@ -328,12 +328,12 @@ lbox_index_new(struct lua_State *L)
 	int n = luaL_checkint(L, 1); /* get space id */
 	int idx = luaL_checkint(L, 2); /* get index id in */
 	/* locate the appropriate index */
-	if (n >= BOX_SPACE_MAX || !space[n].enabled ||
-	    idx >= BOX_INDEX_MAX || space[n].index[idx] == nil)
+	if (n >= BOX_SPACE_MAX || !spaces[n].enabled ||
+	    idx >= BOX_INDEX_MAX || spaces[n].index[idx] == nil)
 		tnt_raise(LoggedError, :ER_NO_SUCH_INDEX, idx, n);
 	/* create a userdata object */
 	void **ptr = lua_newuserdata(L, sizeof(void *));
-	*ptr = space[n].index[idx];
+	*ptr = spaces[n].index[idx];
 	/* set userdata object metatable to indexlib */
 	luaL_getmetatable(L, indexlib_name);
 	lua_setmetatable(L, -2);
diff --git a/mod/box/memcached.m b/mod/box/memcached.m
index c007d43cce..e9eb2d2526 100644
--- a/mod/box/memcached.m
+++ b/mod/box/memcached.m
@@ -413,7 +413,7 @@ memcached_init(void)
 
 	stat_base = stat_register(memcached_stat_strs, memcached_stat_MAX);
 
-	memcached_index = space[cfg.memcached_space].index[0];
+	memcached_index = spaces[cfg.memcached_space].index[0];
 }
 
 void
@@ -430,7 +430,7 @@ memcached_space_init()
                 return;
 
 	/* Configure memcached space. */
-	struct space *memc_s = &space[cfg.memcached_space];
+	struct space *memc_s = &spaces[cfg.memcached_space];
 	memc_s->enabled = true;
 	memc_s->arity = 4;
 
diff --git a/mod/box/request.m b/mod/box/request.m
index e00a3335fd..4c22233b29 100644
--- a/mod/box/request.m
+++ b/mod/box/request.m
@@ -946,7 +946,7 @@ request_set_space(struct txn *txn, struct tbuf *data)
 	if (space_no < 0 || space_no >= BOX_SPACE_MAX)
 		tnt_raise(ClientError, :ER_NO_SUCH_SPACE, space_no);
 
-	txn->space = &space[space_no];
+	txn->space = &spaces[space_no];
 
 	if (!txn->space->enabled)
 		tnt_raise(ClientError, :ER_SPACE_DISABLED, space_no);
diff --git a/mod/box/space.h b/mod/box/space.h
index 848c97ef4e..bdb2aee96b 100644
--- a/mod/box/space.h
+++ b/mod/box/space.h
@@ -79,14 +79,14 @@ struct space {
 	bool enabled;
 };
 
-extern struct space *space;
+extern struct space *spaces;
 
 /** Get space ordinal number. */
 static inline int
 space_n(struct space *sp)
 {
-	assert(sp >= space && sp < (space + BOX_SPACE_MAX));
-	return sp - space;
+	assert(sp >= spaces && sp < (spaces + BOX_SPACE_MAX));
+	return sp - spaces;
 }
 
 void space_validate(struct space *sp, struct tuple *old_tuple,
diff --git a/mod/box/space.m b/mod/box/space.m
index eb5ad4948f..37d865dfba 100644
--- a/mod/box/space.m
+++ b/mod/box/space.m
@@ -35,7 +35,7 @@
 #include "tuple.h"
 #include <pickle.h>
 
-struct space *space = NULL;
+struct space *spaces = NULL;
 
 bool secondary_indexes_enabled = false;
 /** Free a key definition. */
@@ -117,18 +117,18 @@ space_free(void)
 {
 	int i;
 	for (i = 0 ; i < BOX_SPACE_MAX ; i++) {
-		if (!space[i].enabled)
+		if (!spaces[i].enabled)
 			continue;
 
 		int j;
-		for (j = 0 ; j < space[i].key_count; j++) {
-			Index *index = space[i].index[j];
+		for (j = 0 ; j < spaces[i].key_count; j++) {
+			Index *index = spaces[i].index[j];
 			[index free];
-			key_free(&space[i].key_defs[j]);
+			key_free(&spaces[i].key_defs[j]);
 		}
 
-		free(space[i].key_defs);
-		free(space[i].field_types);
+		free(spaces[i].key_defs);
+		free(spaces[i].field_types);
 	}
 }
 
@@ -249,38 +249,38 @@ space_config()
 
 		assert(cfg.memcached_port == 0 || i != cfg.memcached_space);
 
-		space[i].enabled = true;
-		space[i].arity = cfg_space->cardinality;
+		spaces[i].enabled = true;
+		spaces[i].arity = cfg_space->cardinality;
 
 		/*
 		 * Collect key/field info. We need aggregate
 		 * information on all keys before we can create
 		 * indexes.
 		 */
-		space[i].key_count = 0;
+		spaces[i].key_count = 0;
 		for (int j = 0; cfg_space->index[j] != NULL; ++j) {
-			++space[i].key_count;
+			++spaces[i].key_count;
 		}
 
-		space[i].key_defs = malloc(space[i].key_count *
+		spaces[i].key_defs = malloc(spaces[i].key_count *
 					    sizeof(struct key_def));
-		if (space[i].key_defs == NULL) {
+		if (spaces[i].key_defs == NULL) {
 			panic("can't allocate key def array");
 		}
 		for (int j = 0; cfg_space->index[j] != NULL; ++j) {
 			typeof(cfg_space->index[j]) cfg_index = cfg_space->index[j];
-			key_init(&space[i].key_defs[j], cfg_index);
+			key_init(&spaces[i].key_defs[j], cfg_index);
 		}
-		space_init_field_types(&space[i]);
+		space_init_field_types(&spaces[i]);
 
 		/* fill space indexes */
 		for (int j = 0; cfg_space->index[j] != NULL; ++j) {
 			typeof(cfg_space->index[j]) cfg_index = cfg_space->index[j];
 			enum index_type type = STR2ENUM(index_type, cfg_index->type);
-			struct key_def *key_def = &space[i].key_defs[j];
-			Index *index = [Index alloc: type :key_def :&space[i]];
-			[index init: key_def :&space[i]];
-			space[i].index[j] = index;
+			struct key_def *key_def = &spaces[i].key_defs[j];
+			Index *index = [Index alloc: type :key_def :&spaces[i]];
+			[index init: key_def :&spaces[i]];
+			spaces[i].index[j] = index;
 		}
 		say_info("space %i successfully configured", i);
 	}
@@ -290,8 +290,7 @@ void
 space_init(void)
 {
 	/* Allocate and initialize space memory. */
-	space = palloc(eter_pool, sizeof(struct space) * BOX_SPACE_MAX);
-	memset(space, 0, sizeof(struct space) * BOX_SPACE_MAX);
+	spaces = p0alloc(eter_pool, sizeof(struct space) * BOX_SPACE_MAX);
 
 	/* configure regular spaces */
 	space_config();
@@ -303,16 +302,16 @@ build_indexes(void)
 	assert(secondary_indexes_enabled == false);
 
 	for (u32 n = 0; n < BOX_SPACE_MAX; ++n) {
-		if (space[n].enabled == false)
+		if (spaces[n].enabled == false)
 			continue;
-		if (space[n].key_count <= 1)
+		if (spaces[n].key_count <= 1)
 			continue; /* no secondary keys */
 
 		say_info("Building secondary keys in space %" PRIu32 "...", n);
 
-		Index *pk = space[n].index[0];
-		for (int i = 1; i < space[n].key_count; i++) {
-			Index *index = space[n].index[i];
+		Index *pk = spaces[n].index[0];
+		for (int i = 1; i < spaces[n].key_count; i++) {
+			Index *index = spaces[n].index[i];
 			[index build: pk];
 		}
 
-- 
GitLab