[Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup

Timur Safin tsafin at tarantool.org
Wed Oct 14 03:15:41 MSK 2020


Exporting `box_key_def_dup` as accessor to the internal `key_def_dup`

Part of #5384
---
 extra/exports                    |  1 +
 src/box/key_def.c                |  6 ++++++
 src/box/key_def.h                | 10 ++++++++++
 test/app-tap/module_api.c        | 29 +++++++++++++++++++++++++++++
 test/app-tap/module_api.test.lua |  2 +-
 5 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/extra/exports b/extra/exports
index bd05cb08e..da3308230 100644
--- a/extra/exports
+++ b/extra/exports
@@ -154,6 +154,7 @@ box_key_def_validate_tuple
 box_key_def_extract_key
 box_key_def_validate_full_key
 box_key_def_validate_key
+box_key_def_dup
 box_key_part_def_create
 box_tuple_format_default
 box_tuple_new
diff --git a/src/box/key_def.c b/src/box/key_def.c
index 5d556c300..15947d1e2 100644
--- a/src/box/key_def.c
+++ b/src/box/key_def.c
@@ -333,6 +333,12 @@ box_key_def_new_v2(box_key_part_def_t *parts, uint32_t part_count)
 	return key_def;
 }
 
+box_key_def_t *
+box_key_def_dup(const box_key_def_t *key_def)
+{
+	return key_def_dup(key_def);
+}
+
 void
 box_key_def_delete(box_key_def_t *key_def)
 {
diff --git a/src/box/key_def.h b/src/box/key_def.h
index 6326da7b5..01556958f 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -309,6 +309,16 @@ box_key_part_def_create(box_key_part_def_t *part);
 API_EXPORT box_key_def_t *
 box_key_def_new_v2(box_key_part_def_t *parts, uint32_t part_count);
 
+/**
+ * Duplicate key_def.
+ * @param key_def Original key_def.
+ *
+ * @retval not NULL Duplicate of src.
+ * @retval     NULL Memory error.
+ */
+API_EXPORT box_key_def_t *
+box_key_def_dup(const box_key_def_t *key_def);
+
 /**
  * Delete key definition
  *
diff --git a/test/app-tap/module_api.c b/test/app-tap/module_api.c
index 672272e25..6d4f7a413 100644
--- a/test/app-tap/module_api.c
+++ b/test/app-tap/module_api.c
@@ -1464,6 +1464,34 @@ test_key_def_validate_key(struct lua_State *L)
 	return 1;
 }
 
+static int
+test_key_def_dup(lua_State *L)
+{
+	box_key_def_t *key_def = NULL;
+	box_key_part_def_t part;
+	box_key_part_def_t *dump = NULL;
+	uint32_t dump_part_count = 0;
+
+	key_part_def_set_nondefault(&part);
+	key_def = box_key_def_new_v2(&part, 1);
+	assert(key_def != NULL);
+	box_key_def_t *key_def_dup = box_key_def_dup(key_def);
+	assert(key_def_dup != NULL);
+
+	dump = box_key_def_dump_parts(key_def_dup, &dump_part_count);
+	assert(dump != NULL);
+	assert(dump_part_count == 1);
+
+	key_part_def_check_equal(&part, &dump[0]);
+	key_part_def_check_zeros(&dump[0]);
+
+	box_key_def_delete(key_def_dup);
+	box_key_def_delete(key_def);
+
+	lua_pushboolean(L, 1);
+	return 1;
+}
+
 /* }}} key_def api v2 */
 
 static int
@@ -1883,6 +1911,7 @@ luaopen_module_api(lua_State *L)
 		{"test_key_def_merge", test_key_def_merge},
 		{"test_key_def_extract_key", test_key_def_extract_key},
 		{"test_key_def_validate_key", test_key_def_validate_key},
+		{"test_key_def_dup", test_key_def_dup},
 		{"tuple_validate_def", test_tuple_validate_default},
 		{"tuple_validate_fmt", test_tuple_validate_formatted},
 		{NULL, NULL}
diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index f45592ef9..0bf6c8a02 100755
--- a/test/app-tap/module_api.test.lua
+++ b/test/app-tap/module_api.test.lua
@@ -123,7 +123,7 @@ local function test_iscdata(test, module)
 end
 
 local test = require('tap').test("module_api", function(test)
-    test:plan(34)
+    test:plan(35)
     local status, module = pcall(require, 'module_api')
     test:is(status, true, "module")
     test:ok(status, "module is loaded")
-- 
2.20.1



More information about the Tarantool-patches mailing list