From: Alexander Turenko <alexander.turenko@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Cc: tarantool-patches@dev.tarantool.org, Alexander Turenko <alexander.turenko@tarantool.org> Subject: [Tarantool-patches] [PATCH 1/3] merger: drop luaL prefix where contract allows it Date: Mon, 1 Jun 2020 21:10:11 +0300 [thread overview] Message-ID: <12754f9b68359f80c41ea655d1a25028e1a72cca.1591028838.git.alexander.turenko@tarantool.org> (raw) In-Reply-To: <cover.1591028838.git.alexander.turenko@tarantool.org> 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 <struct lua_State *>) * 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
next prev parent reply other threads:[~2020-06-01 18:10 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-01 18:10 [Tarantool-patches] [PATCH 0/3] Merger's NULL defererence Alexander Turenko 2020-06-01 18:10 ` Alexander Turenko [this message] 2020-06-02 22:47 ` [Tarantool-patches] [PATCH 1/3] merger: drop luaL prefix where contract allows it Vladislav Shpilevoy 2020-06-07 16:57 ` Alexander Turenko 2020-06-11 16:17 ` Vladislav Shpilevoy 2020-06-16 11:59 ` Igor Munkin 2020-06-17 17:53 ` Alexander Turenko 2020-06-01 18:10 ` [Tarantool-patches] [PATCH 2/3] merger: fix NULL dereference when called via iproto Alexander Turenko 2020-06-02 22:48 ` Vladislav Shpilevoy 2020-06-07 16:58 ` Alexander Turenko 2020-06-11 16:18 ` Vladislav Shpilevoy 2020-06-17 17:53 ` Alexander Turenko 2020-06-18 22:47 ` Vladislav Shpilevoy 2020-06-01 18:10 ` [Tarantool-patches] [PATCH 3/3] lua: expose temporary Lua state for iproto calls Alexander Turenko 2020-06-02 22:48 ` Vladislav Shpilevoy 2020-06-07 16:58 ` Alexander Turenko 2020-06-02 22:47 ` [Tarantool-patches] [PATCH 0/3] Merger's NULL defererence Vladislav Shpilevoy 2020-06-07 17:17 ` Alexander Turenko 2020-06-07 16:58 ` [Tarantool-patches] [PATCH 2.5/3] merger: clean fiber-local Lua stack after next() Alexander Turenko 2020-06-11 16:20 ` Vladislav Shpilevoy 2020-06-17 17:53 ` Alexander Turenko 2020-06-18 22:48 ` Vladislav Shpilevoy 2020-06-19 7:41 ` Alexander Turenko 2020-06-17 17:54 ` [Tarantool-patches] [PATCH 0/3] Merger's NULL defererence Alexander Turenko
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=12754f9b68359f80c41ea655d1a25028e1a72cca.1591028838.git.alexander.turenko@tarantool.org \ --to=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/3] merger: drop luaL prefix where contract allows it' \ /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