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: Re: [Tarantool-patches] [PATCH 1.10 v3 3/4] module api: luaL_checkibuf
Date: Mon, 12 Oct 2020 10:43:27 +0300	[thread overview]
Message-ID: <1b9601d6a06b$5fbaa2a0$1f2fe7e0$@tarantool.org> (raw)
In-Reply-To: <baf1a1c1d43c32444e20d0f7f6f037f76a1bcacd.1602463038.git.tsafin@tarantool.org>

: From: Timur Safin <tsafin@tarantool.org>
: Subject: [PATCH 1.10 v3 3/4] module api: luaL_checkibuf
: 
: Moved `luaL_checkibuf` to the public part of module api.
: 
: Part of #5384
: ---
:  extra/exports                    |  2 ++
:  src/lua/utils.h                  | 44 ++++++++++++++++++++------------
:  test/app-tap/module_api.c        | 10 ++++++++
:  test/app-tap/module_api.test.lua | 20 ++++++++++++++-
:  4 files changed, 58 insertions(+), 18 deletions(-)
: 
: diff --git a/extra/exports b/extra/exports
: index 9e2023685..abe9eded4 100644
: --- a/extra/exports
: +++ b/extra/exports
: @@ -118,8 +118,10 @@ coio_call
:  coio_getaddrinfo
:  luaL_pushcdata
:  luaL_iscdata
: +luaL_iscallable

Oops, that's an artifact of moving patches around. Would need 
to reshuffle this patch again. And split/remove irrelevant parts.

:  luaL_checkcdata
:  luaL_setcdatagc
: +luaL_checkibuf
:  luaL_ctypeid
:  luaL_cdef
:  luaL_pushuint64
: diff --git a/src/lua/utils.h b/src/lua/utils.h
: index d6fbd0e48..92bf88900 100644
: --- a/src/lua/utils.h
: +++ b/src/lua/utils.h
: @@ -505,6 +505,24 @@ luaT_state(void);
:  LUA_API const char *
:  luaT_tolstring(lua_State *L, int idx, size_t *ssize);
: 
: +/**
: + * Check whether a Lua object is a function or has
: + * metatable/metatype with a __call field.
: + *
: + * Note: It does not check type of __call metatable/metatype
: + * field.
: + */
: +LUA_API int
: +luaL_iscallable(lua_State *L, int idx);
: +
: +/**
: + * 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 *
: +luaL_checkibuf(struct lua_State *L, int idx);
: +
:  /** \endcond public */
: 
:  void
: @@ -588,23 +606,6 @@ luaL_checkfinite(struct lua_State *L, struct
: luaL_serializer *cfg,
:  		luaL_error(L, "number must not be NaN or Inf");
:  }
: 
: -/**
: - * 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.
: - */
: -struct ibuf *
: -luaL_checkibuf(struct lua_State *L, int idx);
: -
: -/**
: - * Check if a value on @a L stack by index @a idx is pointer at
: - * char or const char. '(char *)NULL' is also considered a valid
: - * char pointer.
: - */
: -int
: -luaL_checkconstchar(struct lua_State *L, int idx, const char **res,
: -		    uint32_t *cdata_type_p);
: -
:  /**
:   * @brief Creates a new Lua coroutine in a protected frame. If
:   * <lua_newthread> call underneath succeeds, the created Lua state
: @@ -617,6 +618,15 @@ luaL_checkconstchar(struct lua_State *L, int idx,
: const char **res,
:  struct lua_State *
:  luaT_newthread(struct lua_State *L);
: 
: +/**
: + * Check if a value on @a L stack by index @a idx is pointer at
: + * char or const char. '(char *)NULL' is also considered a valid
: + * char pointer.
: + */
: +int
: +luaL_checkconstchar(struct lua_State *L, int idx, const char **res,
: +		    uint32_t *cdata_type_p);
: +
:  int
:  tarantool_lua_utils_init(struct lua_State *L);
: 
: diff --git a/test/app-tap/module_api.c b/test/app-tap/module_api.c
: index 74a4c4d54..2c4ca710d 100644
: --- a/test/app-tap/module_api.c
: +++ b/test/app-tap/module_api.c
: @@ -150,6 +150,15 @@ test_checkint64(lua_State *L)
:  	return 1;
:  }
: 
: +static int
: +test_checkibuf(lua_State *L)
: +{
: +	struct ibuf *buf;
: +	buf = luaL_checkibuf(L, -1);
: +	lua_pushboolean(L, buf != NULL);
: +	return 1;
: +}
: +
:  static int
:  test_touint64(lua_State *L)
:  {
: @@ -584,6 +593,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 06ecb5470..2b28bdaff 100755
: --- a/test/app-tap/module_api.test.lua
: +++ b/test/app-tap/module_api.test.lua
: @@ -36,6 +36,23 @@ local function test_pushcdata(test, module)
:      test:is(gc_counter, 1, 'pushcdata gc')
:  end
: 
: +local function test_buffers(test, module)
: +    test:plan(7)
: +    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(ibuf), 'checkibuf of ibuf')
: +    test:ok(not module.checkibuf(pbuf), 'checkibuf of pointer to ibuf
: data')
: +end
: +
:  local function test_tuples(test, module)
:      test:plan(8)
: 
: @@ -59,7 +76,7 @@ local function test_tuples(test, module)
:  end
: 
:  local test = require('tap').test("module_api", function(test)
: -    test:plan(25)
: +    test:plan(26)
:      local status, module = pcall(require, 'module_api')
:      test:is(status, true, "module")
:      test:ok(status, "module is loaded")
: @@ -84,6 +101,7 @@ local test = require('tap').test("module_api",
: function(test)
:      test:like(msg, 'luaT_error', 'luaT_error')
: 
:      test:test("pushcdata", test_pushcdata, module)
: +    test:test("buffers", test_buffers, module)
:      test:test("validate", test_tuples, module)
: 
:      space:drop()
: --
: 2.20.1

  reply	other threads:[~2020-10-12  7:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12  0:50 [Tarantool-patches] [PATCH 1.10 v3 0/4] module api: extend for external merger Lua module Timur Safin
2020-10-12  0:50 ` [Tarantool-patches] [PATCH 1.10 v3 1/4] module api: export box_tuple_validate Timur Safin
2020-10-12  0:50 ` [Tarantool-patches] [PATCH 1.10 v3 2/4] module api: export box_key_def_dup Timur Safin
2020-10-12  0:50 ` [Tarantool-patches] [PATCH 1.10 v3 3/4] module api: luaL_checkibuf Timur Safin
2020-10-12  7:43   ` Timur Safin [this message]
2020-10-12  0:50 ` [Tarantool-patches] [PATCH 1.10 v3 4/4] module api: add luaL_iscallable with support of cdata metatype Timur Safin
2020-10-13 11:58   ` Alexander Turenko
2020-10-12  9:19 ` [Tarantool-patches] [PATCH 1.10 v3 0/4] 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='1b9601d6a06b$5fbaa2a0$1f2fe7e0$@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 v3 3/4] module api: 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