From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (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 D96DE469711 for ; Mon, 1 Jun 2020 21:10:34 +0300 (MSK) From: Alexander Turenko Date: Mon, 1 Jun 2020 21:10:11 +0300 Message-Id: <12754f9b68359f80c41ea655d1a25028e1a72cca.1591028838.git.alexander.turenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/3] merger: drop luaL prefix where contract allows it List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org, Alexander Turenko This change highlights the contract of merge source virtual methods: they don't require a Lua state to be passed with arguments. Internal use of a temporary Lua state is the implementation detail. Technically the functions lean on a Lua state existence in a fiber storage, but the next commit will relax this requirement. Made the following renames: * luaL_merge_source_buffer_fetch -> merge_source_buffer_fetch * luaL_merge_source_buffer_next -> merge_source_buffer_next * luaL_merge_source_buffer_destroy -> merge_source_buffer_destroy * keep luaL_merge_source_table_fetch (pass ) * luaL_merge_source_table_next -> merge_source_table_next * luaL_merge_source_table_destroy -> merge_source_table_destroy * keep luaL_merge_source_tuple_fetch (change arguments order) * luaL_merge_source_tuple_next -> merge_source_tuple_next * luaL_merge_source_tuple_destroy -> merge_source_tuple_destroy Also added API comments for destroy() and next() virtual methods to uniform them visually with other merge source functions. Part of #4954 --- src/box/lua/merger.c | 106 +++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 38 deletions(-) diff --git a/src/box/lua/merger.c b/src/box/lua/merger.c index 1b155152b..16814c041 100644 --- a/src/box/lua/merger.c +++ b/src/box/lua/merger.c @@ -354,11 +354,11 @@ struct merge_source_buffer { /* Virtual methods declarations */ static void -luaL_merge_source_buffer_destroy(struct merge_source *base); +merge_source_buffer_destroy(struct merge_source *base); static int -luaL_merge_source_buffer_next(struct merge_source *base, - struct tuple_format *format, - struct tuple **out); +merge_source_buffer_next(struct merge_source *base, + struct tuple_format *format, + struct tuple **out); /* Non-virtual methods */ @@ -373,8 +373,8 @@ static struct merge_source * luaL_merge_source_buffer_new(struct lua_State *L) { static struct merge_source_vtab merge_source_buffer_vtab = { - .destroy = luaL_merge_source_buffer_destroy, - .next = luaL_merge_source_buffer_next, + .destroy = merge_source_buffer_destroy, + .next = merge_source_buffer_next, }; struct merge_source_buffer *source = malloc( @@ -403,7 +403,7 @@ luaL_merge_source_buffer_new(struct lua_State *L) * iterator ends and -1 at error and set a diag. */ static int -luaL_merge_source_buffer_fetch(struct merge_source_buffer *source) +merge_source_buffer_fetch(struct merge_source_buffer *source) { struct lua_State *L = fiber()->storage.lua.stack; int nresult = luaL_iterator_next(L, source->fetch_it); @@ -448,8 +448,13 @@ luaL_merge_source_buffer_fetch(struct merge_source_buffer *source) /* Virtual methods */ +/** + * destroy() virtual method implementation for a buffer source. + * + * @see struct merge_source_vtab + */ static void -luaL_merge_source_buffer_destroy(struct merge_source *base) +merge_source_buffer_destroy(struct merge_source *base) { struct merge_source_buffer *source = container_of(base, struct merge_source_buffer, base); @@ -462,10 +467,15 @@ luaL_merge_source_buffer_destroy(struct merge_source *base) free(source); } +/** + * next() virtual method implementation for a buffer source. + * + * @see struct merge_source_vtab + */ static int -luaL_merge_source_buffer_next(struct merge_source *base, - struct tuple_format *format, - struct tuple **out) +merge_source_buffer_next(struct merge_source *base, + struct tuple_format *format, + struct tuple **out) { struct merge_source_buffer *source = container_of(base, struct merge_source_buffer, base); @@ -476,7 +486,7 @@ luaL_merge_source_buffer_next(struct merge_source *base, * chunks iterator ends. */ while (source->remaining_tuple_count == 0) { - int rc = luaL_merge_source_buffer_fetch(source); + int rc = merge_source_buffer_fetch(source); if (rc < 0) return -1; if (rc == 0) { @@ -541,11 +551,11 @@ struct merge_source_table { /* Virtual methods declarations */ static void -luaL_merge_source_table_destroy(struct merge_source *base); +merge_source_table_destroy(struct merge_source *base); static int -luaL_merge_source_table_next(struct merge_source *base, - struct tuple_format *format, - struct tuple **out); +merge_source_table_next(struct merge_source *base, + struct tuple_format *format, + struct tuple **out); /* Non-virtual methods */ @@ -558,8 +568,8 @@ static struct merge_source * luaL_merge_source_table_new(struct lua_State *L) { static struct merge_source_vtab merge_source_table_vtab = { - .destroy = luaL_merge_source_table_destroy, - .next = luaL_merge_source_table_next, + .destroy = merge_source_table_destroy, + .next = merge_source_table_next, }; struct merge_source_table *source = malloc( @@ -586,9 +596,9 @@ luaL_merge_source_table_new(struct lua_State *L) * received and -1 at an error (set a diag). */ static int -luaL_merge_source_table_fetch(struct merge_source_table *source) +luaL_merge_source_table_fetch(struct lua_State *L, + struct merge_source_table *source) { - struct lua_State *L = fiber()->storage.lua.stack; int nresult = luaL_iterator_next(L, source->fetch_it); /* Handle a Lua error in a gen function. */ @@ -625,8 +635,13 @@ luaL_merge_source_table_fetch(struct merge_source_table *source) /* Virtual methods */ +/** + * destroy() virtual method implementation for a table source. + * + * @see struct merge_source_vtab + */ static void -luaL_merge_source_table_destroy(struct merge_source *base) +merge_source_table_destroy(struct merge_source *base) { struct merge_source_table *source = container_of(base, struct merge_source_table, base); @@ -639,10 +654,15 @@ luaL_merge_source_table_destroy(struct merge_source *base) free(source); } +/** + * next() virtual method implementation for a table source. + * + * @see struct merge_source_vtab + */ static int -luaL_merge_source_table_next(struct merge_source *base, - struct tuple_format *format, - struct tuple **out) +merge_source_table_next(struct merge_source *base, + struct tuple_format *format, + struct tuple **out) { struct lua_State *L = fiber()->storage.lua.stack; struct merge_source_table *source = container_of(base, @@ -659,7 +679,7 @@ luaL_merge_source_table_next(struct merge_source *base, while (source->ref == 0 || lua_isnil(L, -1)) { if (source->ref > 0) lua_pop(L, 2); - int rc = luaL_merge_source_table_fetch(source); + int rc = luaL_merge_source_table_fetch(L, source); if (rc < 0) return -1; if (rc == 0) { @@ -715,11 +735,11 @@ struct merge_source_tuple { /* Virtual methods declarations */ static void -luaL_merge_source_tuple_destroy(struct merge_source *base); +merge_source_tuple_destroy(struct merge_source *base); static int -luaL_merge_source_tuple_next(struct merge_source *base, - struct tuple_format *format, - struct tuple **out); +merge_source_tuple_next(struct merge_source *base, + struct tuple_format *format, + struct tuple **out); /* Non-virtual methods */ @@ -732,8 +752,8 @@ static struct merge_source * luaL_merge_source_tuple_new(struct lua_State *L) { static struct merge_source_vtab merge_source_tuple_vtab = { - .destroy = luaL_merge_source_tuple_destroy, - .next = luaL_merge_source_tuple_next, + .destroy = merge_source_tuple_destroy, + .next = merge_source_tuple_next, }; struct merge_source_tuple *source = malloc( @@ -763,8 +783,8 @@ luaL_merge_source_tuple_new(struct lua_State *L) * Return -1 at error (set a diag). */ static int -luaL_merge_source_tuple_fetch(struct merge_source_tuple *source, - struct lua_State *L) +luaL_merge_source_tuple_fetch(struct lua_State *L, + struct merge_source_tuple *source) { int nresult = luaL_iterator_next(L, source->fetch_it); @@ -792,8 +812,13 @@ luaL_merge_source_tuple_fetch(struct merge_source_tuple *source, /* Virtual methods */ +/** + * destroy() virtual method implementation for a tuple source. + * + * @see struct merge_source_vtab + */ static void -luaL_merge_source_tuple_destroy(struct merge_source *base) +merge_source_tuple_destroy(struct merge_source *base) { struct merge_source_tuple *source = container_of(base, struct merge_source_tuple, base); @@ -804,16 +829,21 @@ luaL_merge_source_tuple_destroy(struct merge_source *base) free(source); } +/** + * next() virtual method implementation for a tuple source. + * + * @see struct merge_source_vtab + */ static int -luaL_merge_source_tuple_next(struct merge_source *base, - struct tuple_format *format, - struct tuple **out) +merge_source_tuple_next(struct merge_source *base, + struct tuple_format *format, + struct tuple **out) { struct lua_State *L = fiber()->storage.lua.stack; struct merge_source_tuple *source = container_of(base, struct merge_source_tuple, base); - int rc = luaL_merge_source_tuple_fetch(source, L); + int rc = luaL_merge_source_tuple_fetch(L, source); if (rc < 0) return -1; /* -- 2.25.0