[tarantool-patches] [PATCH v4 19/20] refactoring: remove exceptions from ck_constraint_def_new_from_tuple
Ilya Kosarev
i.kosarev at tarantool.org
Mon Sep 23 18:57:10 MSK 2019
ck_constraint_def_new_from_tuple is used in
on_replace_dd_ck_constraint therefore it has to be cleared from
exceptions. Now it doesn't throw any more. It's usages are updated.
Some _xc functions, not needed any more, are removed.
Part of #4247
---
src/box/alter.cc | 39 ++++++++++++++++++++++++---------------
src/box/identifier.h | 10 ----------
src/box/tuple.h | 20 --------------------
3 files changed, 24 insertions(+), 45 deletions(-)
diff --git a/src/box/alter.cc b/src/box/alter.cc
index f94603ab3..8a15738c9 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -5244,34 +5244,41 @@ static struct ck_constraint_def *
ck_constraint_def_new_from_tuple(struct tuple *tuple)
{
uint32_t name_len;
- const char *name =
- tuple_field_str_xc(tuple, BOX_CK_CONSTRAINT_FIELD_NAME,
- &name_len);
+ const char *name = tuple_field_str(tuple, BOX_CK_CONSTRAINT_FIELD_NAME,
+ &name_len);
+ if (name == NULL)
+ return NULL;
if (name_len > BOX_NAME_MAX) {
- tnt_raise(ClientError, ER_CREATE_CK_CONSTRAINT,
+ diag_set(ClientError, ER_CREATE_CK_CONSTRAINT,
tt_cstr(name, BOX_INVALID_NAME_MAX),
"check constraint name is too long");
+ return NULL;
}
- identifier_check_xc(name, name_len);
- uint32_t space_id =
- tuple_field_u32_xc(tuple, BOX_CK_CONSTRAINT_FIELD_SPACE_ID);
- const char *language_str =
- tuple_field_cstr_xc(tuple, BOX_CK_CONSTRAINT_FIELD_LANGUAGE);
+ if (identifier_check(name, name_len) != 0)
+ return NULL;
+ uint32_t space_id;
+ if (tuple_field_u32(tuple, BOX_CK_CONSTRAINT_FIELD_SPACE_ID,
+ &space_id) != 0)
+ return NULL;
+ const char *language_str = tuple_field_cstr(tuple,
+ BOX_CK_CONSTRAINT_FIELD_LANGUAGE);
+ if (language_str == NULL)
+ return NULL;
enum ck_constraint_language language =
STR2ENUM(ck_constraint_language, language_str);
if (language == ck_constraint_language_MAX) {
- tnt_raise(ClientError, ER_FUNCTION_LANGUAGE, language_str,
+ diag_set(ClientError, ER_FUNCTION_LANGUAGE, language_str,
tt_cstr(name, name_len));
+ return NULL;
}
uint32_t expr_str_len;
- const char *expr_str =
- tuple_field_str_xc(tuple, BOX_CK_CONSTRAINT_FIELD_CODE,
- &expr_str_len);
+ const char *expr_str = tuple_field_str(tuple,
+ BOX_CK_CONSTRAINT_FIELD_CODE, &expr_str_len);
+ if (expr_str == NULL)
+ return NULL;
struct ck_constraint_def *ck_def =
ck_constraint_def_new(name, name_len, expr_str, expr_str_len,
space_id, language);
- if (ck_def == NULL)
- diag_raise();
return ck_def;
}
@@ -5381,6 +5388,8 @@ on_replace_dd_ck_constraint(struct trigger * /* trigger*/, void *event)
/* Create or replace check constraint. */
struct ck_constraint_def *ck_def =
ck_constraint_def_new_from_tuple(new_tuple);
+ if (ck_def == NULL)
+ return -1;
auto ck_def_guard = make_scoped_guard([=] {
ck_constraint_def_delete(ck_def);
});
diff --git a/src/box/identifier.h b/src/box/identifier.h
index a0ed6c10e..0d39793ba 100644
--- a/src/box/identifier.h
+++ b/src/box/identifier.h
@@ -51,16 +51,6 @@ identifier_check(const char *str, int str_len);
#if defined(__cplusplus)
} /* extern "C" */
-/**
- * Throw an error if identifier is not valid.
- */
-static inline void
-identifier_check_xc(const char *str, int str_len)
-{
- if (identifier_check(str, str_len))
- diag_raise();
-}
-
#endif /* defined(__cplusplus) */
#endif /* TARANTOOL_BOX_IDENTIFIER_H_INCLUDED */
diff --git a/src/box/tuple.h b/src/box/tuple.h
index c208ac0ea..398feaf39 100644
--- a/src/box/tuple.h
+++ b/src/box/tuple.h
@@ -1128,26 +1128,6 @@ tuple_field_u32_xc(struct tuple *tuple, uint32_t fieldno)
return out;
}
-/** @copydoc tuple_field_str() */
-static inline const char *
-tuple_field_str_xc(struct tuple *tuple, uint32_t fieldno, uint32_t *len)
-{
- const char *ret = tuple_field_str(tuple, fieldno, len);
- if (ret == NULL)
- diag_raise();
- return ret;
-}
-
-/** @copydoc tuple_field_cstr() */
-static inline const char *
-tuple_field_cstr_xc(struct tuple *tuple, uint32_t fieldno)
-{
- const char *out = tuple_field_cstr(tuple, fieldno);
- if (out == NULL)
- diag_raise();
- return out;
-}
-
#endif /* defined(__cplusplus) */
#endif /* TARANTOOL_BOX_TUPLE_H_INCLUDED */
--
2.17.1
More information about the Tarantool-patches
mailing list