Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Timur Safin <tsafin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 2.X v3 3/3] module api: luaL_checkibuf
Date: Tue, 13 Oct 2020 14:47:34 +0300	[thread overview]
Message-ID: <20201013114734.ridfxhn6cwh4neki@tkn_work_nb> (raw)
In-Reply-To: <0abb1776e7eeca79aba354af000d70a68a95fc9d.1602463103.git.tsafin@tarantool.org>

I CCed Igor, because he is maybe interested about the topic regarding
naming of Lua/C helpers.

Answered inline.

WBR, Alexander Turenko.

> diff --git a/src/lua/utils.h b/src/lua/utils.h
> index e80e2b1a2..7658c67f8 100644
> --- a/src/lua/utils.h
> +++ b/src/lua/utils.h
> @@ -539,6 +539,14 @@ luaT_tolstring(lua_State *L, int idx, size_t *ssize);
>  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.
> + */
> +struct ibuf *
> +luaL_checkibuf(struct lua_State *L, int idx);
> +

First, some background: luaL_checkfoo() raise a Lua error when type
checking fails. lua_isfoo() returns zero in such case, lua_tofoo()
return NULL. IMHO, lua_isfoo() / lua_tofoo() is often more convenient
for Lua/C code, because you may need to free some resources explicitly.
It also allows to return / raise a domain specific error (say, give
short usage information).

 | [-0, +0, -]
 | int lua_isuserdata (lua_State *L, int index);
 |
 | Returns 1 if the value at the given acceptable index is a userdata
 | (either full or light), and 0 otherwise. 

 | [-0, +0, -]
 | void *lua_touserdata (lua_State *L, int index);
 |
 | If the value at the given acceptable index is a full userdata,
 | returns its block address. If the value is a light userdata, returns
 | its pointer. Otherwise, returns NULL. 

You may find more examples in https://pgl.yoyo.org/luai/i/_

So I would either implement `int luaT_isibuf(L, idx, box_ibuf_t **)` or
rename the function to `box_ibuf_t *luaT_toibuf(L, idx)`.

Regarding prefixes: we use 'luaL_' for general purpose functions, but
'luaT_' for tarantool specific objects. ibuf is tarantool's thing.

BTW, Vlad tells me it possibly should be named as 'box ibuf', not just
'ibuf'. However the name would be a bit ugly (luaT_is_box_ibuf()), so I
guess 'luaT_' prefix is enough to say that it is something tarantool
specific.

BTW, it seems the patch re ibuf functions should come before this one to
use the public type name (box_ibuf_t) in the declaration.

> +local function test_buffers(test, module)
> +    test:plan(8)
> +    local ffi = require('ffi')
> +    local buffer = require('buffer')
> +
> +    local bufalloc = buffer.static_alloc("char", 128)
> +    local ibuf = buffer.ibuf()

Let's also check <struct ibuf *>.

 | tarantool> ffi.typeof(buffer.ibuf())
 | ---
 | - ctype<struct ibuf>
 | ...
 | 
 | tarantool> ffi.typeof(buffer.IBUF_SHARED)
 | ---
 | - ctype<struct ibuf *>
 | ...

  reply	other threads:[~2020-10-13 11:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12  0:44 [Tarantool-patches] [PATCH 2.X v3 0/3] module api: extend for external merger Lua module Timur Safin
2020-10-12  0:44 ` [Tarantool-patches] [PATCH 2.X v3 1/3] module api: export box_tuple_validate Timur Safin
2020-10-13  0:14   ` Alexander Turenko
2020-10-13  0:35     ` Timur Safin
2020-10-12  0:44 ` [Tarantool-patches] [PATCH 2.X v3 2/3] module api: export box_key_def_dup Timur Safin
2020-10-13  0:46   ` Alexander Turenko
2020-10-12  0:44 ` [Tarantool-patches] [PATCH 2.X v3 3/3] module api: luaL_checkibuf Timur Safin
2020-10-13 11:47   ` Alexander Turenko [this message]
2020-10-13 19:26     ` Igor Munkin
2020-10-13 16:30 ` [Tarantool-patches] [PATCH 2.X v3] module api: box_ibuf_* wrappers Timur Safin
2020-10-13 18:21   ` Alexander Turenko
2020-10-13 19:02     ` Timur Safin
2020-10-13 19:58       ` Alexander Turenko

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=20201013114734.ridfxhn6cwh4neki@tkn_work_nb \
    --to=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tsafin@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2.X v3 3/3] 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