From a4a80d00041b48a438f3739680badd4507276bde Mon Sep 17 00:00:00 2001
From: Georgiy Lebedev <g.lebedev@tarantool.org>
Date: Thu, 23 Feb 2023 13:09:26 +0300
Subject: [PATCH] box: add `space_id_is_system` helper
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In some cases we don't have the whole space struct, but we want to
determine whether the provided space identifier corresponds to a system
space — add a `space_id_is_system` helper and refactor `space_is_system` to
reuse it.

Needed for #7974

NO_CHANGELOG=refactoring
NO_DOC=refactoring
NO_TEST=refactoring

(cherry picked from commit 928e57332e9a46702e54b0525cc72b24daf0f186)
---
 src/box/schema_def.h | 12 ++++++++++++
 src/box/space.c      |  3 +--
 src/box/space.h      |  3 +--
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/box/schema_def.h b/src/box/schema_def.h
index 422065b8df..34529790d2 100644
--- a/src/box/schema_def.h
+++ b/src/box/schema_def.h
@@ -345,6 +345,18 @@ schema_object_name(enum schema_object_type type);
 const char *
 schema_entity_name(enum schema_object_type type);
 
+/**
+ * Check that the space id corresponds to a system space, which means that is
+ * has a special meaning for tarantool and has predefined insert/remove
+ * triggers.
+ */
+static inline bool
+space_id_is_system(uint32_t space_id)
+{
+	return space_id > BOX_SYSTEM_ID_MIN &&
+	       space_id < BOX_SYSTEM_ID_MAX;
+}
+
 #if defined(__cplusplus)
 } /* extern "C" */
 #endif /* defined(__cplusplus) */
diff --git a/src/box/space.c b/src/box/space.c
index 4cea54cc29..970b12bcdb 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -122,8 +122,7 @@ space_fill_index_map(struct space *space)
 bool
 space_is_system(const struct space *space)
 {
-	return space->def->id > BOX_SYSTEM_ID_MIN &&
-	       space->def->id < BOX_SYSTEM_ID_MAX;
+	return space_id_is_system(space->def->id);
 }
 
 /**
diff --git a/src/box/space.h b/src/box/space.h
index a676d610a6..6301ac7cfe 100644
--- a/src/box/space.h
+++ b/src/box/space.h
@@ -541,8 +541,7 @@ space_is_vinyl(const struct space *space)
 }
 
 /**
- * Check that the space is a system space, which means that is has a special
- * meaning for tarantool and has predefined insert/remove triggers.
+ * Check that the space is a system space, see also `space_id_is_system`.
  */
 bool
 space_is_system(const struct space *space);
-- 
GitLab