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 3/5] module api: introduced luaT_toibuf instead of luaL_checkibuf
Date: Wed, 14 Oct 2020 03:15:42 +0300	[thread overview]
Message-ID: <8370b21d24d54f8591e3b575af22b91ef5cab849.1602634213.git.tsafin@tarantool.org> (raw)
In-Reply-To: <cover.1602634213.git.tsafin@tarantool.org>

* made `luaL_checkibuf` public;
* renamed it to `luaT_toibuf` to follow naming convention
  (it's not raising error, and is casting to ibuf type).

Part of #5384
---
 extra/exports                    |  1 +
 src/lua/msgpack.c                |  2 +-
 src/lua/utils.c                  |  2 +-
 src/lua/utils.h                  | 22 +++++++++++++++++-----
 test/app-tap/module_api.c        | 10 ++++++++++
 test/app-tap/module_api.test.lua | 21 ++++++++++++++++++++-
 6 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/extra/exports b/extra/exports
index da3308230..37077120d 100644
--- a/extra/exports
+++ b/extra/exports
@@ -134,6 +134,7 @@ luaT_error
 luaT_call
 luaT_cpcall
 luaT_state
+luaT_toibuf
 luaT_tolstring
 luaT_tuple_encode
 luaT_tuple_new
diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c
index e3935d383..838f582ff 100644
--- a/src/lua/msgpack.c
+++ b/src/lua/msgpack.c
@@ -442,7 +442,7 @@ lua_msgpack_encode(lua_State *L)
 
 	struct ibuf *buf;
 	if (index > 1) {
-		buf = luaL_checkibuf(L, 2);
+		buf = luaT_toibuf(L, 2);
 		if (buf == NULL) {
 			return luaL_error(L, "msgpack.encode: argument 2 "
 					  "must be of type 'struct ibuf'");
diff --git a/src/lua/utils.c b/src/lua/utils.c
index 318715960..90515affc 100644
--- a/src/lua/utils.c
+++ b/src/lua/utils.c
@@ -1030,7 +1030,7 @@ luaT_tolstring(lua_State *L, int idx, size_t *len)
 }
 
 struct ibuf *
-luaL_checkibuf(struct lua_State *L, int idx)
+luaT_toibuf(struct lua_State *L, int idx)
 {
 	if (lua_type(L, idx) != LUA_TCDATA)
 		return NULL;
diff --git a/src/lua/utils.h b/src/lua/utils.h
index d6fbd0e48..a44c419d3 100644
--- a/src/lua/utils.h
+++ b/src/lua/utils.h
@@ -505,6 +505,14 @@ luaT_state(void);
 LUA_API const char *
 luaT_tolstring(lua_State *L, int idx, size_t *ssize);
 
+/**
+ * Check if a value on @a L stack by index @a idx is an ibuf
+ * object. Both 'struct ibuf' and 'struct ibuf *' are accepted.
+ * Returns NULL, if can't convert - not an ibuf object.
+ */
+LUA_API struct ibuf *
+luaT_toibuf(struct lua_State *L, int idx);
+
 /** \endcond public */
 
 void
@@ -589,12 +597,16 @@ luaL_checkfinite(struct lua_State *L, struct luaL_serializer *cfg,
 }
 
 /**
- * Check if a value on @a L stack by index @a idx is an ibuf
- * object. Both 'struct ibuf' and 'struct ibuf *' are accepted.
- * Returns NULL, if can't convert - not an ibuf object.
+ * @brief Creates a new Lua coroutine in a protected frame. If
+ * <lua_newthread> call underneath succeeds, the created Lua state
+ * is on the top of the guest stack and a pointer to this state is
+ * returned. Otherwise LUA_ERRMEM error is handled and the result
+ * is NULL.
+ * @param L is a Lua state
+ * @sa <lua_newthread>
  */
-struct ibuf *
-luaL_checkibuf(struct lua_State *L, int idx);
+struct lua_State *
+luaT_newthread(struct lua_State *L);
 
 /**
  * Check if a value on @a L stack by index @a idx is pointer at
diff --git a/test/app-tap/module_api.c b/test/app-tap/module_api.c
index 6d4f7a413..e29abcb85 100644
--- a/test/app-tap/module_api.c
+++ b/test/app-tap/module_api.c
@@ -155,6 +155,15 @@ test_checkint64(lua_State *L)
 	return 1;
 }
 
+static int
+test_checkibuf(lua_State *L)
+{
+	struct ibuf *buf;
+	buf = luaT_toibuf(L, -1);
+	lua_pushboolean(L, buf != NULL);
+	return 1;
+}
+
 static int
 test_touint64(lua_State *L)
 {
@@ -1887,6 +1896,7 @@ luaopen_module_api(lua_State *L)
 		{"test_pushint64", test_pushint64 },
 		{"test_checkuint64", test_checkuint64 },
 		{"test_checkint64", test_checkint64 },
+		{"checkibuf", test_checkibuf},
 		{"test_touint64", test_touint64 },
 		{"test_toint64", test_toint64 },
 		{"test_fiber", test_fiber },
diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index 0bf6c8a02..acda3deec 100755
--- a/test/app-tap/module_api.test.lua
+++ b/test/app-tap/module_api.test.lua
@@ -36,6 +36,24 @@ local function test_pushcdata(test, module)
     test:is(gc_counter, 1, 'pushcdata gc')
 end
 
+local function test_buffers(test, module)
+    test:plan(8)
+    local ffi = require('ffi')
+    local buffer = require('buffer')
+
+    local ibuf = buffer.ibuf()
+    local pbuf = ibuf:alloc(128)
+
+    test:ok(not module.checkibuf(nil), 'checkibuf of nil')
+    test:ok(not module.checkibuf({}), 'checkibuf of {}')
+    test:ok(not module.checkibuf(1LL), 'checkibuf of 1LL')
+    test:ok(not module.checkibuf(box.NULL), 'checkibuf of box.NULL')
+    test:ok(not module.checkibuf(buffer.reg1), 'checkibuf of reg1')
+    test:ok(module.checkibuf(buffer.IBUF_SHARED), "checkibuf of ibuf*")
+    test:ok(module.checkibuf(ibuf), 'checkibuf of ibuf')
+    test:ok(not module.checkibuf(pbuf), 'checkibuf of pointer to ibuf data')
+end
+
 local function test_tuple_validate(test, module)
     test:plan(12)
 
@@ -123,7 +141,7 @@ local function test_iscdata(test, module)
 end
 
 local test = require('tap').test("module_api", function(test)
-    test:plan(35)
+    test:plan(36)
     local status, module = pcall(require, 'module_api')
     test:is(status, true, "module")
     test:ok(status, "module is loaded")
@@ -149,6 +167,7 @@ local test = require('tap').test("module_api", function(test)
 
     test:test("pushcdata", test_pushcdata, module)
     test:test("iscdata", test_iscdata, module)
+    test:test("buffers", test_buffers, module)
     test:test("tuple_validate", test_tuple_validate, module)
 
     space:drop()
-- 
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 ` [Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup Timur Safin
2020-10-15 22:30   ` Alexander Turenko
2020-10-14  0:15 ` Timur Safin [this message]
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=8370b21d24d54f8591e3b575af22b91ef5cab849.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 3/5] module api: introduced luaT_toibuf instead of luaL_checkibuf' \
    /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