From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 1AE272D3B4 for ; Wed, 17 Oct 2018 14:06:44 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2NE65Fltkr5P for ; Wed, 17 Oct 2018 14:06:44 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 5120B2D2EF for ; Wed, 17 Oct 2018 14:06:43 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH] box: add tuple:size function References: <1538070923-23087-1-git-send-email-ivushkinalex@gmail.com> <20181016182144.GB5454@chai> <20181017072810.bxyfdrtq2rsxj5ub@tkn_work_nb> <20181017152949.GB19013@chai> From: Vladislav Shpilevoy Message-ID: <4f41a343-cd2a-44c3-06b8-3267db212b79@tarantool.org> Date: Wed, 17 Oct 2018 21:06:37 +0300 MIME-Version: 1.0 In-Reply-To: <20181017152949.GB19013@chai> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, Konstantin Osipov , Alexander Turenko Cc: Morgan-iv On 17/10/2018 18:29, Konstantin Osipov wrote: > * Alexander Turenko [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.