From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH] box: add tuple:size function
Date: Wed, 17 Oct 2018 21:10:26 +0300 [thread overview]
Message-ID: <57bdac27-d132-6f66-575b-432acb202c8a@tarantool.org> (raw)
In-Reply-To: <4f41a343-cd2a-44c3-06b8-3267db212b79@tarantool.org>
In addition, a function, returning some internal size
that can not be applied to any user code object, is
useless except statistics.
So box_tuple_bsize will be useless.
On 17/10/2018 21:06, Vladislav Shpilevoy wrote:
>
>
> On 17/10/2018 18:29, Konstantin Osipov wrote:
>> * Alexander Turenko <alexander.turenko@tarantool.org> [18/10/17 10:45]:
>>> Are tuple.bsize and box_tuple_bsize() subjects to change or it is only
>>> about the Lua part?
>>
>> tuple.bsize is used internally, so I don't think you should change
>> it. But it's better to rename it to msgpack_size or something like
>> that to avoid ambiguity.
>>
>> box_tuple_bsize() should be ok to change.
>>
>
> box_tuple_bsize() is already documented in module.h as
> returning only tuple data.
>
> Also, some people can use it right now to allocate a
> buffer of a correct size before calling box_tuple_to_buf.
> I understand, that box_tuple_to_buf(tuple, NULL, 0) returns
> bsize as well, but some people could miss it, or just use
> box_tuple_bsize because it looks better when you write like
> this:
>
> size = box_tuple_bsize(tuple)
> buf = alloc(size)
> box_tuple_to_buf(tuple, buf, size)
>
> than like this:
>
> size = box_tuple_to_buf(tuple, NULL, 0) // <- difference
> buf = alloc(size)
> box_tuple_to_buf(tuple, buf, size)
>
> Even if we close eyes on the fact, that a user of
> the first way will allocate more data than needed,
> imagine, that then he does something like this:
>
> send(sockfd, buf, size)
>
> Now, he send some garbage uninitialized data of 14
> bytes at the end of buf.
>
> I understand, that you likely not believe me that
> the first way looks more intuitive, but look at
> our own code: box_tuple_bsize() is used now in
>
> *box/lua/tuple.c in tuple_to_mpstream();
> * box/lua/tuple.lua via FFI;
>
> to allocate a buffer before copying tuple data
> directly or via tuple_to_buf. We can fix our code,
> but can not fix user's one.
>
> So here we can either
>
> * fix documentation of the site without breaking anything
> * or break behavior of public API destroying an ability to
> learn tuple data size in a natural way;
> * add new method and again fix the site documentation.
>
> I described it just for the record that you have chosen
> the second, most destructive way.
>
>
next prev parent reply other threads:[~2018-10-17 18:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-27 17:55 [tarantool-patches] " AlexeyIvushkin
2018-10-03 14:20 ` [tarantool-patches] " Vladislav Shpilevoy
2018-10-03 15:05 ` Vladislav Shpilevoy
2018-10-05 10:23 ` [tarantool-patches] " Vladimir Davydov
2018-10-06 13:58 ` [tarantool-patches] " Vladislav Shpilevoy
2018-10-08 10:16 ` Vladimir Davydov
2018-10-10 10:25 ` Vladislav Shpilevoy
2018-10-16 18:21 ` Konstantin Osipov
2018-10-17 7:28 ` Alexander Turenko
2018-10-17 15:29 ` Konstantin Osipov
2018-10-17 15:50 ` Alexander Turenko
2018-10-18 18:11 ` Konstantin Osipov
2018-10-18 18:15 ` Alexander Turenko
2018-10-17 18:06 ` Vladislav Shpilevoy
2018-10-17 18:10 ` Vladislav Shpilevoy [this message]
2018-10-17 18:14 ` Konstantin Osipov
2018-10-17 18:20 ` Alexander Turenko
2018-10-17 20:36 ` Vladislav Shpilevoy
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=57bdac27-d132-6f66-575b-432acb202c8a@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH] box: add tuple:size function' \
/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