[PATCH v2 5/8] box: rework field_def and tuple_compare to work with mp_field_type instead of mp_type

Serge Petrenko sergepetrenko at tarantool.org
Thu Aug 8 14:55:56 MSK 2019


This a preparation for adding decimal fields and decimal comparators. It
will be needed, since newly introduced user types, such as decimal, will
all share a single mp_type, and we want to avoid additional checks for
MP_EXT subtypes.

Prerequisite #4333
---
 src/box/field_def.c      |  24 ++---
 src/box/field_def.h      |  12 ++-
 src/box/key_def.h        |   2 +-
 src/box/tuple_compare.cc | 228 ++++++++++++++++++++-------------------
 src/box/tuple_format.c   |   2 +-
 5 files changed, 136 insertions(+), 132 deletions(-)

diff --git a/src/box/field_def.c b/src/box/field_def.c
index 346042b98..2fad81d42 100644
--- a/src/box/field_def.c
+++ b/src/box/field_def.c
@@ -49,18 +49,18 @@ const char *mp_type_strs[] = {
 
 const uint32_t field_mp_type[] = {
 	/* [FIELD_TYPE_ANY]      =  */ UINT32_MAX,
-	/* [FIELD_TYPE_UNSIGNED] =  */ 1U << MP_UINT,
-	/* [FIELD_TYPE_STRING]   =  */ 1U << MP_STR,
-	/* [FIELD_TYPE_NUMBER]   =  */ (1U << MP_UINT) | (1U << MP_INT) |
-		(1U << MP_FLOAT) | (1U << MP_DOUBLE),
-	/* [FIELD_TYPE_INTEGER]  =  */ (1U << MP_UINT) | (1U << MP_INT),
-	/* [FIELD_TYPE_BOOLEAN]  =  */ 1U << MP_BOOL,
-	/* [FIELD_TYPE_VARBINARY] =  */ 1U << MP_BIN,
-	/* [FIELD_TYPE_SCALAR]   =  */ (1U << MP_UINT) | (1U << MP_INT) |
-		(1U << MP_FLOAT) | (1U << MP_DOUBLE) | (1U << MP_STR) |
-		(1U << MP_BIN) | (1U << MP_BOOL),
-	/* [FIELD_TYPE_ARRAY]    =  */ 1U << MP_ARRAY,
-	/* [FIELD_TYPE_MAP]      =  */ (1U << MP_MAP),
+	/* [FIELD_TYPE_UNSIGNED] =  */ 1U << MP_FIELD_UINT,
+	/* [FIELD_TYPE_STRING]   =  */ 1U << MP_FIELD_STR,
+	/* [FIELD_TYPE_NUMBER]   =  */ (1U << MP_FIELD_UINT) | (1U << MP_FIELD_INT) |
+		(1U << MP_FIELD_FLOAT) | (1U << MP_FIELD_DOUBLE),
+	/* [FIELD_TYPE_INTEGER]  =  */ (1U << MP_FIELD_UINT) | (1U << MP_FIELD_INT),
+	/* [FIELD_TYPE_BOOLEAN]  =  */ 1U << MP_FIELD_BOOL,
+	/* [FIELD_TYPE_VARBINARY] =  */ 1U << MP_FIELD_BIN,
+	/* [FIELD_TYPE_SCALAR]   =  */ (1U << MP_FIELD_UINT) | (1U << MP_FIELD_INT) |
+		(1U << MP_FIELD_FLOAT) | (1U << MP_FIELD_DOUBLE) | (1U << MP_FIELD_STR) |
+		(1U << MP_FIELD_BIN) | (1U << MP_FIELD_BOOL),
+	/* [FIELD_TYPE_ARRAY]    =  */ 1U << MP_FIELD_ARRAY,
+	/* [FIELD_TYPE_MAP]      =  */ (1U << MP_FIELD_MAP),
 };
 
 const char *field_type_strs[] = {
diff --git a/src/box/field_def.h b/src/box/field_def.h
index c1a7ec0a9..2f21f3cfc 100644
--- a/src/box/field_def.h
+++ b/src/box/field_def.h
@@ -37,6 +37,7 @@
 #include <limits.h>
 #include <msgpuck.h>
 #include "opt_def.h"
+#include "mp_user_types.h"
 
 #if defined(__cplusplus)
 extern "C" {
@@ -142,15 +143,16 @@ struct field_def {
 	struct Expr *default_value_expr;
 };
 
-/** Checks if mp_type (MsgPack) is compatible with field type. */
+/** Checks if mp_typeof(data) is compatible with field type. */
 static inline bool
-field_mp_type_is_compatible(enum field_type type, enum mp_type mp_type,
+field_mp_type_is_compatible(enum field_type type, const char *data,
 			    bool is_nullable)
 {
+	enum mp_field_type check_type = msgpack_to_field_type(data);
 	assert(type < field_type_MAX);
-	assert((size_t)mp_type < CHAR_BIT * sizeof(*field_mp_type));
-	uint32_t mask = field_mp_type[type] | (is_nullable * (1U << MP_NIL));
-	return (mask & (1U << mp_type)) != 0;
+	assert((size_t)check_type < CHAR_BIT * sizeof(*field_mp_type));
+	uint32_t mask = field_mp_type[type] | (is_nullable * (1U << MP_FIELD_NIL));
+	return (mask & (1U << check_type)) != 0;
 }
 
 static inline bool
diff --git a/src/box/key_def.h b/src/box/key_def.h
index c6e33e4ad..4ce842aff 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -528,7 +528,7 @@ static inline int
 key_part_validate(enum field_type key_type, const char *key,
 		  uint32_t field_no, bool is_nullable)
 {
-	if (unlikely(!field_mp_type_is_compatible(key_type, mp_typeof(*key),
+	if (unlikely(!field_mp_type_is_compatible(key_type, key,
 						  is_nullable))) {
 		diag_set(ClientError, ER_KEY_PART_TYPE, field_no,
 			 field_type_strs[key_type]);
diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc
index b7b54e21a..b4932db6d 100644
--- a/src/box/tuple_compare.cc
+++ b/src/box/tuple_compare.cc
@@ -77,23 +77,24 @@ enum mp_class {
 };
 
 static enum mp_class mp_classes[] = {
-	/* .MP_NIL     = */ MP_CLASS_NIL,
-	/* .MP_UINT    = */ MP_CLASS_NUMBER,
-	/* .MP_INT     = */ MP_CLASS_NUMBER,
-	/* .MP_STR     = */ MP_CLASS_STR,
-	/* .MP_BIN     = */ MP_CLASS_BIN,
-	/* .MP_ARRAY   = */ MP_CLASS_ARRAY,
-	/* .MP_MAP     = */ MP_CLASS_MAP,
-	/* .MP_BOOL    = */ MP_CLASS_BOOL,
-	/* .MP_FLOAT   = */ MP_CLASS_NUMBER,
-	/* .MP_DOUBLE  = */ MP_CLASS_NUMBER,
-	/* .MP_BIN     = */ MP_CLASS_BIN
+	/* .MP_FIELD_UNKNOWN = */ mp_class_max,
+	/* .MP_FIELD_NIL     = */ MP_CLASS_NIL,
+	/* .MP_FIELD_INT     = */ MP_CLASS_NUMBER,
+	/* .MP_FIELD_UINT    = */ MP_CLASS_NUMBER,
+	/* .MP_FIELD_STR     = */ MP_CLASS_STR,
+	/* .MP_FIELD_BIN     = */ MP_CLASS_BIN,
+	/* .MP_FIELD_ARRAY   = */ MP_CLASS_ARRAY,
+	/* .MP_FIELD_MAP     = */ MP_CLASS_MAP,
+	/* .MP_FIELD_BOOL    = */ MP_CLASS_BOOL,
+	/* .MP_FIELD_FLOAT   = */ MP_CLASS_NUMBER,
+	/* .MP_FIELD_DOUBLE  = */ MP_CLASS_NUMBER,
+	/* .MP_FIELD_BIN     = */ MP_CLASS_BIN
 };
 
 #define COMPARE_RESULT(a, b) (a < b ? -1 : a > b)
 
 static enum mp_class
-mp_classof(enum mp_type type)
+mp_classof(enum mp_field_type type)
 {
 	return mp_classes[type];
 }
@@ -107,14 +108,14 @@ mp_compare_bool(const char *field_a, const char *field_b)
 }
 
 static int
-mp_compare_integer_with_type(const char *field_a, enum mp_type a_type,
-			     const char *field_b, enum mp_type b_type)
+mp_compare_integer_with_type(const char *field_a, enum mp_field_type a_type,
+			     const char *field_b, enum mp_field_type b_type)
 {
 	assert(mp_classof(a_type) == MP_CLASS_NUMBER);
 	assert(mp_classof(b_type) == MP_CLASS_NUMBER);
-	if (a_type == MP_UINT) {
+	if (a_type == MP_FIELD_UINT) {
 		uint64_t a_val = mp_decode_uint(&field_a);
-		if (b_type == MP_UINT) {
+		if (b_type == MP_FIELD_UINT) {
 			uint64_t b_val = mp_decode_uint(&field_b);
 			return COMPARE_RESULT(a_val, b_val);
 		} else {
@@ -125,7 +126,7 @@ mp_compare_integer_with_type(const char *field_a, enum mp_type a_type,
 		}
 	} else {
 		int64_t a_val = mp_decode_int(&field_a);
-		if (b_type == MP_UINT) {
+		if (b_type == MP_FIELD_UINT) {
 			uint64_t b_val = mp_decode_uint(&field_b);
 			if (a_val < 0)
 				return -1;
@@ -209,10 +210,10 @@ mp_compare_double_uint64(double lhs, uint64_t rhs, int k)
 }
 
 static int
-mp_compare_double_any_int(double lhs, const char *rhs, enum mp_type rhs_type,
+mp_compare_double_any_int(double lhs, const char *rhs, enum mp_field_type rhs_type,
 			  int k)
 {
-	if (rhs_type == MP_INT) {
+	if (rhs_type == MP_FIELD_INT) {
 		int64_t v = mp_decode_int(&rhs);
 		if (v < 0) {
 			return mp_compare_double_uint64(-lhs, (uint64_t)-v,
@@ -220,18 +221,18 @@ mp_compare_double_any_int(double lhs, const char *rhs, enum mp_type rhs_type,
 		}
 		return mp_compare_double_uint64(lhs, (uint64_t)v, k);
 	}
-	assert(rhs_type == MP_UINT);
+	assert(rhs_type == MP_FIELD_UINT);
 	return mp_compare_double_uint64(lhs, mp_decode_uint(&rhs), k);
 }
 
 static int
 mp_compare_double_any_number(double lhs, const char *rhs,
-			     enum mp_type rhs_type, int k)
+			     enum mp_field_type rhs_type, int k)
 {
 	double v;
-	if (rhs_type == MP_FLOAT)
+	if (rhs_type == MP_FIELD_FLOAT)
 		v = mp_decode_float(&rhs);
-	else if (rhs_type == MP_DOUBLE)
+	else if (rhs_type == MP_FIELD_DOUBLE)
 		v = mp_decode_double(&rhs);
 	else
 		return mp_compare_double_any_int(lhs, rhs, rhs_type, k);
@@ -265,42 +266,42 @@ mp_compare_double_any_number(double lhs, const char *rhs,
 }
 
 static int
-mp_compare_number_with_type(const char *lhs, enum mp_type lhs_type,
-			    const char *rhs, enum mp_type rhs_type)
+mp_compare_number_with_type(const char *lhs, enum mp_field_type lhs_type,
+			    const char *rhs, enum mp_field_type rhs_type)
 {
 	assert(mp_classof(lhs_type) == MP_CLASS_NUMBER);
 	assert(mp_classof(rhs_type) == MP_CLASS_NUMBER);
 
-	if (rhs_type == MP_FLOAT) {
+	if (rhs_type == MP_FIELD_FLOAT) {
 		return mp_compare_double_any_number(
 			mp_decode_float(&rhs), lhs, lhs_type, -1
 		);
 	}
-	if (rhs_type == MP_DOUBLE) {
+	if (rhs_type == MP_FIELD_DOUBLE) {
 		return mp_compare_double_any_number(
 			mp_decode_double(&rhs), lhs, lhs_type, -1
 		);
 	}
-	assert(rhs_type == MP_INT || rhs_type == MP_UINT);
-	if (lhs_type == MP_FLOAT) {
+	assert(rhs_type == MP_FIELD_INT || rhs_type == MP_FIELD_UINT);
+	if (lhs_type == MP_FIELD_FLOAT) {
 		return mp_compare_double_any_int(
 			mp_decode_float(&lhs), rhs, rhs_type, 1
 		);
 	}
-	if (lhs_type == MP_DOUBLE) {
+	if (lhs_type == MP_FIELD_DOUBLE) {
 		return mp_compare_double_any_int(
 			mp_decode_double(&lhs), rhs, rhs_type, 1
 		);
 	}
-	assert(lhs_type == MP_INT || lhs_type == MP_UINT);
+	assert(lhs_type == MP_FIELD_INT || lhs_type == MP_FIELD_UINT);
 	return mp_compare_integer_with_type(lhs, lhs_type, rhs, rhs_type);
 }
 
 static inline int
 mp_compare_number(const char *lhs, const char *rhs)
 {
-	return mp_compare_number_with_type(lhs, mp_typeof(*lhs),
-					   rhs, mp_typeof(*rhs));
+	return mp_compare_number_with_type(lhs, msgpack_to_field_type(lhs),
+					   rhs, msgpack_to_field_type(rhs));
 }
 
 static inline int
@@ -345,9 +346,10 @@ static mp_compare_f mp_class_comparators[] = {
 };
 
 static int
-mp_compare_scalar_with_type(const char *field_a, enum mp_type a_type,
-			    const char *field_b, enum mp_type b_type)
+mp_compare_scalar_with_type(const char *field_a, enum mp_field_type a_type,
+			    const char *field_b, enum mp_field_type b_type)
 {
+	assert(a_type != MP_FIELD_UNKNOWN && b_type != MP_FIELD_UNKNOWN);
 	enum mp_class a_class = mp_classof(a_type);
 	enum mp_class b_class = mp_classof(b_type);
 	if (a_class != b_class)
@@ -360,17 +362,17 @@ mp_compare_scalar_with_type(const char *field_a, enum mp_type a_type,
 static inline int
 mp_compare_scalar(const char *field_a, const char *field_b)
 {
-	return mp_compare_scalar_with_type(field_a, mp_typeof(*field_a),
-					   field_b, mp_typeof(*field_b));
+	return mp_compare_scalar_with_type(field_a, msgpack_to_field_type(field_a),
+					   field_b, msgpack_to_field_type(field_b));
 }
 
 static inline int
 mp_compare_scalar_coll(const char *field_a, const char *field_b,
 		       struct coll *coll)
 {
-	enum mp_type type_a = mp_typeof(*field_a);
-	enum mp_type type_b = mp_typeof(*field_b);
-	if (type_a == MP_STR && type_b == MP_STR)
+	enum mp_field_type type_a = msgpack_to_field_type(field_a);
+	enum mp_field_type type_b = msgpack_to_field_type(field_b);
+	if (type_a == MP_FIELD_STR && type_b == MP_FIELD_STR)
 		return mp_compare_str_coll(field_a, field_b, coll);
 	return mp_compare_scalar_with_type(field_a, type_a, field_b, type_b);
 }
@@ -397,9 +399,9 @@ tuple_compare_field(const char *field_a, const char *field_b,
 		       mp_compare_str(field_a, field_b);
 	case FIELD_TYPE_INTEGER:
 		return mp_compare_integer_with_type(field_a,
-						    mp_typeof(*field_a),
+						    msgpack_to_field_type(field_a),
 						    field_b,
-						    mp_typeof(*field_b));
+						    msgpack_to_field_type(field_b));
 	case FIELD_TYPE_NUMBER:
 		return mp_compare_number(field_a, field_b);
 	case FIELD_TYPE_BOOLEAN:
@@ -417,8 +419,8 @@ tuple_compare_field(const char *field_a, const char *field_b,
 }
 
 static int
-tuple_compare_field_with_type(const char *field_a, enum mp_type a_type,
-			      const char *field_b, enum mp_type b_type,
+tuple_compare_field_with_type(const char *field_a, enum mp_field_type a_type,
+			      const char *field_b, enum mp_field_type b_type,
 			      int8_t type, struct coll *coll)
 {
 	switch (type) {
@@ -482,11 +484,11 @@ tuple_compare_slowpath(struct tuple *tuple_a, hint_t tuple_a_hint,
 			return tuple_compare_field(tuple_a_raw, tuple_b_raw,
 						   part->type, part->coll);
 		}
-		enum mp_type a_type = mp_typeof(*tuple_a_raw);
-		enum mp_type b_type = mp_typeof(*tuple_b_raw);
-		if (a_type == MP_NIL)
-			return b_type == MP_NIL ? 0 : -1;
-		else if (b_type == MP_NIL)
+		enum mp_field_type a_type = msgpack_to_field_type(tuple_a_raw);
+		enum mp_field_type b_type = msgpack_to_field_type(tuple_b_raw);
+		if (a_type == MP_FIELD_NIL)
+			return b_type == MP_FIELD_NIL ? 0 : -1;
+		else if (b_type == MP_FIELD_NIL)
 			return 1;
 		return tuple_compare_field_with_type(tuple_a_raw,  a_type,
 						     tuple_b_raw, b_type,
@@ -500,7 +502,7 @@ tuple_compare_slowpath(struct tuple *tuple_a, hint_t tuple_a_hint,
 	const uint32_t *field_map_b = tuple_field_map(tuple_b);
 	struct key_part *end;
 	const char *field_a, *field_b;
-	enum mp_type a_type, b_type;
+	enum mp_field_type a_type, b_type;
 	if (is_nullable)
 		end = part + key_def->unique_part_count;
 	else
@@ -538,17 +540,17 @@ tuple_compare_slowpath(struct tuple *tuple_a, hint_t tuple_a_hint,
 				continue;
 		}
 		if (has_optional_parts) {
-			a_type = field_a != NULL ? mp_typeof(*field_a) : MP_NIL;
-			b_type = field_b != NULL ? mp_typeof(*field_b) : MP_NIL;
+			a_type = field_a != NULL ? msgpack_to_field_type(field_a) : MP_FIELD_NIL;
+			b_type = field_b != NULL ? msgpack_to_field_type(field_b) : MP_FIELD_NIL;
 		} else {
-			a_type = mp_typeof(*field_a);
-			b_type = mp_typeof(*field_b);
+			a_type = msgpack_to_field_type(field_a);
+			b_type = msgpack_to_field_type(field_b);
 		}
-		if (a_type == MP_NIL) {
-			if (b_type != MP_NIL)
+		if (a_type == MP_FIELD_NIL) {
+			if (b_type != MP_FIELD_NIL)
 				return -1;
 			was_null_met = true;
-		} else if (b_type == MP_NIL) {
+		} else if (b_type == MP_FIELD_NIL) {
 			return 1;
 		} else {
 			rc = tuple_compare_field_with_type(field_a, a_type,
@@ -629,7 +631,7 @@ tuple_compare_with_key_slowpath(struct tuple *tuple, hint_t tuple_hint,
 	struct tuple_format *format = tuple_format(tuple);
 	const char *tuple_raw = tuple_data(tuple);
 	const uint32_t *field_map = tuple_field_map(tuple);
-	enum mp_type a_type, b_type;
+	enum mp_field_type a_type, b_type;
 	if (likely(part_count == 1)) {
 		const char *field;
 		if (is_multikey) {
@@ -649,13 +651,13 @@ tuple_compare_with_key_slowpath(struct tuple *tuple, hint_t tuple_hint,
 						   part->coll);
 		}
 		if (has_optional_parts)
-			a_type = field != NULL ? mp_typeof(*field) : MP_NIL;
+			a_type = field != NULL ? msgpack_to_field_type(field) : MP_FIELD_NIL;
 		else
-			a_type = mp_typeof(*field);
-		b_type = mp_typeof(*key);
-		if (a_type == MP_NIL) {
-			return b_type == MP_NIL ? 0 : -1;
-		} else if (b_type == MP_NIL) {
+			a_type = msgpack_to_field_type(field);
+		b_type = msgpack_to_field_type(key);
+		if (a_type == MP_FIELD_NIL) {
+			return b_type == MP_FIELD_NIL ? 0 : -1;
+		} else if (b_type == MP_FIELD_NIL) {
 			return 1;
 		} else {
 			return tuple_compare_field_with_type(field, a_type, key,
@@ -688,14 +690,14 @@ tuple_compare_with_key_slowpath(struct tuple *tuple, hint_t tuple_hint,
 				continue;
 		}
 		if (has_optional_parts)
-			a_type = field != NULL ? mp_typeof(*field) : MP_NIL;
+			a_type = field != NULL ? msgpack_to_field_type(field) : MP_FIELD_NIL;
 		else
-			a_type = mp_typeof(*field);
-		b_type = mp_typeof(*key);
-		if (a_type == MP_NIL) {
-			if (b_type != MP_NIL)
+			a_type = msgpack_to_field_type(field);
+		b_type = msgpack_to_field_type(key);
+		if (a_type == MP_FIELD_NIL) {
+			if (b_type != MP_FIELD_NIL)
 				return -1;
-		} else if (b_type == MP_NIL) {
+		} else if (b_type == MP_FIELD_NIL) {
 			return 1;
 		} else {
 			rc = tuple_compare_field_with_type(field, a_type, key,
@@ -721,11 +723,11 @@ key_compare_parts(const char *key_a, const char *key_b, uint32_t part_count,
 			return tuple_compare_field(key_a, key_b, part->type,
 						   part->coll);
 		}
-		enum mp_type a_type = mp_typeof(*key_a);
-		enum mp_type b_type = mp_typeof(*key_b);
-		if (a_type == MP_NIL) {
-			return b_type == MP_NIL ? 0 : -1;
-		} else if (b_type == MP_NIL) {
+		enum mp_field_type a_type = msgpack_to_field_type(key_a);
+		enum mp_field_type b_type = msgpack_to_field_type(key_b);
+		if (a_type == MP_FIELD_NIL) {
+			return b_type == MP_FIELD_NIL ? 0 : -1;
+		} else if (b_type == MP_FIELD_NIL) {
 			return 1;
 		} else {
 			return tuple_compare_field_with_type(key_a, a_type,
@@ -746,12 +748,12 @@ key_compare_parts(const char *key_a, const char *key_b, uint32_t part_count,
 			else
 				continue;
 		}
-		enum mp_type a_type = mp_typeof(*key_a);
-		enum mp_type b_type = mp_typeof(*key_b);
-		if (a_type == MP_NIL) {
-			if (b_type != MP_NIL)
+		enum mp_field_type a_type = msgpack_to_field_type(key_a);
+		enum mp_field_type b_type = msgpack_to_field_type(key_b);
+		if (a_type == MP_FIELD_NIL) {
+			if (b_type != MP_FIELD_NIL)
 				return -1;
-		} else if (b_type == MP_NIL) {
+		} else if (b_type == MP_FIELD_NIL) {
 			return 1;
 		} else {
 			rc = tuple_compare_field_with_type(key_a, a_type, key_b,
@@ -802,7 +804,7 @@ tuple_compare_with_key_sequential(struct tuple *tuple, hint_t tuple_hint,
 		key += tuple->bsize - mp_sizeof_array(field_count);
 		for (uint32_t i = field_count; i < part_count;
 		     ++i, mp_next(&key)) {
-			if (mp_typeof(*key) != MP_NIL)
+			if (msgpack_to_field_type(key) != MP_FIELD_NIL)
 				return -1;
 		}
 	}
@@ -859,19 +861,19 @@ tuple_compare_sequential(struct tuple *tuple_a, hint_t tuple_a_hint,
 	struct key_part *end = part + key_def->unique_part_count;
 	uint32_t i = 0;
 	for (; part < end; ++part, ++i) {
-		enum mp_type a_type, b_type;
+		enum mp_field_type a_type, b_type;
 		if (has_optional_parts) {
-			a_type = i >= fc_a ? MP_NIL : mp_typeof(*key_a);
-			b_type = i >= fc_b ? MP_NIL : mp_typeof(*key_b);
+			a_type = i >= fc_a ? MP_FIELD_NIL : msgpack_to_field_type(key_a);
+			b_type = i >= fc_b ? MP_FIELD_NIL : msgpack_to_field_type(key_b);
 		} else {
-			a_type = mp_typeof(*key_a);
-			b_type = mp_typeof(*key_b);
+			a_type = msgpack_to_field_type(key_a);
+			b_type = msgpack_to_field_type(key_b);
 		}
-		if (a_type == MP_NIL) {
-			if (b_type != MP_NIL)
+		if (a_type == MP_FIELD_NIL) {
+			if (b_type != MP_FIELD_NIL)
 				return -1;
 			was_null_met = true;
-		} else if (b_type == MP_NIL) {
+		} else if (b_type == MP_FIELD_NIL) {
 			return 1;
 		} else {
 			rc = tuple_compare_field_with_type(key_a, a_type, key_b,
@@ -1292,9 +1294,9 @@ func_index_compare(struct tuple *tuple_a, hint_t tuple_a_hint,
 
 	const char *key_a = (const char *)tuple_a_hint;
 	const char *key_b = (const char *)tuple_b_hint;
-	assert(mp_typeof(*key_a) == MP_ARRAY);
+	assert(msgpack_to_field_type(key_a) == MP_FIELD_ARRAY);
 	uint32_t part_count_a = mp_decode_array(&key_a);
-	assert(mp_typeof(*key_b) == MP_ARRAY);
+	assert(msgpack_to_field_type(key_b) == MP_FIELD_ARRAY);
 	uint32_t part_count_b = mp_decode_array(&key_b);
 
 	uint32_t key_part_count = MIN(part_count_a, part_count_b);
@@ -1349,7 +1351,7 @@ func_index_compare_with_key(struct tuple *tuple, hint_t tuple_hint,
 	assert(key_def->for_func_index);
 	assert(is_nullable == key_def->is_nullable);
 	const char *tuple_key = (const char *)tuple_hint;
-	assert(mp_typeof(*tuple_key) == MP_ARRAY);
+	assert(msgpack_to_field_type(tuple_key) == MP_FIELD_ARRAY);
 
 	uint32_t tuple_key_count = mp_decode_array(&tuple_key);
 	part_count = MIN(part_count, tuple_key_count);
@@ -1541,24 +1543,24 @@ hint_bin(const char *s, uint32_t len)
 static inline hint_t
 field_hint_boolean(const char *field)
 {
-	assert(mp_typeof(*field) == MP_BOOL);
+	assert(msgpack_to_field_type(field) == MP_FIELD_BOOL);
 	return hint_bool(mp_decode_bool(&field));
 }
 
 static inline hint_t
 field_hint_unsigned(const char *field)
 {
-	assert(mp_typeof(*field) == MP_UINT);
+	assert(msgpack_to_field_type(field) == MP_FIELD_UINT);
 	return hint_uint(mp_decode_uint(&field));
 }
 
 static inline hint_t
 field_hint_integer(const char *field)
 {
-	switch (mp_typeof(*field)) {
-	case MP_UINT:
+	switch (msgpack_to_field_type(field)) {
+	case MP_FIELD_UINT:
 		return hint_uint(mp_decode_uint(&field));
-	case MP_INT:
+	case MP_FIELD_INT:
 		return hint_int(mp_decode_int(&field));
 	default:
 		unreachable();
@@ -1569,14 +1571,14 @@ field_hint_integer(const char *field)
 static inline hint_t
 field_hint_number(const char *field)
 {
-	switch (mp_typeof(*field)) {
-	case MP_UINT:
+	switch (msgpack_to_field_type(field)) {
+	case MP_FIELD_UINT:
 		return hint_uint(mp_decode_uint(&field));
-	case MP_INT:
+	case MP_FIELD_INT:
 		return hint_int(mp_decode_int(&field));
-	case MP_FLOAT:
+	case MP_FIELD_FLOAT:
 		return hint_double(mp_decode_float(&field));
-	case MP_DOUBLE:
+	case MP_FIELD_DOUBLE:
 		return hint_double(mp_decode_double(&field));
 	default:
 		unreachable();
@@ -1587,7 +1589,7 @@ field_hint_number(const char *field)
 static inline hint_t
 field_hint_string(const char *field, struct coll *coll)
 {
-	assert(mp_typeof(*field) == MP_STR);
+	assert(msgpack_to_field_type(field) == MP_FIELD_STR);
 	uint32_t len = mp_decode_strl(&field);
 	return coll == NULL ? hint_str(field, len) :
 			      hint_str_coll(field, len, coll);
@@ -1596,7 +1598,7 @@ field_hint_string(const char *field, struct coll *coll)
 static inline hint_t
 field_hint_varbinary(const char *field)
 {
-	assert(mp_typeof(*field) == MP_BIN);
+	assert(msgpack_to_field_type(field) == MP_FIELD_BIN);
 	uint32_t len = mp_decode_binl(&field);
 	return hint_bin(field, len);
 }
@@ -1605,22 +1607,22 @@ static inline hint_t
 field_hint_scalar(const char *field, struct coll *coll)
 {
 	uint32_t len;
-	switch(mp_typeof(*field)) {
-	case MP_BOOL:
+	switch(msgpack_to_field_type(field)) {
+	case MP_FIELD_BOOL:
 		return hint_bool(mp_decode_bool(&field));
-	case MP_UINT:
+	case MP_FIELD_UINT:
 		return hint_uint(mp_decode_uint(&field));
-	case MP_INT:
+	case MP_FIELD_INT:
 		return hint_int(mp_decode_int(&field));
-	case MP_FLOAT:
+	case MP_FIELD_FLOAT:
 		return hint_double(mp_decode_float(&field));
-	case MP_DOUBLE:
+	case MP_FIELD_DOUBLE:
 		return hint_double(mp_decode_double(&field));
-	case MP_STR:
+	case MP_FIELD_STR:
 		len = mp_decode_strl(&field);
 		return coll == NULL ? hint_str(field, len) :
 				      hint_str_coll(field, len, coll);
-	case MP_BIN:
+	case MP_FIELD_BIN:
 		len = mp_decode_binl(&field);
 		return hint_bin(field, len);
 	default:
@@ -1633,7 +1635,7 @@ template <enum field_type type, bool is_nullable>
 static inline hint_t
 field_hint(const char *field, struct coll *coll)
 {
-	if (is_nullable && mp_typeof(*field) == MP_NIL)
+	if (is_nullable && msgpack_to_field_type(field) == MP_FIELD_NIL)
 		return hint_nil();
 	switch (type) {
 	case FIELD_TYPE_BOOLEAN:
diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
index 514d5d9c0..bd7f985db 100644
--- a/src/box/tuple_format.c
+++ b/src/box/tuple_format.c
@@ -1169,7 +1169,7 @@ tuple_format_iterator_next(struct tuple_format_iterator *it,
 	 * defined in format.
 	 */
 	bool is_nullable = tuple_field_is_nullable(field);
-	if (!field_mp_type_is_compatible(field->type, mp_typeof(*entry->data),
+	if (!field_mp_type_is_compatible(field->type, entry->data,
 					 is_nullable) != 0) {
 		diag_set(ClientError, ER_FIELD_TYPE,
 			 tuple_field_path(field),
-- 
2.20.1 (Apple Git-117)




More information about the Tarantool-patches mailing list