Tarantool development patches archive
 help / color / mirror / Atom feed
From: Timur Safin <tsafin@tarantool.org>
To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup
Date: Wed, 14 Oct 2020 03:15:41 +0300	[thread overview]
Message-ID: <1ce6ed8f564840da010fec4b937f4eeaf918e4db.1602634213.git.tsafin@tarantool.org> (raw)
In-Reply-To: <cover.1602634213.git.tsafin@tarantool.org>

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

  parent reply	other threads:[~2020-10-14  0:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14  0:15 [Tarantool-patches] [PATCH 1.10 v4 0/5] module api: extend for external merger Lua module Timur Safin
2020-10-14  0:15 ` [Tarantool-patches] [PATCH 1.10 v4 1/5] module api: export box_tuple_validate Timur Safin
2020-10-14  0:15 ` Timur Safin [this message]
2020-10-15 22:30   ` [Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup Alexander Turenko
2020-10-14  0:15 ` [Tarantool-patches] [PATCH 1.10 v4 3/5] module api: introduced luaT_toibuf instead of luaL_checkibuf Timur Safin
2020-10-14  0:15 ` [Tarantool-patches] [PATCH 1.10 v4 4/5] module api: box_ibuf_* wrappers Timur Safin
2020-10-14  0:15 ` [Tarantool-patches] [PATCH 1.10 v4 5/5] module api: add luaL_iscallable with support of cdata metatype Timur Safin
2020-10-14  0:18 ` [Tarantool-patches] [PATCH 1.10 v4 0/5] module api: extend for external merger Lua module Timur Safin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ce6ed8f564840da010fec4b937f4eeaf918e4db.1602634213.git.tsafin@tarantool.org \
    --to=tsafin@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox