From 82474b467dbcffe42a103faf079f59f5a0b8c01e Mon Sep 17 00:00:00 2001
From: Andrey Saranchin <Andrey22102001@gmail.com>
Date: Thu, 4 May 2023 11:51:56 +0300
Subject: [PATCH] iproto: rename IPROTO_KEY_MAX to iproto_key_MAX

We are going to generate iproto_key enum automatically to generate iproto
constants for Lua as well. This mechanism generates *_MAX constant for enum
using its name, which is in lower case. So let's convert IPROTO_KEY_MAX to
form which is appropriate for enum generator.

Part of #8443

NO_TEST=rename constant
NO_CHANGELOG=internal
NO_DOC=internal
---
 src/box/iproto_constants.c |  4 ++--
 src/box/iproto_constants.h |  6 +++---
 src/box/xrow.c             | 12 ++++++------
 test/unit/xrow.cc          |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/box/iproto_constants.c b/src/box/iproto_constants.c
index 7a468e6b32..86391b06a7 100644
--- a/src/box/iproto_constants.c
+++ b/src/box/iproto_constants.c
@@ -30,7 +30,7 @@
  */
 #include "iproto_constants.h"
 
-const unsigned char iproto_key_type[IPROTO_KEY_MAX] =
+const unsigned char iproto_key_type[iproto_key_MAX] =
 {
 	/* {{{ header */
 		/* 0x00 */	MP_UINT,   /* IPROTO_REQUEST_TYPE */
@@ -198,7 +198,7 @@ const uint64_t iproto_body_key_map[IPROTO_TYPE_STAT_MAX] = {
 };
 #undef bit
 
-const char *iproto_key_strs[IPROTO_KEY_MAX] = {
+const char *iproto_key_strs[iproto_key_MAX] = {
 	"type",             /* 0x00 */
 	"sync",             /* 0x01 */
 	"replica id",       /* 0x02 */
diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h
index 7948c42a08..aca2cf0492 100644
--- a/src/box/iproto_constants.h
+++ b/src/box/iproto_constants.h
@@ -185,7 +185,7 @@ enum iproto_key {
 	 * 0x7f, and we rely on this in some places by allocating a uint8_t to
 	 * hold a msgpack-encoded key value.
 	 */
-	IPROTO_KEY_MAX
+	iproto_key_MAX
 };
 
 /**
@@ -224,7 +224,7 @@ iproto_key_bit(unsigned char key)
 	return 1ULL << key;
 }
 
-extern const unsigned char iproto_key_type[IPROTO_KEY_MAX];
+extern const unsigned char iproto_key_type[iproto_key_MAX];
 
 /**
  * IPROTO command codes.
@@ -427,7 +427,7 @@ static inline const char *
 iproto_key_name(enum iproto_key key)
 {
 	extern const char *iproto_key_strs[];
-	if (key >= IPROTO_KEY_MAX)
+	if (key >= iproto_key_MAX)
 		return NULL;
 	return iproto_key_strs[key];
 }
diff --git a/src/box/xrow.c b/src/box/xrow.c
index 72ed0418f1..586c1ad831 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -163,7 +163,7 @@ xrow_header_decode(struct xrow_header *header, const char **pos,
 		if (mp_typeof(**pos) != MP_UINT)
 			goto bad_header;
 		uint64_t key = mp_decode_uint(pos);
-		if (key >= IPROTO_KEY_MAX ||
+		if (key >= iproto_key_MAX ||
 		    iproto_key_type[key] != mp_typeof(**pos))
 			goto bad_header;
 		switch (key) {
@@ -906,7 +906,7 @@ xrow_decode_dml(struct xrow_header *row, struct request *request,
 		uint64_t key = mp_decode_uint(&data);
 		const char *value = data;
 		mp_next(&data);
-		if (key >= IPROTO_KEY_MAX ||
+		if (key >= iproto_key_MAX ||
 		    iproto_key_type[key] != mp_typeof(*value))
 			goto error;
 		key_map &= ~iproto_key_bit(key);
@@ -1144,7 +1144,7 @@ xrow_decode_id(const struct xrow_header *row, struct id_request *request)
 		if (mp_typeof(*p) != MP_UINT)
 			goto error;
 		uint64_t key = mp_decode_uint(&p);
-		if (key >= IPROTO_KEY_MAX ||
+		if (key >= iproto_key_MAX ||
 		    iproto_key_type[key] != mp_typeof(*p))
 			goto error;
 		switch (key) {
@@ -1252,7 +1252,7 @@ xrow_decode_synchro(const struct xrow_header *row, struct synchro_request *req)
 			continue;
 		}
 		uint8_t key = mp_decode_uint(&d);
-		if (key >= IPROTO_KEY_MAX || iproto_key_type[key] != type) {
+		if (key >= iproto_key_MAX || iproto_key_type[key] != type) {
 			xrow_on_decode_err(row, ER_INVALID_MSGPACK,
 					   "request body");
 			return -1;
@@ -1539,7 +1539,7 @@ xrow_decode_watch(const struct xrow_header *row, struct watch_request *request)
 		if (mp_typeof(*data) != MP_UINT)
 			goto error;
 		uint64_t key = mp_decode_uint(&data);
-		if (key < IPROTO_KEY_MAX &&
+		if (key < iproto_key_MAX &&
 		    iproto_key_type[key] != MP_NIL &&
 		    iproto_key_type[key] != mp_typeof(*data))
 			goto error;
@@ -1720,7 +1720,7 @@ xrow_decode_begin(const struct xrow_header *row, struct begin_request *request)
 		if (mp_typeof(*d) != MP_UINT)
 			goto bad_msgpack;
 		uint64_t key = mp_decode_uint(&d);
-		if (key >= IPROTO_KEY_MAX ||
+		if (key >= iproto_key_MAX ||
 		    mp_typeof(*d) != iproto_key_type[key])
 			goto bad_msgpack;
 		switch (key) {
diff --git a/test/unit/xrow.cc b/test/unit/xrow.cc
index 42ae849d78..b4f7173c47 100644
--- a/test/unit/xrow.cc
+++ b/test/unit/xrow.cc
@@ -50,7 +50,7 @@ test_iproto_constants()
 	 * accessed by an index out of the range
 	 * [0, IPROTO_KEY_MAX).
 	 */
-	for (int i = 0; i < IPROTO_KEY_MAX; ++i)
+	for (int i = 0; i < iproto_key_MAX; ++i)
 		(void) iproto_key_name((enum iproto_key) i);
 
 	/* Same for iproto_type. */
-- 
GitLab