From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2835C4696C8 for ; Mon, 20 Apr 2020 01:25:17 +0300 (MSK) From: Leonid Vasiliev Date: Mon, 20 Apr 2020 01:25:07 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Subject: [Tarantool-patches] [PATCH V6 05/10] box: move Lua MP_EXT decoder from tuple.c List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org From: Vladislav Shpilevoy Lua C module 'msgpack' supports registration of custom extension decoders for MP_EXT values. That is needed to make 'msgpack' not depending on any modules which use it. So far the only box-related extension were tuples - struct tuple cdata needed to be encoded as an array. That is going to change in next commits, where struct error cdata appears, also depending on box. So the decoder can't be located in src/box/lua/tuple.c. It is moved to a more common place - src/box/lua/init.c. Needed for #4398 --- src/box/lua/init.c | 18 ++++++++++++++++++ src/box/lua/tuple.c | 16 ---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/box/lua/init.c b/src/box/lua/init.c index 0a65c3b..7899c16 100644 --- a/src/box/lua/init.c +++ b/src/box/lua/init.c @@ -36,6 +36,7 @@ #include "lua/utils.h" /* luaT_error() */ #include "lua/trigger.h" +#include "lua/msgpack.h" #include "box/box.h" #include "box/txn.h" @@ -395,6 +396,21 @@ static const struct luaL_Reg boxlib_backup[] = { {NULL, NULL} }; +/** + * A MsgPack extensions handler, for types defined in box. + */ +static enum mp_type +luamp_encode_extension_box(struct lua_State *L, int idx, + struct mpstream *stream) +{ + struct tuple *tuple = luaT_istuple(L, idx); + if (tuple != NULL) { + tuple_to_mpstream(tuple, stream); + return MP_ARRAY; + } + return MP_EXT; +} + #include "say.h" void @@ -435,6 +451,8 @@ box_lua_init(struct lua_State *L) luaopen_merger(L); lua_pop(L, 1); + luamp_set_encode_extension(luamp_encode_extension_box); + /* Load Lua extension */ for (const char **s = lua_sources; *s; s += 2) { const char *modname = *s; diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c index aba906d..03b4b8a 100644 --- a/src/box/lua/tuple.c +++ b/src/box/lua/tuple.c @@ -290,20 +290,6 @@ tuple_to_mpstream(struct tuple *tuple, struct mpstream *stream) mpstream_advance(stream, bsize); } -/* A MsgPack extensions handler that supports tuples */ -static enum mp_type -luamp_encode_extension_box(struct lua_State *L, int idx, - struct mpstream *stream) -{ - struct tuple *tuple = luaT_istuple(L, idx); - if (tuple != NULL) { - tuple_to_mpstream(tuple, stream); - return MP_ARRAY; - } - - return MP_EXT; -} - /** * Convert a tuple into lua table. Named fields are stored as * {name = value} pairs. Not named fields are stored as @@ -582,8 +568,6 @@ box_lua_tuple_init(struct lua_State *L) luaL_register_module(L, tuplelib_name, lbox_tuplelib); lua_pop(L, 1); - luamp_set_encode_extension(luamp_encode_extension_box); - tuple_serializer_update_options(); trigger_create(&tuple_serializer.update_trigger, on_msgpack_serializer_update, NULL, NULL); -- 2.7.4