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 3B9792FEA4 for ; Thu, 22 Nov 2018 14:10:53 -0500 (EST) 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 6orTn9D1PyiV for ; Thu, 22 Nov 2018 14:10:53 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 F04102FC8A for ; Thu, 22 Nov 2018 14:10:52 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v2 2/7] box: add method dump_lua to port Date: Thu, 22 Nov 2018 22:10:50 +0300 Message-Id: <15aaf24f520f8a1ad834ec417bcde6f42331a583.1542910674.git.imeevma@gmail.com> In-Reply-To: References: 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: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org New method dump_lua dumps saved in port tuples to Lua stack. It will allow us to call this method without any other interaction with port. Needed for #3505 --- src/box/lua/call.c | 1 + src/box/port.c | 22 ++++++++++++++++++++++ src/box/port.h | 12 ++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/box/lua/call.c b/src/box/lua/call.c index 1f20426..52939ae 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -424,6 +424,7 @@ port_lua_dump_plain(struct port *port, uint32_t *size); static const struct port_vtab port_lua_vtab = { .dump_msgpack = port_lua_dump, .dump_msgpack_16 = port_lua_dump_16, + .dump_lua = NULL, .dump_plain = port_lua_dump_plain, .destroy = port_lua_destroy, }; diff --git a/src/box/port.c b/src/box/port.c index 266cf3d..a65a32d 100644 --- a/src/box/port.c +++ b/src/box/port.c @@ -36,6 +36,8 @@ #include #include #include "errinj.h" +#include "lua/utils.h" +#include "lua/tuple.h" static struct mempool port_tuple_entry_pool; @@ -121,6 +123,19 @@ port_tuple_dump_msgpack(struct port *base, struct obuf *out) return 1; } +static int +port_tuple_dump_lua(struct port *base, struct lua_State *L) +{ + struct port_tuple *port = port_tuple(base); + struct port_tuple_entry *pe; + int i = 0; + for (pe = port->first; pe != NULL; pe = pe->next) { + luaT_pushtuple(L, pe->tuple); + lua_rawseti(L, -2, ++i); + } + return port->size; +} + void port_destroy(struct port *port) { @@ -139,6 +154,12 @@ port_dump_msgpack_16(struct port *port, struct obuf *out) return port->vtab->dump_msgpack_16(port, out); } +int +port_dump_lua(struct port *port, struct lua_State *L) +{ + return port->vtab->dump_lua(port, L); +} + const char * port_dump_plain(struct port *port, uint32_t *size) { @@ -161,6 +182,7 @@ port_free(void) const struct port_vtab port_tuple_vtab = { .dump_msgpack = port_tuple_dump_msgpack, .dump_msgpack_16 = port_tuple_dump_msgpack_16, + .dump_lua = port_tuple_dump_lua, .dump_plain = NULL, .destroy = port_tuple_destroy, }; diff --git a/src/box/port.h b/src/box/port.h index 882bb37..3bd83b0 100644 --- a/src/box/port.h +++ b/src/box/port.h @@ -78,6 +78,11 @@ struct port_vtab { */ int (*dump_msgpack_16)(struct port *port, struct obuf *out); /** + * Dump the content of a port to Lua stack. + * On success returns number of entries dumped. + */ + int (*dump_lua)(struct port *port, struct lua_State *L); + /** * Dump a port content as a plain text into a buffer, * allocated inside. */ @@ -185,6 +190,13 @@ int port_dump_msgpack_16(struct port *port, struct obuf *out); /** + * Same as port_dump(), but use the legacy Tarantool 1.6 + * format. + */ +int +port_dump_lua(struct port *port, struct lua_State *L); + +/** * Dump a port content as a plain text into a buffer, * allocated inside. * @param port Port with data to dump. -- 2.7.4